Skip to content

Commit d52e5b0

Browse files
authored
fix: correctly check for properties in thaw/snow (#2976)
1 parent b198a75 commit d52e5b0

File tree

5 files changed

+20
-26
lines changed

5 files changed

+20
-26
lines changed

worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,7 @@ public int thaw(BlockVector3 position, double radius, int height)
27882788
if (setBlock(mutable, air)) {
27892789
if (y > getMinY()) {
27902790
BlockState block = getBlock(mutable2);
2791-
if (block.getStates().containsKey(snowy)) {
2791+
if (block.getBlockType().hasProperty(snowy)) {
27922792
if (setBlock(mutable2, block.with(snowy, false))) {
27932793
affected++;
27942794
}

worldedit-core/src/main/java/com/sk89q/worldedit/function/block/SnowSimulator.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
import com.sk89q.worldedit.registry.state.BooleanProperty;
2727
import com.sk89q.worldedit.registry.state.EnumProperty;
2828
import com.sk89q.worldedit.registry.state.Property;
29+
import com.sk89q.worldedit.world.block.BlockCategories;
2930
import com.sk89q.worldedit.world.block.BlockState;
31+
import com.sk89q.worldedit.world.block.BlockType;
3032
import com.sk89q.worldedit.world.block.BlockTypes;
3133

3234
import java.util.Locale;
33-
import java.util.Map;
3435

3536
public class SnowSimulator implements LayerFunction {
3637

@@ -120,22 +121,19 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException
120121
abovePosition) > 10) {
121122
return false;
122123
} else if (!block.getBlockType().getMaterial().isFullCube()) {
123-
Map<Property<?>, Object> states = block.getStates();
124-
if (states.containsKey(slab) && block.getState(slab).equalsIgnoreCase("bottom")) {
124+
BlockType type = block.getBlockType();
125+
if (type.hasProperty(slab) && block.getState(slab).equalsIgnoreCase("bottom")) {
125126
return false;
126-
} else if (states.containsKey(trapdoorOpen) && states.containsKey(trapdoor) && (block.getState(trapdoorOpen)
127-
|| block.getState(trapdoor).equalsIgnoreCase("bottom"))) {
127+
} else if ((type.hasProperty(trapdoorOpen) && block.getState(trapdoorOpen)) ||
128+
(type.hasProperty(trapdoor) && block.getState(trapdoor).equalsIgnoreCase("bottom"))) {
128129
return false;
129-
} else if (states.containsKey(stair) && block.getState(stair).equalsIgnoreCase("bottom")) {
130+
} else if (type.hasProperty(stair) && block.getState(stair).equalsIgnoreCase("bottom")) {
130131
return false;
131132
} else {
132133
return false;
133134
}
134135
//FAWE end
135-
} else if (!block.getBlockType().id().toLowerCase(Locale.ROOT).contains("ice") && block
136-
.getBlockType()
137-
.getMaterial()
138-
.isTranslucent()) {
136+
} else if (!BlockCategories.SNOW_LAYER_CAN_SURVIVE_ON.contains(block.getBlockType())) {
139137
return false;
140138
}
141139

@@ -144,14 +142,14 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException
144142
// We've hit the highest layer (If it doesn't contain current + 2 it means it's 1 away from full)
145143
if (!snowLayersProperty.getValues().contains(currentHeight + 2)) {
146144
if (this.extent.setBlock(abovePosition, snowBlock)) {
147-
if (block.getStates().containsKey(snowy)) {
145+
if (block.getBlockType().hasProperty(snowy)) {
148146
this.extent.setBlock(position, block.with(snowy, true));
149147
}
150148
this.affected++;
151149
}
152150
} else {
153151
if (this.extent.setBlock(abovePosition, above.with(snowLayersProperty, currentHeight + 1))) {
154-
if (block.getStates().containsKey(snowy)) {
152+
if (block.getBlockType().hasProperty(snowy)) {
155153
this.extent.setBlock(position, block.with(snowy, true));
156154
}
157155
this.affected++;
@@ -160,7 +158,7 @@ public boolean apply(BlockVector3 position, int depth) throws WorldEditException
160158
return false;
161159
}
162160
if (this.extent.setBlock(abovePosition, snow)) {
163-
if (block.getStates().containsKey(snowy)) {
161+
if (block.getBlockType().hasProperty(snowy)) {
164162
this.extent.setBlock(position, block.with(snowy, true));
165163
}
166164
this.affected++;

worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ public void setName(final String name) {
140140

141141
@Override
142142
public boolean equals(Object obj) {
143-
if (!(obj instanceof Property)) {
143+
if (!(obj instanceof Property property)) {
144144
return false;
145145
}
146-
return getName().equals(((Property<?>) obj).getName());
146+
return getName().equals(property.getName()) && property.getValues().equals(getValues());
147147
}
148148
//FAWE end
149149
}

worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public <V> BlockState withProperties(final BlockState other) {
366366
BlockState newState = this;
367367
for (Property<?> prop : ot.getProperties()) {
368368
PropertyKey key = prop.getKey();
369-
if (blockType.hasPropertyOfType(key, prop.getClass())) {
369+
if (blockType.hasProperty(prop)) {
370370
newState = newState.with(key, other.getState(key));
371371
}
372372
}

worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,14 @@ public boolean hasProperty(PropertyKey key) {
248248
}
249249

250250
/**
251-
* {@return whether this block type has a property with given key of the given type}
251+
* {@return whether this block type has a given property}
252252
*
253-
* @param key the key identifying the property
254-
* @param propertyType the expected type of the property
253+
* @param property the expected property
255254
* @since TODO
256255
*/
257-
public boolean hasPropertyOfType(PropertyKey key, Class<?> propertyType) {
258-
int ordinal = key.getId();
259-
Property<?> property;
260-
return this.settings.propertiesMapArr.length > ordinal
261-
&& (property = this.settings.propertiesMapArr[ordinal]) != null
262-
&& property.getClass() == propertyType;
256+
public boolean hasProperty(Property<?> property) {
257+
int ordinal = property.getKey().getId();
258+
return this.settings.propertiesMapArr.length > ordinal && property.equals(this.settings.propertiesMapArr[ordinal]);
263259
}
264260

265261
public <V> Property<V> getProperty(PropertyKey key) {

0 commit comments

Comments
 (0)