diff --git a/src/main/java/fi/dy/masa/litematica/util/PlacementHandler.java b/src/main/java/fi/dy/masa/litematica/util/PlacementHandler.java index 33234d0c8c..bfd32dd136 100644 --- a/src/main/java/fi/dy/masa/litematica/util/PlacementHandler.java +++ b/src/main/java/fi/dy/masa/litematica/util/PlacementHandler.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Optional; import com.google.common.collect.ImmutableSet; + import net.minecraft.block.*; import net.minecraft.block.enums.BlockHalf; import net.minecraft.block.enums.ComparatorMode; @@ -39,9 +40,8 @@ public class PlacementHandler Properties.INVERTED, Properties.OPEN, //Properties.PERSISTENT, - // TODO --> TEST (Boolean) - Properties.POWERED, - Properties.LOCKED, + //Properties.POWERED, + //Properties.LOCKED, // EnumProperty: // ATTACHMENT - Bells // AXIS - Pillar @@ -81,6 +81,14 @@ public class PlacementHandler Properties.ROTATION ); + /** + * BlackList for Block States. Entries here will be reset to their default value. + */ + public static final ImmutableSet> BLACKLISTED_PROPERTIES = ImmutableSet.of( + Properties.WATERLOGGED, + Properties.POWERED + ); + public static EasyPlaceProtocol getEffectiveProtocolVersion() { EasyPlaceProtocol protocol = (EasyPlaceProtocol) Configs.Generic.EASY_PLACE_PROTOCOL.getOptionListValue(); @@ -181,7 +189,7 @@ else if (block instanceof ComparatorBlock) { state = state.with(Properties.BLOCK_HALF, protocolValue > 0 ? BlockHalf.TOP : BlockHalf.BOTTOM); } - + //System.out.printf("[PHv2] stateOut: %s\n", state.toString()); return state; @@ -237,10 +245,23 @@ public static > BlockState applyPlacementProtocolV3(Bloc { for (Property p : propList) { - //if (((p instanceof EnumProperty ep) && ep.getType().equals(Direction.class) == false) && + //System.out.printf("[PHv3] check property [%s], whitelisted [%s], blacklisted [%s]\n", p.getName(), WHITELISTED_PROPERTIES.contains(p), BLACKLISTED_PROPERTIES.contains(p)); + if ((property.isPresent() && !property.get().equals(p)) || (property.isEmpty()) && WHITELISTED_PROPERTIES.contains(p)) + //WHITELISTED_PROPERTIES.contains(p) && + //!BLACKLISTED_PROPERTIES.contains(p)) + + /* + if (property.isPresent() && property.get().equals(p)) + { + //System.out.printf("[PHv3] skipping prot val: 0x%08X [Property %s]\n", protocolValue, p.getName()); + continue; + } + else if (WHITELISTED_PROPERTIES.contains(p) && + !BLACKLISTED_PROPERTIES.contains(p)) + */ { @SuppressWarnings("unchecked") Property prop = (Property) p; @@ -250,6 +271,7 @@ public static > BlockState applyPlacementProtocolV3(Bloc int requiredBits = MathHelper.floorLog2(MathHelper.smallestEncompassingPowerOfTwo(list.size())); int bitMask = ~(0xFFFFFFFF << requiredBits); int valueIndex = protocolValue & bitMask; + //System.out.printf("[PHv3] trying to apply valInd: %d, bits: %d, prot val: 0x%08X [Property %s]\n", valueIndex, requiredBits, protocolValue, prop.getName()); if (valueIndex >= 0 && valueIndex < list.size()) @@ -277,6 +299,12 @@ public static > BlockState applyPlacementProtocolV3(Bloc protocolValue >>>= requiredBits; } } + /* + else + { + System.out.printf("[PHv3] skipping prot val: 0x%08X [Property %s]\n", protocolValue, p.getName()); + } + */ } } catch (Exception e) @@ -284,6 +312,20 @@ public static > BlockState applyPlacementProtocolV3(Bloc Litematica.logger.warn("Exception trying to apply placement protocol value", e); } + // Strip Blacklisted properties, and use the Block's default state. + // This needs to be done after the initial loop, or it breaks compatibility + for (Property p : BLACKLISTED_PROPERTIES) + { + if (state.contains(p)) + { + @SuppressWarnings("unchecked") + Property prop = (Property) p; + BlockState def = state.getBlock().getDefaultState(); + state = state.with(prop, def.get(prop)); + //System.out.printf("[PHv3] blacklisted state [%s] found, setting default value\n", prop.getName()); + } + } + if (state.canPlaceAt(context.getWorld(), context.getPos())) { //System.out.printf("[PHv3] validator passed for \"%s\"\n", state); diff --git a/src/main/java/fi/dy/masa/litematica/util/WorldUtils.java b/src/main/java/fi/dy/masa/litematica/util/WorldUtils.java index df31cb9727..f67b37f919 100644 --- a/src/main/java/fi/dy/masa/litematica/util/WorldUtils.java +++ b/src/main/java/fi/dy/masa/litematica/util/WorldUtils.java @@ -882,10 +882,23 @@ public static > Vec3d applyPlacementProtocolV3(BlockPos { for (Property p : propList) { - //if (((p instanceof EnumProperty ep) && ep.getType().equals(Direction.class) == false) && + //System.out.printf("(WorldUtils):v3: check property [%s], whitelisted [%s], blacklisted [%s]\n", p.getName(), PlacementHandler.WHITELISTED_PROPERTIES.contains(p), PlacementHandler.BLACKLISTED_PROPERTIES.contains(p)); + + /* if ((property.isPresent() && !property.get().equals(p)) || (property.isEmpty()) && PlacementHandler.WHITELISTED_PROPERTIES.contains(p)) + //PlacementHandler.WHITELISTED_PROPERTIES.contains(p) && + //!PlacementHandler.BLACKLISTED_PROPERTIES.contains(p)) + */ + + if (property.isPresent() && property.get().equals(p)) + { + //System.out.printf("(WorldUtils):v3: skipping prot val: 0x%08X [Property %s]\n", protocolValue, p.getName()); + continue; + } + if (PlacementHandler.WHITELISTED_PROPERTIES.contains(p) && + !PlacementHandler.BLACKLISTED_PROPERTIES.contains(p)) { @SuppressWarnings("unchecked") Property prop = (Property) p; @@ -905,6 +918,12 @@ public static > Vec3d applyPlacementProtocolV3(BlockPos ++propCount; } } + /* + else + { + System.out.printf("(WorldUtils):v3: skipping prot val: 0x%08X [Property %s]\n", protocolValue, p.getName()); + } + */ } } catch (Exception e)