Files
CatServer/patches/net/minecraft/block/state/BlockStateContainer.java.patch
2019-02-24 22:29:41 +08:00

161 lines
6.9 KiB
Diff

--- ../src-base/minecraft/net/minecraft/block/state/BlockStateContainer.java
+++ ../src-work/minecraft/net/minecraft/block/state/BlockStateContainer.java
@@ -59,6 +59,16 @@
public BlockStateContainer(Block blockIn, IProperty<?>... properties)
{
+ this(blockIn, properties, null);
+ }
+
+ protected StateImplementation createState(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<net.minecraftforge.common.property.IUnlistedProperty<?>, java.util.Optional<?>> unlistedProperties)
+ {
+ return new StateImplementation(block, properties);
+ }
+
+ protected BlockStateContainer(Block blockIn, IProperty<?>[] properties, ImmutableMap<net.minecraftforge.common.property.IUnlistedProperty<?>, java.util.Optional<?>> unlistedProperties)
+ {
this.block = blockIn;
Map < String, IProperty<? >> map = Maps. < String, IProperty<? >> newHashMap();
@@ -69,18 +79,18 @@
}
this.properties = ImmutableSortedMap.copyOf(map);
- Map < Map < IProperty<?>, Comparable<? >> , BlockStateContainer.StateImplementation > map2 = Maps. < Map < IProperty<?>, Comparable<? >> , BlockStateContainer.StateImplementation > newLinkedHashMap();
- List<BlockStateContainer.StateImplementation> list1 = Lists.<BlockStateContainer.StateImplementation>newArrayList();
+ Map < Map < IProperty<?>, Comparable<? >> , StateImplementation > map2 = Maps. < Map < IProperty<?>, Comparable<? >> , StateImplementation > newLinkedHashMap();
+ List<StateImplementation> list1 = Lists.<StateImplementation>newArrayList();
for (List < Comparable<? >> list : Cartesian.cartesianProduct(this.getAllowedValues()))
{
Map < IProperty<?>, Comparable<? >> map1 = MapPopulator. < IProperty<?>, Comparable<? >> createMap(this.properties.values(), list);
- BlockStateContainer.StateImplementation blockstatecontainer$stateimplementation = new BlockStateContainer.StateImplementation(blockIn, ImmutableMap.copyOf(map1));
+ StateImplementation blockstatecontainer$stateimplementation = createState(blockIn, ImmutableMap.copyOf(map1), unlistedProperties);
map2.put(map1, blockstatecontainer$stateimplementation);
list1.add(blockstatecontainer$stateimplementation);
}
- for (BlockStateContainer.StateImplementation blockstatecontainer$stateimplementation1 : list1)
+ for (StateImplementation blockstatecontainer$stateimplementation1 : list1)
{
blockstatecontainer$stateimplementation1.buildPropertyValueTable(map2);
}
@@ -170,6 +180,13 @@
this.properties = propertiesIn;
}
+ protected StateImplementation(Block blockIn, ImmutableMap<IProperty<?>, Comparable<?>> propertiesIn, ImmutableTable<IProperty<?>, Comparable<?>, IBlockState> propertyValueTable)
+ {
+ this.block = blockIn;
+ this.properties = propertiesIn;
+ this.propertyValueTable = propertyValueTable;
+ }
+
public Collection < IProperty<? >> getPropertyKeys()
{
return Collections. < IProperty<? >> unmodifiableCollection(this.properties.keySet());
@@ -236,7 +253,7 @@
return this.properties.hashCode();
}
- public void buildPropertyValueTable(Map < Map < IProperty<?>, Comparable<? >> , BlockStateContainer.StateImplementation > map)
+ public void buildPropertyValueTable(Map < Map < IProperty<?>, Comparable<? >> , StateImplementation > map)
{
if (this.propertyValueTable != null)
{
@@ -473,5 +490,94 @@
{
return this.block.getBlockFaceShape(worldIn, this, pos, facing);
}
+
+ //Forge Start
+ @Override
+ public ImmutableTable<IProperty<?>, Comparable<?>, IBlockState> getPropertyValueTable()
+ {
+ return propertyValueTable;
+ }
+
+ @Override
+ public int getLightOpacity(IBlockAccess world, BlockPos pos)
+ {
+ return this.block.getLightOpacity(this, world, pos);
+ }
+
+ @Override
+ public int getLightValue(IBlockAccess world, BlockPos pos)
+ {
+ return this.block.getLightValue(this, world, pos);
+ }
+
+ @Override
+ public boolean isSideSolid(IBlockAccess world, BlockPos pos, EnumFacing side)
+ {
+ return this.block.isSideSolid(this, world, pos, side);
+ }
+
+ @Override
+ public boolean doesSideBlockChestOpening(IBlockAccess world, BlockPos pos, EnumFacing side)
+ {
+ return this.block.doesSideBlockChestOpening(this, world, pos, side);
+ }
+
+ @Override
+ public boolean doesSideBlockRendering(IBlockAccess world, BlockPos pos, EnumFacing side)
+ {
+ return this.block.doesSideBlockRendering(this, world, pos, side);
+ }
}
+
+ /**
+ * Forge added class to make building things easier.
+ * Will return an instance of BlockStateContainer appropriate for
+ * the list of properties passed in.
+ *
+ * Example usage:
+ *
+ * protected BlockStateContainer createBlockState()
+ * {
+ * return (new BlockStateContainer.Builder(this)).add(FACING).add(SOME_UNLISTED).build();
+ * }
+ *
+ */
+ public static class Builder
+ {
+ private final Block block;
+ private final List<IProperty<?>> listed = Lists.newArrayList();
+ private final List<net.minecraftforge.common.property.IUnlistedProperty<?>> unlisted = Lists.newArrayList();
+
+ public Builder(Block block)
+ {
+ this.block = block;
+ }
+
+ public Builder add(IProperty<?>... props)
+ {
+ for (IProperty<?> prop : props)
+ this.listed.add(prop);
+ return this;
+ }
+
+ public Builder add(net.minecraftforge.common.property.IUnlistedProperty<?>... props)
+ {
+ for (net.minecraftforge.common.property.IUnlistedProperty<?> prop : props)
+ this.unlisted.add(prop);
+ return this;
+ }
+
+ public BlockStateContainer build()
+ {
+ IProperty<?>[] listed = new IProperty[this.listed.size()];
+ listed = this.listed.toArray(listed);
+ if (this.unlisted.size() == 0)
+ return new BlockStateContainer(this.block, listed);
+
+ net.minecraftforge.common.property.IUnlistedProperty<?>[] unlisted = new net.minecraftforge.common.property.IUnlistedProperty[this.unlisted.size()];
+ unlisted = this.unlisted.toArray(unlisted);
+
+ return new net.minecraftforge.common.property.ExtendedBlockState(this.block, listed, unlisted);
+ }
+ }
}