Skip to content

Commit 20638cc

Browse files
Fix: Binary compatibility with Structurize
1 parent b0c8c9f commit 20638cc

14 files changed

Lines changed: 123 additions & 146 deletions

.changeset/gentle-camels-shine.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"CreateColonies": patch
3+
---
4+
5+
fix: Changes to reflect Structurize's bugfix in Structurize 1.0.804

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ registrate_version = MC1.20-1.3.3
4646

4747
blockui_version=1.20.1-1.0.190-snapshot
4848
domum_ornamentum_version=1.20.1-1.0.288-snapshot
49-
structurize_version=1.20.1-1.0.781-snapshot
50-
minecolonies_version=1.20.1-1.1.1011-snapshot
49+
structurize_version=1.20.1-1.0.804-snapshot
50+
minecolonies_version=1.20.1-1.1.1195-snapshot
5151

5252
## Mod Properties
5353

@@ -67,4 +67,4 @@ mod_group_id=nl.motionlesstrain.createcolonies
6767
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
6868
mod_authors=MotionlessTrain
6969
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
70-
mod_description=A compatibility project between Create and Structurize/Minecolonies
70+
mod_description=A compatibility project between Create and Structurize/Minecolonies
Lines changed: 83 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,123 @@
11
package nl.motionlesstrain.createcolonies.placementhandlers;
22

33
import com.ldtteam.structurize.api.util.constant.Constants;
4+
import com.ldtteam.structurize.placement.IPlacementContext;
45
import com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler;
5-
import com.ldtteam.structurize.util.PlacementSettings;
66
import com.simibubi.create.content.kinetics.belt.BeltBlock;
77
import com.simibubi.create.content.kinetics.belt.BeltPart;
88
import net.minecraft.core.BlockPos;
99
import net.minecraft.nbt.CompoundTag;
1010
import net.minecraft.nbt.Tag;
11+
import net.minecraft.util.Tuple;
1112
import net.minecraft.world.item.ItemStack;
1213
import net.minecraft.world.level.Level;
14+
import net.minecraft.world.level.block.entity.BlockEntity;
1315
import net.minecraft.world.level.block.state.BlockState;
1416
import nl.motionlesstrain.createcolonies.resources.CreateResources;
1517
import nl.motionlesstrain.createcolonies.utils.BlockPosUtil;
1618
import nl.motionlesstrain.createcolonies.utils.ItemUtils;
19+
import org.jetbrains.annotations.NotNull;
1720
import org.jetbrains.annotations.Nullable;
1821

1922
import java.util.*;
2023

2124
import static com.ldtteam.structurize.placement.handlers.placement.PlacementHandlers.handleTileEntityPlacement;
2225

2326
public class BeltPlacementHandler implements IPlacementHandler {
24-
@Override
25-
public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState) {
26-
return blockState.is(CreateResources.Blocks.belt);
27-
}
28-
29-
private final Map<BlockPos, Map<BlockPos, List<ItemStack>>> beltItems = new HashMap<>();
30-
31-
@Override
32-
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, boolean b) {
33-
final List<ItemStack> requiredItems = new ArrayList<>();
34-
35-
if (blockState.hasProperty(BeltBlock.PART)) {
36-
if (blockState.getValue(BeltBlock.PART) != BeltPart.MIDDLE) {
37-
requiredItems.add(ItemUtils.stackFromNullable(CreateResources.Items.shaft));
38-
}
39-
if (blockState.getValue(BeltBlock.PART) == BeltPart.START) {
40-
requiredItems.add(ItemUtils.stackFromNullable(CreateResources.Items.belt));
41-
// The start one seems to have an inventory
42-
if (compoundTag != null && compoundTag.contains("Inventory", Tag.TAG_COMPOUND)) {
43-
final var inventoryCompound = compoundTag.getCompound("Inventory");
44-
final var itemEntities = inventoryCompound.getList("Items", Tag.TAG_COMPOUND);
45-
for (final var itemEntity : itemEntities) {
46-
if (itemEntity instanceof CompoundTag itemEntityTag) {
47-
var itemTag = itemEntityTag.getCompound("Item");
48-
requiredItems.add(ItemStack.of(itemTag));
49-
}
50-
}
51-
}
27+
@Override
28+
public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState) {
29+
return blockState.is(CreateResources.Blocks.belt);
30+
}
31+
32+
private final Map<BlockPos, Map<BlockPos, List<ItemStack>>> beltItems = new HashMap<>();
33+
34+
@Override
35+
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, @NotNull IPlacementContext placementContext) {
36+
final List<ItemStack> requiredItems = new ArrayList<>();
37+
38+
if (blockState.hasProperty(BeltBlock.PART)) {
39+
if (blockState.getValue(BeltBlock.PART) != BeltPart.MIDDLE) {
40+
requiredItems.add(ItemUtils.stackFromNullable(CreateResources.Items.shaft));
41+
}
42+
if (blockState.getValue(BeltBlock.PART) == BeltPart.START) {
43+
requiredItems.add(ItemUtils.stackFromNullable(CreateResources.Items.belt));
44+
// The start one seems to have an inventory
45+
if (compoundTag != null && compoundTag.contains("Inventory", Tag.TAG_COMPOUND)) {
46+
final var inventoryCompound = compoundTag.getCompound("Inventory");
47+
final var itemEntities = inventoryCompound.getList("Items", Tag.TAG_COMPOUND);
48+
for (final var itemEntity : itemEntities) {
49+
if (itemEntity instanceof CompoundTag itemEntityTag) {
50+
var itemTag = itemEntityTag.getCompound("Item");
51+
requiredItems.add(ItemStack.of(itemTag));
5252
}
53+
}
5354
}
55+
}
56+
}
5457

55-
if (compoundTag != null) {
58+
if (compoundTag != null) {
5659

57-
final var controller = compoundTag.getCompound("Controller");
58-
final var controllerPos = BlockPosUtil.fromNBT(controller);
60+
final var controller = compoundTag.getCompound("Controller");
61+
final var controllerPos = BlockPosUtil.fromNBT(controller);
5962

60-
final var allBeltItems = beltItems.computeIfAbsent(controllerPos, ignored -> new HashMap<>());
63+
final var allBeltItems = beltItems.computeIfAbsent(controllerPos, ignored -> new HashMap<>());
6164

62-
final var length = compoundTag.getInt("Length");
65+
final var length = compoundTag.getInt("Length");
6366

64-
// If we are at the end of the belt, we know the entire belt is within the schematic, and we list the resources for it
65-
if (allBeltItems.size() + 1 == length && !allBeltItems.containsKey(blockPos)) {
66-
for (var items : allBeltItems.values()) {
67-
requiredItems.addAll(items);
68-
items.clear();
69-
}
70-
allBeltItems.put(blockPos, requiredItems);
71-
} else if (allBeltItems.size() < length) {
72-
allBeltItems.put(blockPos, requiredItems);
73-
return List.of();
74-
} else {
75-
return allBeltItems.getOrDefault(blockPos, List.of());
76-
}
67+
// If we are at the end of the belt, we know the entire belt is within the schematic, and we list the resources for it
68+
if (allBeltItems.size() + 1 == length && !allBeltItems.containsKey(blockPos)) {
69+
for (var items : allBeltItems.values()) {
70+
requiredItems.addAll(items);
71+
items.clear();
7772
}
78-
return requiredItems;
73+
allBeltItems.put(blockPos, requiredItems);
74+
} else if (allBeltItems.size() < length) {
75+
allBeltItems.put(blockPos, requiredItems);
76+
return List.of();
77+
} else {
78+
return allBeltItems.getOrDefault(blockPos, List.of());
79+
}
7980
}
81+
return requiredItems;
82+
}
8083

81-
private record BeltInfo(BlockPos pos, BlockState state, @Nullable CompoundTag tag) {}
84+
@Override
85+
public boolean doesWorldStateMatchBlueprintState(BlockState worldState, BlockState blueprintState, @Nullable Tuple<BlockEntity, CompoundTag> blockEntityData, @NotNull IPlacementContext placementContext) {
86+
return worldState.equals(blueprintState);
87+
}
8288

83-
private final Map<BlockPos, SortedMap<BlockPos, BeltInfo>> beltParts = new HashMap<>();
84-
@Override
85-
public ActionProcessingResult handle(Level world, BlockPos pos, BlockState blockState, @Nullable CompoundTag tileEntityData, boolean complete, BlockPos centerPos, @SuppressWarnings("removal") PlacementSettings settings) {
86-
if (tileEntityData == null) return ActionProcessingResult.DENY;
89+
private record BeltInfo(BlockPos pos, BlockState state, @Nullable CompoundTag tag) {
90+
}
8791

88-
final var controller = tileEntityData.getCompound("Controller");
89-
final var controllerPos = BlockPosUtil.fromNBT(controller);
92+
private final Map<BlockPos, SortedMap<BlockPos, BeltInfo>> beltParts = new HashMap<>();
9093

91-
final var length = tileEntityData.getInt("Length");
94+
@Override
95+
public ActionProcessingResult handle(Level world, BlockPos pos, BlockState blockState, @Nullable CompoundTag tileEntityData, @NotNull IPlacementContext placementContext) {
96+
if (tileEntityData == null) return ActionProcessingResult.DENY;
9297

93-
final var knownBeltParts = beltParts.computeIfAbsent(controllerPos, ignored -> new TreeMap<>());
94-
knownBeltParts.put(pos, new BeltInfo(pos, blockState, tileEntityData));
98+
final var controller = tileEntityData.getCompound("Controller");
99+
final var controllerPos = BlockPosUtil.fromNBT(controller);
95100

96-
if (knownBeltParts.size() == length) {
97-
for (final Map.Entry<BlockPos, BeltInfo> entry : knownBeltParts.entrySet()) {
98-
final var info = entry.getValue();
99-
if (!world.setBlock(info.pos(), info.state(), Constants.UPDATE_FLAG)) {
100-
for (final var alreadyPlaced : knownBeltParts.headMap(entry.getKey()).values()) {
101-
world.removeBlock(alreadyPlaced.pos(), false);
102-
}
103-
return ActionProcessingResult.DENY;
104-
}
105-
handleTileEntityPlacement(info.tag(), world, info.pos(), settings);
106-
}
107-
beltParts.remove(controllerPos);
108-
beltItems.remove(controllerPos);
109-
}
101+
final var length = tileEntityData.getInt("Length");
110102

111-
return ActionProcessingResult.SUCCESS;
103+
final var knownBeltParts = beltParts.computeIfAbsent(controllerPos, ignored -> new TreeMap<>());
104+
knownBeltParts.put(pos, new BeltInfo(pos, blockState, tileEntityData));
105+
106+
if (knownBeltParts.size() == length) {
107+
for (final Map.Entry<BlockPos, BeltInfo> entry : knownBeltParts.entrySet()) {
108+
final var info = entry.getValue();
109+
if (!world.setBlock(info.pos(), info.state(), Constants.UPDATE_FLAG)) {
110+
for (final var alreadyPlaced : knownBeltParts.headMap(entry.getKey()).values()) {
111+
world.removeBlock(alreadyPlaced.pos(), false);
112+
}
113+
return ActionProcessingResult.DENY;
114+
}
115+
handleTileEntityPlacement(info.tag(), world, info.pos(), placementContext.getRotationMirror());
116+
}
117+
beltParts.remove(controllerPos);
118+
beltItems.remove(controllerPos);
112119
}
120+
121+
return ActionProcessingResult.SUCCESS;
122+
}
113123
}

src/main/java/nl/motionlesstrain/createcolonies/placementhandlers/ChainConveyorPlacementHandler.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package nl.motionlesstrain.createcolonies.placementhandlers;
22

3-
import com.ldtteam.structurize.blueprints.v1.Blueprint;
4-
import com.ldtteam.structurize.util.PlacementSettings;
3+
import com.ldtteam.structurize.placement.IPlacementContext;
54
import net.minecraft.core.BlockPos;
65
import net.minecraft.nbt.CompoundTag;
76
import net.minecraft.nbt.ListTag;
@@ -29,7 +28,7 @@ public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState)
2928
}
3029

3130
@Override
32-
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, boolean b) {
31+
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag) {
3332
if (compoundTag != null) {
3433
final ListTag connections = compoundTag.getList("Connections", Tag.TAG_COMPOUND);
3534
final int neededChains = connections.stream().map(CompoundTag.class::cast).map(BlockPosUtil::fromNBT).filter(connectionPos ->
@@ -46,7 +45,7 @@ private record ConveyorInfo(BlockPos pos, BlockPos newBlockPos, CompoundTag bloc
4645
private Map<BlockPos, Map<BlockPos, ConveyorInfo>> connections = new HashMap<>();
4746

4847
@Override
49-
public ActionProcessingResult handle(Blueprint blueprint, Level world, BlockPos pos, BlockState blockState, @Nullable CompoundTag tileEntityData, boolean complete, BlockPos centerPos, PlacementSettings settings) {
48+
public ActionProcessingResult handle(Level world, BlockPos pos, BlockState blockState, @Nullable CompoundTag tileEntityData, IPlacementContext placementContext) {
5049
if (tileEntityData != null) {
5150
final ListTag connections = tileEntityData.getList("Connections", Tag.TAG_COMPOUND);
5251
final ListTag newConnections = new ListTag();
@@ -56,13 +55,13 @@ public ActionProcessingResult handle(Blueprint blueprint, Level world, BlockPos
5655
for (int i = 0; i < connections.size(); i++) {
5756
final CompoundTag connection = connections.getCompound(i);
5857
final BlockPos blockPos = BlockPosUtil.fromNBT(connection);
59-
final BlockPos newBlockPos = blockPos.rotate(blueprint.getRotationMirror().rotation());
58+
final BlockPos newBlockPos = blockPos.rotate(placementContext.getRotationMirror().rotation);
6059

6160
if (existingConnections.containsKey(newBlockPos)) {
6261
final ConveyorInfo info = existingConnections.remove(newBlockPos);
6362
final ListTag infoConnections = info.blockEntity().getList("Connections", Tag.TAG_COMPOUND);
6463
infoConnections.add(BlockPosUtil.toNBT(info.newBlockPos()));
65-
handleTileEntityPlacement(info.blockEntity(), world, info.pos());
64+
handleTileEntityPlacement(info.blockEntity(), world, info.pos(), placementContext.getRotationMirror());
6665

6766
newConnections.add(BlockPosUtil.toNBT(newBlockPos));
6867
} else {
@@ -73,6 +72,6 @@ public ActionProcessingResult handle(Blueprint blueprint, Level world, BlockPos
7372
}
7473
tileEntityData.put("Connections", newConnections);
7574
}
76-
return super.handle(blueprint, world, pos, blockState, tileEntityData, complete, centerPos, settings);
75+
return super.handle(world, pos, blockState, tileEntityData, placementContext);
7776
}
7877
}

src/main/java/nl/motionlesstrain/createcolonies/placementhandlers/CopyCatPlacementHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState)
2121
}
2222

2323
@Override
24-
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, boolean b) {
24+
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag) {
2525
final List<ItemStack> itemList = new ArrayList<>();
2626
itemList.add(BlockUtils.getItemStackFromBlockState(blockState));
2727
if (compoundTag != null && compoundTag.contains("Item", Tag.TAG_COMPOUND)) {

src/main/java/nl/motionlesstrain/createcolonies/placementhandlers/DeployerPlacementHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState)
2222
}
2323

2424
@Override
25-
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, boolean b) {
25+
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag) {
2626
final List<ItemStack> neededItems = new ArrayList<>();
2727
neededItems.add(ItemUtils.stackFromNullable(Items.deployer));
2828
if (compoundTag != null && compoundTag.contains("Inventory", Tag.TAG_LIST)) {

src/main/java/nl/motionlesstrain/createcolonies/placementhandlers/EncasedPipePlacementHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package nl.motionlesstrain.createcolonies.placementhandlers;
22

3-
import com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler;
43
import net.minecraft.core.BlockPos;
54
import net.minecraft.nbt.CompoundTag;
65
import net.minecraft.world.item.ItemStack;
@@ -19,7 +18,7 @@ public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState)
1918
}
2019

2120
@Override
22-
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, boolean b) {
21+
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag) {
2322
return List.of(ItemUtils.stackFromNullable(CreateResources.Items.fluidPipe));
2423
}
2524
}

src/main/java/nl/motionlesstrain/createcolonies/placementhandlers/EncasedShaftPlacementHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package nl.motionlesstrain.createcolonies.placementhandlers;
22

3-
import com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler;
43
import net.minecraft.core.BlockPos;
54
import net.minecraft.nbt.CompoundTag;
65
import net.minecraft.world.item.ItemStack;
@@ -20,7 +19,7 @@ public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState)
2019
}
2120

2221
@Override
23-
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, boolean b) {
22+
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag) {
2423
return List.of(ItemUtils.stackFromNullable(CreateResources.Items.shaft));
2524
}
2625
}

src/main/java/nl/motionlesstrain/createcolonies/placementhandlers/GearPlacementHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState)
3030
}
3131

3232
@Override
33-
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, boolean b) {
33+
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag) {
3434
final ItemStack requirement = gearRequirements.get(blockState.getBlock());
3535
return requirement == null ? List.of() : List.of(requirement);
3636
}
Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
package nl.motionlesstrain.createcolonies.placementhandlers;
22

33
import com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler;
4-
import com.ldtteam.structurize.util.BlockUtils;
5-
import com.mojang.logging.LogUtils;
6-
import net.minecraft.core.BlockPos;
7-
import net.minecraft.nbt.CompoundTag;
8-
import net.minecraft.world.item.ItemStack;
9-
import net.minecraft.world.level.Level;
10-
import net.minecraft.world.level.block.state.BlockState;
114
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
12-
import nl.motionlesstrain.createcolonies.CommonConfig;
13-
import org.jetbrains.annotations.Nullable;
14-
import org.slf4j.Logger;
15-
16-
import java.util.List;
175

186
public class PlacementHandlers {
197
private static void addHandler(IPlacementHandler handler) {
@@ -30,24 +18,5 @@ public static void initialiseHandlers(FMLLoadCompleteEvent ignored) {
3018
addHandler(new TrainBogeyPlacementHandler());
3119
addHandler(new TrainStationPlacementHandler());
3220
addHandler(new TrackPlacementHandler());
33-
if (CommonConfig.debugLog) {
34-
addHandler(new DebugPlacementHandler());
35-
}
36-
}
37-
38-
private static class DebugPlacementHandler implements IPlacementHandler {
39-
private static final Logger LOGGER = LogUtils.getLogger();
40-
41-
@Override
42-
public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState) {
43-
LOGGER.debug("Trying to handle block state {} at position {}, needing items {} if not overridden", blockState, blockPos,
44-
BlockUtils.getItemStackFromBlockState(blockState));
45-
return false;
46-
}
47-
48-
@Override
49-
public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockState blockState, @Nullable CompoundTag compoundTag, boolean b) {
50-
return List.of();
51-
}
5221
}
5322
}

0 commit comments

Comments
 (0)