From 219cd153f9e0e82bea7dcdc97411d41e8ff9fb97 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 3 Nov 2024 11:45:13 +0000 Subject: [PATCH 1/4] fix: correctly check for properties in thaw/snow - fixes #2963 --- .../java/com/sk89q/worldedit/EditSession.java | 2 +- .../function/block/SnowSimulator.java | 21 +++++++++---------- .../worldedit/world/block/BlockType.java | 3 ++- 3 files changed, 13 insertions(+), 13 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 95bffb6818..675102809f 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 int thaw(BlockVector3 position, double radius, int height) if (setBlock(mutable, air)) { if (y > getMinY()) { BlockState block = getBlock(mutable2); - if (block.getStates().containsKey(snowy)) { + if (block.getBlockType().hasPropertyOfType(snowy.getKey(), snowy.getClass())) { 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 962fb3c7d3..f24acc7fb9 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 @@ -27,10 +27,10 @@ import com.sk89q.worldedit.registry.state.EnumProperty; import com.sk89q.worldedit.registry.state.Property; 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,20 +120,19 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException 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.hasPropertyOfType(slab.getKey(), slab.getClass()) && 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.hasPropertyOfType(trapdoorOpen.getKey(), trapdoorOpen.getClass()) && block.getState(trapdoorOpen)) || + (type.hasPropertyOfType(trapdoor.getKey(), trapdoor.getClass()) && block.getState(trapdoor).equalsIgnoreCase("bottom"))) { return false; - } else if (states.containsKey(stair) && block.getState(stair).equalsIgnoreCase("bottom")) { + } else if (type.hasPropertyOfType(stair.getKey(), stair.getClass()) && block.getState(stair).equalsIgnoreCase("bottom")) { return false; } else { return false; } //FAWE end - } else if (!block.getBlockType().id().toLowerCase(Locale.ROOT).contains("ice") && block - .getBlockType() + } else if (!block.getBlockType().id().toLowerCase(Locale.ROOT).contains("ice") && block.getBlockType() .getMaterial() .isTranslucent()) { return false; @@ -144,14 +143,14 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException // 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().hasPropertyOfType(snowy.getKey(), snowy.getClass())) { 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().hasPropertyOfType(snowy.getKey(), snowy.getClass())) { this.extent.setBlock(position, block.with(snowy, true)); } this.affected++; @@ -160,7 +159,7 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException return false; } if (this.extent.setBlock(abovePosition, snow)) { - if (block.getStates().containsKey(snowy)) { + if (block.getBlockType().hasPropertyOfType(snowy.getKey(), snowy.getClass())) { this.extent.setBlock(position, block.with(snowy, true)); } this.affected++; 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 e72d0b0e3f..b66142e934 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 @@ -254,7 +254,8 @@ public boolean hasProperty(PropertyKey key) { * @param propertyType the expected type of the property * @since TODO */ - public boolean hasPropertyOfType(PropertyKey key, Class propertyType) { + @SuppressWarnings("rawtypes") + public boolean hasPropertyOfType(PropertyKey key, Class propertyType) { int ordinal = key.getId(); Property property; return this.settings.propertiesMapArr.length > ordinal From 2c1a212d00ea019067475a15c807bc87023cc84d Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 3 Nov 2024 13:23:09 +0000 Subject: [PATCH 2/4] fix: fully compare properties --- .../java/com/sk89q/worldedit/EditSession.java | 2 +- .../worldedit/function/block/SnowSimulator.java | 14 +++++++------- .../registry/state/AbstractProperty.java | 4 ++-- .../sk89q/worldedit/world/block/BlockState.java | 2 +- .../sk89q/worldedit/world/block/BlockType.java | 16 +++++++--------- 5 files changed, 18 insertions(+), 20 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 675102809f..7986ee366d 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 int thaw(BlockVector3 position, double radius, int height) if (setBlock(mutable, air)) { if (y > getMinY()) { BlockState block = getBlock(mutable2); - if (block.getBlockType().hasPropertyOfType(snowy.getKey(), snowy.getClass())) { + 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 f24acc7fb9..d1aa4ee912 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 @@ -121,12 +121,12 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException return false; } else if (!block.getBlockType().getMaterial().isFullCube()) { BlockType type = block.getBlockType(); - if (type.hasPropertyOfType(slab.getKey(), slab.getClass()) && block.getState(slab).equalsIgnoreCase("bottom")) { + if (type.hasProperty(slab) && block.getState(slab).equalsIgnoreCase("bottom")) { return false; - } else if ((type.hasPropertyOfType(trapdoorOpen.getKey(), trapdoorOpen.getClass()) && block.getState(trapdoorOpen)) || - (type.hasPropertyOfType(trapdoor.getKey(), trapdoor.getClass()) && 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 (type.hasPropertyOfType(stair.getKey(), stair.getClass()) && block.getState(stair).equalsIgnoreCase("bottom")) { + } else if (type.hasProperty(stair) && block.getState(stair).equalsIgnoreCase("bottom")) { return false; } else { return false; @@ -143,14 +143,14 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException // 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.getBlockType().hasPropertyOfType(snowy.getKey(), snowy.getClass())) { + 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.getBlockType().hasPropertyOfType(snowy.getKey(), snowy.getClass())) { + if (block.getBlockType().hasProperty(snowy)) { this.extent.setBlock(position, block.with(snowy, true)); } this.affected++; @@ -159,7 +159,7 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException return false; } if (this.extent.setBlock(abovePosition, snow)) { - if (block.getBlockType().hasPropertyOfType(snowy.getKey(), snowy.getClass())) { + 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 e248ad5cb6..423e472639 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 void setName(final String name) { @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 95f2c2585f..0107385122 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 @@ -351,7 +351,7 @@ public BlockState withProperties(final BlockState other) { 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 b66142e934..dd00660780 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,19 +248,17 @@ public boolean hasProperty(PropertyKey key) { } /** - * {@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 */ - @SuppressWarnings("rawtypes") - public boolean hasPropertyOfType(PropertyKey key, Class propertyType) { - int ordinal = key.getId(); - Property property; + public boolean hasProperty(Property property) { + int ordinal = property.getKey().getId(); + Property selfProperty; return this.settings.propertiesMapArr.length > ordinal - && (property = this.settings.propertiesMapArr[ordinal]) != null - && property.getClass() == propertyType; + && (selfProperty = this.settings.propertiesMapArr[ordinal]) != null + && selfProperty == property; } public Property getProperty(PropertyKey key) { From 0517852acf3ae74b344ce8e71a40d35d14d31469 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Mon, 4 Nov 2024 17:45:47 +0000 Subject: [PATCH 3/4] Use block category --- .../com/sk89q/worldedit/function/block/SnowSimulator.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 d1aa4ee912..e64bb69bb1 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,6 +26,7 @@ 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; @@ -132,9 +133,7 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException 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; } From 013982d73e7ecc77123ca933f86d9def46894d11 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 16 Nov 2024 11:02:32 +0000 Subject: [PATCH 4/4] Use AbstractProperty#equals --- .../main/java/com/sk89q/worldedit/world/block/BlockType.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 dd00660780..eb53032b21 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 @@ -255,10 +255,7 @@ public boolean hasProperty(PropertyKey key) { */ public boolean hasProperty(Property property) { int ordinal = property.getKey().getId(); - Property selfProperty; - return this.settings.propertiesMapArr.length > ordinal - && (selfProperty = this.settings.propertiesMapArr[ordinal]) != null - && selfProperty == property; + return this.settings.propertiesMapArr.length > ordinal && property.equals(this.settings.propertiesMapArr[ordinal]); } public Property getProperty(PropertyKey key) {