diff --git a/src/main/java/net/minecraftforge/common/property/ExtendedBlockState.java b/src/main/java/net/minecraftforge/common/property/ExtendedBlockState.java index 6f92b9989e..ddb6f706d5 100644 --- a/src/main/java/net/minecraftforge/common/property/ExtendedBlockState.java +++ b/src/main/java/net/minecraftforge/common/property/ExtendedBlockState.java @@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableTable; import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -75,51 +74,36 @@ public class ExtendedBlockState extends BlockStateContainer protected StateImplementation createState(@Nonnull Block block, @Nonnull ImmutableMap, Comparable> properties, @Nullable ImmutableMap, Optional> unlistedProperties) { if (unlistedProperties == null || unlistedProperties.isEmpty()) return super.createState(block, properties, unlistedProperties); - return new ExtendedStateImplementation(block, properties, unlistedProperties, null); + return new ExtendedStateImplementation(block, properties, unlistedProperties, null, null); } protected static class ExtendedStateImplementation extends StateImplementation implements IExtendedBlockState { private final ImmutableMap, Optional> unlistedProperties; - private Map, Comparable>, BlockStateContainer.StateImplementation> normalMap; + private IBlockState cleanState; - protected ExtendedStateImplementation(Block block, ImmutableMap, Comparable> properties, ImmutableMap, Optional> unlistedProperties, @Nullable ImmutableTable, Comparable, IBlockState> table) + protected ExtendedStateImplementation(Block block, ImmutableMap, Comparable> properties, ImmutableMap, Optional> unlistedProperties, @Nullable ImmutableTable, Comparable, IBlockState> table, IBlockState clean) { - super(block, properties); + super(block, properties, table); this.unlistedProperties = unlistedProperties; - this.propertyValueTable = table; + this.cleanState = clean == null ? this : clean; } @Override @Nonnull public , V extends T> IBlockState withProperty(@Nonnull IProperty property, @Nonnull V value) { - if (!this.getProperties().containsKey(property)) - { - throw new IllegalArgumentException("Cannot set property " + property + " as it does not exist in " + getBlock().getBlockState()); + IBlockState clean = super.withProperty(property, value); + if (clean == this.cleanState) { + return this; } - else - { - if (!property.getAllowedValues().contains(value)) - { - throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on block " + Block.REGISTRY.getNameForObject(getBlock()) + ", it is not an allowed value"); - } else - { - if (this.getProperties().get(property) == value) - { - return this; - } - Map, Comparable> map = Maps.newHashMap(getProperties()); - map.put(property, value); - if (Iterables.all(unlistedProperties.values(), Predicates.>equalTo(Optional.empty()))) - { // no dynamic properties present, looking up in the normal table - return normalMap.get(map); - } - ImmutableTable, Comparable, IBlockState> table = propertyValueTable; - table = ((StateImplementation) table.get(property, value)).getPropertyValueTable(); - return new ExtendedStateImplementation(getBlock(), ImmutableMap.copyOf(map), unlistedProperties, table).setMap(this.normalMap); - } + + if (Iterables.all(unlistedProperties.values(), Predicates.>equalTo(Optional.empty()))) + { // no dynamic properties present, looking up in the normal table + return clean; } + + return new ExtendedStateImplementation(getBlock(), clean.getProperties(), unlistedProperties, ((StateImplementation)clean).getPropertyValueTable(), this.cleanState); } @Override @@ -137,9 +121,9 @@ public class ExtendedBlockState extends BlockStateContainer newMap.put(property, Optional.ofNullable(value)); if(Iterables.all(newMap.values(), Predicates.>equalTo(Optional.empty()))) { // no dynamic properties, lookup normal state - return (IExtendedBlockState) normalMap.get(getProperties()); + return (IExtendedBlockState)cleanState; } - return new ExtendedStateImplementation(getBlock(), getProperties(), ImmutableMap.copyOf(newMap), propertyValueTable).setMap(this.normalMap); + return new ExtendedStateImplementation(getBlock(), getProperties(), ImmutableMap.copyOf(newMap), propertyValueTable, this.cleanState); } @Override @@ -158,29 +142,15 @@ public class ExtendedBlockState extends BlockStateContainer return property.getType().cast(this.unlistedProperties.get(property).orElse(null)); } - @Override public ImmutableMap, Optional> getUnlistedProperties() { return unlistedProperties; } - @Override - public void buildPropertyValueTable(Map, Comparable>, BlockStateContainer.StateImplementation> map) - { - this.normalMap = map; - super.buildPropertyValueTable(map); - } - - private ExtendedStateImplementation setMap(Map, Comparable>, BlockStateContainer.StateImplementation> map) - { - this.normalMap = map; - return this; - } - @Override public IBlockState getClean() { - return this.normalMap.get(getProperties()); + return cleanState; } } -} \ No newline at end of file +}