diff --git a/patches/minecraft/net/minecraft/block/state/BlockState.java.patch b/patches/minecraft/net/minecraft/block/state/BlockState.java.patch index 90b08e76e..7168f0548 100644 --- a/patches/minecraft/net/minecraft/block/state/BlockState.java.patch +++ b/patches/minecraft/net/minecraft/block/state/BlockState.java.patch @@ -26,7 +26,21 @@ linkedhashmap.put(map, stateimplementation); arraylist.add(stateimplementation); } -@@ -231,5 +241,10 @@ +@@ -135,6 +145,13 @@ + this.field_177239_a = p_i45660_1_; + this.field_177237_b = p_i45660_2_; + } ++ ++ protected StateImplementation(Block blockIn, ImmutableMap propertiesIn, ImmutableTable propertyValueTable) ++ { ++ this.field_177239_a = blockIn; ++ this.field_177237_b = propertiesIn; ++ this.field_177238_c = propertyValueTable; ++ } + + public Collection func_177227_a() + { +@@ -231,5 +248,10 @@ { this(p_i45661_1_, p_i45661_2_); } diff --git a/patches/minecraft/net/minecraft/block/state/BlockStateBase.java.patch b/patches/minecraft/net/minecraft/block/state/BlockStateBase.java.patch new file mode 100644 index 000000000..9587997da --- /dev/null +++ b/patches/minecraft/net/minecraft/block/state/BlockStateBase.java.patch @@ -0,0 +1,12 @@ +--- ../src-base/minecraft/net/minecraft/block/state/BlockStateBase.java ++++ ../src-work/minecraft/net/minecraft/block/state/BlockStateBase.java +@@ -76,4 +76,9 @@ + + return stringbuilder.toString(); + } ++ ++ public com.google.common.collect.ImmutableTable getPropertyValueTable() ++ { ++ return null; ++ } + } diff --git a/patches/minecraft/net/minecraft/world/chunk/storage/ExtendedBlockStorage.java.patch b/patches/minecraft/net/minecraft/world/chunk/storage/ExtendedBlockStorage.java.patch new file mode 100644 index 000000000..34fba0645 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/chunk/storage/ExtendedBlockStorage.java.patch @@ -0,0 +1,11 @@ +--- ../src-base/minecraft/net/minecraft/world/chunk/storage/ExtendedBlockStorage.java ++++ ../src-work/minecraft/net/minecraft/world/chunk/storage/ExtendedBlockStorage.java +@@ -35,6 +35,8 @@ + + public void func_177484_a(int p_177484_1_, int p_177484_2_, int p_177484_3_, IBlockState p_177484_4_) + { ++ if (p_177484_4_ instanceof net.minecraftforge.common.property.IExtendedBlockState) ++ p_177484_4_ = ((net.minecraftforge.common.property.IExtendedBlockState) p_177484_4_).getClean(); + IBlockState iblockstate1 = this.func_177485_a(p_177484_1_, p_177484_2_, p_177484_3_); + Block block = iblockstate1.func_177230_c(); + Block block1 = p_177484_4_.func_177230_c(); diff --git a/src/main/java/net/minecraftforge/common/property/ExtendedBlockState.java b/src/main/java/net/minecraftforge/common/property/ExtendedBlockState.java index 967791046..e213a7f0a 100644 --- a/src/main/java/net/minecraftforge/common/property/ExtendedBlockState.java +++ b/src/main/java/net/minecraftforge/common/property/ExtendedBlockState.java @@ -47,6 +47,7 @@ public class ExtendedBlockState extends BlockState @Override protected StateImplementation createState(Block block, ImmutableMap properties, ImmutableMap unlistedProperties) { + if (unlistedProperties == null || unlistedProperties.isEmpty()) return super.createState(block, properties, unlistedProperties); return new ExtendedStateImplementation(block, properties, unlistedProperties, null); } @@ -79,15 +80,15 @@ public class ExtendedBlockState extends BlockState { return this; } - if(Iterables.all(unlistedProperties.values(), Predicates.>equalTo(Optional.absent()))) - { // no dynamic properties present, looking up in the normal table - return super.withProperty(property, value); - } Map map = new HashMap(getProperties()); map.put(property, value); + if(Iterables.all(unlistedProperties.values(), Predicates.>equalTo(Optional.absent()))) + { // no dynamic properties present, looking up in the normal table + return (IExtendedBlockState) normalMap.get(map); + } ImmutableTable table = propertyValueTable; table = ((StateImplementation)table.get(property, value)).getPropertyValueTable(); - return new ExtendedStateImplementation(getBlock(), ImmutableMap.copyOf(map), unlistedProperties, table); + return new ExtendedStateImplementation(getBlock(), ImmutableMap.copyOf(map), unlistedProperties, table).setMap(this.normalMap); } } @@ -107,7 +108,7 @@ public class ExtendedBlockState extends BlockState { // no dynamic properties, lookup normal state return (IExtendedBlockState) normalMap.get(getProperties()); } - return new ExtendedStateImplementation(getBlock(), getProperties(), ImmutableMap.copyOf(newMap), propertyValueTable); + return new ExtendedStateImplementation(getBlock(), getProperties(), ImmutableMap.copyOf(newMap), propertyValueTable).setMap(this.normalMap); } public Collection> getUnlistedNames() @@ -135,5 +136,16 @@ public class ExtendedBlockState extends BlockState this.normalMap = map; super.buildPropertyValueTable(map); } + + private ExtendedStateImplementation setMap(Map, IBlockState> map) + { + this.normalMap = map; + return this; + } + + public IBlockState getClean() + { + return this.normalMap.get(getProperties()); + } } } diff --git a/src/main/java/net/minecraftforge/common/property/IExtendedBlockState.java b/src/main/java/net/minecraftforge/common/property/IExtendedBlockState.java index 218e42711..5c809add6 100644 --- a/src/main/java/net/minecraftforge/common/property/IExtendedBlockState.java +++ b/src/main/java/net/minecraftforge/common/property/IExtendedBlockState.java @@ -16,4 +16,6 @@ public interface IExtendedBlockState extends IBlockState IExtendedBlockState withProperty(IUnlistedProperty property, V value); ImmutableMap, Optional> getUnlistedProperties(); + + IBlockState getClean(); } diff --git a/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java b/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java index 2358b93f5..c15c8f372 100644 --- a/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java +++ b/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java @@ -1,38 +1,22 @@ package net.minecraftforge.debug; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyDirection; +import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.client.resources.IResourceManager; -import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.client.resources.model.ModelResourceLocation; -import net.minecraft.client.resources.model.ModelRotation; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; +import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import net.minecraftforge.client.model.Attributes; -import net.minecraftforge.client.model.ICustomModelLoader; -import net.minecraftforge.client.model.IFlexibleBakedModel; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.client.model.IModelState; import net.minecraftforge.client.model.ModelLoader; -import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.b3d.B3DLoader; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState; @@ -44,9 +28,6 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; -import com.google.common.base.Function; -import com.google.common.primitives.Ints; - @Mod(modid = ModelLoaderRegistryDebug.MODID, version = ModelLoaderRegistryDebug.VERSION) public class ModelLoaderRegistryDebug @@ -71,14 +52,16 @@ public class ModelLoaderRegistryDebug public static class CustomModelBlock extends Block { + public static final PropertyDirection FACING = PropertyDirection.create("facing"); public static final CustomModelBlock instance = new CustomModelBlock(); public static final String name = "CustomModelBlock"; private int counter = 1; - private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{ B3DLoader.B3DFrameProperty.instance }); + public ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{B3DLoader.B3DFrameProperty.instance}); private CustomModelBlock() { super(Material.iron); + this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); setCreativeTab(CreativeTabs.tabBlock); setUnlocalizedName(MODID + ":" + name); } @@ -92,11 +75,30 @@ public class ModelLoaderRegistryDebug @Override public boolean isVisuallyOpaque() { return false; } + @Override + public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) + { + return this.getDefaultState().withProperty(FACING, getFacingFromEntity(world, pos, placer)); + } + + @Override + public IBlockState getStateFromMeta(int meta) + { + return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta)); + } + + @Override + public int getMetaFromState(IBlockState state) + { + return ((EnumFacing) state.getValue(FACING)).getIndex(); + } + @Override public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { + //Only return an IExtendedBlockState from this method and createState(), otherwise block placement might break! B3DLoader.B3DState newState = new B3DLoader.B3DState(null, counter); - return ((IExtendedBlockState)this.state.getBaseState()).withProperty(B3DLoader.B3DFrameProperty.instance, newState); + return ((IExtendedBlockState) state).withProperty(B3DLoader.B3DFrameProperty.instance, newState); } @Override @@ -112,5 +114,31 @@ public class ModelLoaderRegistryDebug } return false; } + + @Override + public BlockState createBlockState() + { + return new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{B3DLoader.B3DFrameProperty.instance}); + } + + public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn) + { + if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F) + { + double d0 = entityIn.posY + (double)entityIn.getEyeHeight(); + + if (d0 - (double)clickedBlock.getY() > 2.0D) + { + return EnumFacing.UP; + } + + if ((double)clickedBlock.getY() - d0 > 0.0D) + { + return EnumFacing.DOWN; + } + } + + return entityIn.getHorizontalFacing().getOpposite(); + } } } diff --git a/src/test/resources/assets/forgedebugmodelloaderregistry/blockstates/CustomModelBlock.json b/src/test/resources/assets/forgedebugmodelloaderregistry/blockstates/CustomModelBlock.json index 4b73e67cc..6bd2f3faf 100644 --- a/src/test/resources/assets/forgedebugmodelloaderregistry/blockstates/CustomModelBlock.json +++ b/src/test/resources/assets/forgedebugmodelloaderregistry/blockstates/CustomModelBlock.json @@ -9,9 +9,9 @@ }, "variants": { "normal": [{ - "transform": { + /*"transform": { "rotation": {"y": 45} - } + }*/ }], "inventory": [{ /*"transform": { @@ -22,6 +22,14 @@ } }*/ "transform": "forge:default-block" - }] + }], + "facing": { + "down": {"model": "forgedebugmodelloaderregistry:chest.b3d", "x": 90}, + "up": {"model": "forgedebugmodelloaderregistry:chest.b3d", "x": 270}, + "north": {"model": "forgedebugmodelloaderregistry:chest.b3d"}, + "south": {"model": "forgedebugmodelloaderregistry:chest.b3d", "y": 180}, + "west": {"model": "forgedebugmodelloaderregistry:chest.b3d", "y": 270}, + "east": {"model": "forgedebugmodelloaderregistry:chest.b3d", "y": 90} + } } }