Merge pull request #2048 from shadekiller666/UnlistedPropertyValue
Fix for ExtendedBlockStates containing at least one IProperty and one IUnlistedProperty preventing block placement.
This commit is contained in:
commit
5623634f56
7 changed files with 122 additions and 35 deletions
|
@ -26,7 +26,21 @@
|
||||||
linkedhashmap.put(map, stateimplementation);
|
linkedhashmap.put(map, stateimplementation);
|
||||||
arraylist.add(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_);
|
this(p_i45661_1_, p_i45661_2_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<IProperty, Comparable, IBlockState> getPropertyValueTable()
|
||||||
|
+ {
|
||||||
|
+ return null;
|
||||||
|
+ }
|
||||||
|
}
|
|
@ -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();
|
|
@ -47,6 +47,7 @@ public class ExtendedBlockState extends BlockState
|
||||||
@Override
|
@Override
|
||||||
protected StateImplementation createState(Block block, ImmutableMap properties, ImmutableMap unlistedProperties)
|
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);
|
return new ExtendedStateImplementation(block, properties, unlistedProperties, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,15 +80,15 @@ public class ExtendedBlockState extends BlockState
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if(Iterables.all(unlistedProperties.values(), Predicates.<Optional<?>>equalTo(Optional.absent())))
|
|
||||||
{ // no dynamic properties present, looking up in the normal table
|
|
||||||
return super.withProperty(property, value);
|
|
||||||
}
|
|
||||||
Map<IProperty, Comparable> map = new HashMap<IProperty, Comparable>(getProperties());
|
Map<IProperty, Comparable> map = new HashMap<IProperty, Comparable>(getProperties());
|
||||||
map.put(property, value);
|
map.put(property, value);
|
||||||
|
if(Iterables.all(unlistedProperties.values(), Predicates.<Optional<?>>equalTo(Optional.absent())))
|
||||||
|
{ // no dynamic properties present, looking up in the normal table
|
||||||
|
return (IExtendedBlockState) normalMap.get(map);
|
||||||
|
}
|
||||||
ImmutableTable<IProperty, Comparable, IBlockState> table = propertyValueTable;
|
ImmutableTable<IProperty, Comparable, IBlockState> table = propertyValueTable;
|
||||||
table = ((StateImplementation)table.get(property, value)).getPropertyValueTable();
|
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
|
{ // no dynamic properties, lookup normal state
|
||||||
return (IExtendedBlockState) normalMap.get(getProperties());
|
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<IUnlistedProperty<?>> getUnlistedNames()
|
public Collection<IUnlistedProperty<?>> getUnlistedNames()
|
||||||
|
@ -135,5 +136,16 @@ public class ExtendedBlockState extends BlockState
|
||||||
this.normalMap = map;
|
this.normalMap = map;
|
||||||
super.buildPropertyValueTable(map);
|
super.buildPropertyValueTable(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ExtendedStateImplementation setMap(Map<Map<IProperty, Comparable>, IBlockState> map)
|
||||||
|
{
|
||||||
|
this.normalMap = map;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IBlockState getClean()
|
||||||
|
{
|
||||||
|
return this.normalMap.get(getProperties());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,6 @@ public interface IExtendedBlockState extends IBlockState
|
||||||
<V>IExtendedBlockState withProperty(IUnlistedProperty<V> property, V value);
|
<V>IExtendedBlockState withProperty(IUnlistedProperty<V> property, V value);
|
||||||
|
|
||||||
ImmutableMap<IUnlistedProperty<?>, Optional<?>> getUnlistedProperties();
|
ImmutableMap<IUnlistedProperty<?>, Optional<?>> getUnlistedProperties();
|
||||||
|
|
||||||
|
IBlockState getClean();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +1,22 @@
|
||||||
package net.minecraftforge.debug;
|
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.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.properties.IProperty;
|
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.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.ModelResourceLocation;
|
||||||
import net.minecraft.client.resources.model.ModelRotation;
|
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
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.ModelLoader;
|
||||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
|
||||||
import net.minecraftforge.client.model.b3d.B3DLoader;
|
import net.minecraftforge.client.model.b3d.B3DLoader;
|
||||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
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.common.registry.GameRegistry;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
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)
|
@Mod(modid = ModelLoaderRegistryDebug.MODID, version = ModelLoaderRegistryDebug.VERSION)
|
||||||
|
|
||||||
public class ModelLoaderRegistryDebug
|
public class ModelLoaderRegistryDebug
|
||||||
|
@ -71,14 +52,16 @@ public class ModelLoaderRegistryDebug
|
||||||
|
|
||||||
public static class CustomModelBlock extends Block
|
public static class CustomModelBlock extends Block
|
||||||
{
|
{
|
||||||
|
public static final PropertyDirection FACING = PropertyDirection.create("facing");
|
||||||
public static final CustomModelBlock instance = new CustomModelBlock();
|
public static final CustomModelBlock instance = new CustomModelBlock();
|
||||||
public static final String name = "CustomModelBlock";
|
public static final String name = "CustomModelBlock";
|
||||||
private int counter = 1;
|
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()
|
private CustomModelBlock()
|
||||||
{
|
{
|
||||||
super(Material.iron);
|
super(Material.iron);
|
||||||
|
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
||||||
setCreativeTab(CreativeTabs.tabBlock);
|
setCreativeTab(CreativeTabs.tabBlock);
|
||||||
setUnlocalizedName(MODID + ":" + name);
|
setUnlocalizedName(MODID + ":" + name);
|
||||||
}
|
}
|
||||||
|
@ -92,11 +75,30 @@ public class ModelLoaderRegistryDebug
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisuallyOpaque() { return false; }
|
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
|
@Override
|
||||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
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);
|
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
|
@Override
|
||||||
|
@ -112,5 +114,31 @@ public class ModelLoaderRegistryDebug
|
||||||
}
|
}
|
||||||
return false;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
},
|
},
|
||||||
"variants": {
|
"variants": {
|
||||||
"normal": [{
|
"normal": [{
|
||||||
"transform": {
|
/*"transform": {
|
||||||
"rotation": {"y": 45}
|
"rotation": {"y": 45}
|
||||||
}
|
}*/
|
||||||
}],
|
}],
|
||||||
"inventory": [{
|
"inventory": [{
|
||||||
/*"transform": {
|
/*"transform": {
|
||||||
|
@ -22,6 +22,14 @@
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
"transform": "forge:default-block"
|
"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}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue