From d52e5b0970d96f00b0909d9b8039d06ada6714c3 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 19 Nov 2024 15:54:49 +0000 Subject: [PATCH] fix: correctly check for properties in thaw/snow (#2976) --- .../java/com/sk89q/worldedit/EditSession.java | 2 +- .../function/block/SnowSimulator.java | 24 +++++++++---------- .../registry/state/AbstractProperty.java | 4 ++-- .../worldedit/world/block/BlockState.java | 2 +- .../worldedit/world/block/BlockType.java | 14 ++++------- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 95bffb681..7986ee366 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2788,7 +2788,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { if (setBlock(mutable, air)) { if (y > getMinY()) { BlockState block = getBlock(mutable2); - if (block.getStates().containsKey(snowy)) { + if (block.getBlockType().hasProperty(snowy)) { if (setBlock(mutable2, block.with(snowy, false))) { affected++; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/SnowSimulator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/SnowSimulator.java index 962fb3c7d..e64bb69bb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/SnowSimulator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/SnowSimulator.java @@ -26,11 +26,12 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.BooleanProperty; import com.sk89q.worldedit.registry.state.EnumProperty; import com.sk89q.worldedit.registry.state.Property; +import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.Locale; -import java.util.Map; public class SnowSimulator implements LayerFunction { @@ -120,22 +121,19 @@ public class SnowSimulator implements LayerFunction { abovePosition) > 10) { return false; } else if (!block.getBlockType().getMaterial().isFullCube()) { - Map, Object> states = block.getStates(); - if (states.containsKey(slab) && block.getState(slab).equalsIgnoreCase("bottom")) { + BlockType type = block.getBlockType(); + if (type.hasProperty(slab) && block.getState(slab).equalsIgnoreCase("bottom")) { return false; - } else if (states.containsKey(trapdoorOpen) && states.containsKey(trapdoor) && (block.getState(trapdoorOpen) - || block.getState(trapdoor).equalsIgnoreCase("bottom"))) { + } else if ((type.hasProperty(trapdoorOpen) && block.getState(trapdoorOpen)) || + (type.hasProperty(trapdoor) && block.getState(trapdoor).equalsIgnoreCase("bottom"))) { return false; - } else if (states.containsKey(stair) && block.getState(stair).equalsIgnoreCase("bottom")) { + } else if (type.hasProperty(stair) && block.getState(stair).equalsIgnoreCase("bottom")) { return false; } else { return false; } //FAWE end - } else if (!block.getBlockType().id().toLowerCase(Locale.ROOT).contains("ice") && block - .getBlockType() - .getMaterial() - .isTranslucent()) { + } else if (!BlockCategories.SNOW_LAYER_CAN_SURVIVE_ON.contains(block.getBlockType())) { return false; } @@ -144,14 +142,14 @@ public class SnowSimulator implements LayerFunction { // We've hit the highest layer (If it doesn't contain current + 2 it means it's 1 away from full) if (!snowLayersProperty.getValues().contains(currentHeight + 2)) { if (this.extent.setBlock(abovePosition, snowBlock)) { - if (block.getStates().containsKey(snowy)) { + if (block.getBlockType().hasProperty(snowy)) { this.extent.setBlock(position, block.with(snowy, true)); } this.affected++; } } else { if (this.extent.setBlock(abovePosition, above.with(snowLayersProperty, currentHeight + 1))) { - if (block.getStates().containsKey(snowy)) { + if (block.getBlockType().hasProperty(snowy)) { this.extent.setBlock(position, block.with(snowy, true)); } this.affected++; @@ -160,7 +158,7 @@ public class SnowSimulator implements LayerFunction { return false; } if (this.extent.setBlock(abovePosition, snow)) { - if (block.getStates().containsKey(snowy)) { + if (block.getBlockType().hasProperty(snowy)) { this.extent.setBlock(position, block.with(snowy, true)); } this.affected++; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java index e248ad5cb..423e47263 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java @@ -140,10 +140,10 @@ public abstract class AbstractProperty implements Property { @Override public boolean equals(Object obj) { - if (!(obj instanceof Property)) { + if (!(obj instanceof Property property)) { return false; } - return getName().equals(((Property) obj).getName()); + return getName().equals(property.getName()) && property.getValues().equals(getValues()); } //FAWE end } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index b6a12cb7c..0be6d43c8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -366,7 +366,7 @@ public class BlockState implements BlockStateHolder, Pattern { BlockState newState = this; for (Property prop : ot.getProperties()) { PropertyKey key = prop.getKey(); - if (blockType.hasPropertyOfType(key, prop.getClass())) { + if (blockType.hasProperty(prop)) { newState = newState.with(key, other.getState(key)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index e72d0b0e3..eb53032b2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -248,18 +248,14 @@ public class BlockType implements Keyed, Pattern { } /** - * {@return whether this block type has a property with given key of the given type} + * {@return whether this block type has a given property} * - * @param key the key identifying the property - * @param propertyType the expected type of the property + * @param property the expected property * @since TODO */ - public boolean hasPropertyOfType(PropertyKey key, Class propertyType) { - int ordinal = key.getId(); - Property property; - return this.settings.propertiesMapArr.length > ordinal - && (property = this.settings.propertiesMapArr[ordinal]) != null - && property.getClass() == propertyType; + public boolean hasProperty(Property property) { + int ordinal = property.getKey().getId(); + return this.settings.propertiesMapArr.length > ordinal && property.equals(this.settings.propertiesMapArr[ordinal]); } public Property getProperty(PropertyKey key) {