Updated mimics so that they store and display the meta for the block they want to mimic (using reflection).
This commit is contained in:
parent
117e692969
commit
ebd7b1f8da
|
@ -119,7 +119,7 @@ public class BlockMimic extends BlockStringContainer implements IVariantProvider
|
||||||
if (stack != null && stack.getItem() instanceof ItemBlock)
|
if (stack != null && stack.getItem() instanceof ItemBlock)
|
||||||
{
|
{
|
||||||
Block block = ((ItemBlock) stack.getItem()).getBlock();
|
Block block = ((ItemBlock) stack.getItem()).getBlock();
|
||||||
IBlockState mimicState = block.getStateFromMeta(stack.getItemDamage());
|
IBlockState mimicState = block.getStateFromMeta(mimic.metaOfReplacedBlock);
|
||||||
if (block != this)
|
if (block != this)
|
||||||
{
|
{
|
||||||
if (block.getRenderType(mimicState) == EnumBlockRenderType.ENTITYBLOCK_ANIMATED)
|
if (block.getRenderType(mimicState) == EnumBlockRenderType.ENTITYBLOCK_ANIMATED)
|
||||||
|
|
|
@ -70,7 +70,10 @@ public class ItemBlockMimic extends ItemBlock
|
||||||
if (tile instanceof TileMimic)
|
if (tile instanceof TileMimic)
|
||||||
{
|
{
|
||||||
TileMimic mimic = (TileMimic) tile;
|
TileMimic mimic = (TileMimic) tile;
|
||||||
|
mimic.metaOfReplacedBlock = block.getMetaFromState(iblockstate);
|
||||||
mimic.setInventorySlotContents(0, replacedStack);
|
mimic.setInventorySlotContents(0, replacedStack);
|
||||||
|
mimic.refreshTileEntity();
|
||||||
|
|
||||||
if (player.capabilities.isCreativeMode)
|
if (player.capabilities.isCreativeMode)
|
||||||
{
|
{
|
||||||
mimic.dropItemsOnBreak = false;
|
mimic.dropItemsOnBreak = false;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package WayofTime.bloodmagic.tile;
|
package WayofTime.bloodmagic.tile;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.ITileEntityProvider;
|
import net.minecraft.block.ITileEntityProvider;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -13,14 +15,18 @@ import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||||
import WayofTime.bloodmagic.registry.ModBlocks;
|
import WayofTime.bloodmagic.registry.ModBlocks;
|
||||||
import WayofTime.bloodmagic.util.Utils;
|
import WayofTime.bloodmagic.util.Utils;
|
||||||
|
|
||||||
public class TileMimic extends TileInventory
|
public class TileMimic extends TileInventory
|
||||||
{
|
{
|
||||||
|
private static Field _blockMetadata = ReflectionHelper.findField(TileEntity.class, "blockMetadata", "field_145847_g");
|
||||||
|
|
||||||
public boolean dropItemsOnBreak = true;
|
public boolean dropItemsOnBreak = true;
|
||||||
public NBTTagCompound tileTag = new NBTTagCompound();
|
public NBTTagCompound tileTag = new NBTTagCompound();
|
||||||
public TileEntity mimicedTile = null;
|
public TileEntity mimicedTile = null;
|
||||||
|
public int metaOfReplacedBlock = 0;
|
||||||
|
|
||||||
public TileMimic()
|
public TileMimic()
|
||||||
{
|
{
|
||||||
|
@ -47,7 +53,7 @@ public class TileMimic extends TileInventory
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Utils.insertItemToTile(this, player);
|
Utils.insertItemToTile(this, player);
|
||||||
mimicedTile = getTileFromStackWithTag(worldObj, pos, getStackInSlot(0), tileTag);
|
this.refreshTileEntity();
|
||||||
|
|
||||||
if (player.capabilities.isCreativeMode)
|
if (player.capabilities.isCreativeMode)
|
||||||
{
|
{
|
||||||
|
@ -63,6 +69,11 @@ public class TileMimic extends TileInventory
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshTileEntity()
|
||||||
|
{
|
||||||
|
mimicedTile = getTileFromStackWithTag(worldObj, pos, getStackInSlot(0), tileTag, metaOfReplacedBlock);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound tag)
|
public void readFromNBT(NBTTagCompound tag)
|
||||||
{
|
{
|
||||||
|
@ -70,7 +81,8 @@ public class TileMimic extends TileInventory
|
||||||
|
|
||||||
dropItemsOnBreak = tag.getBoolean("dropItemsOnBreak");
|
dropItemsOnBreak = tag.getBoolean("dropItemsOnBreak");
|
||||||
tileTag = tag.getCompoundTag("tileTag");
|
tileTag = tag.getCompoundTag("tileTag");
|
||||||
mimicedTile = getTileFromStackWithTag(worldObj, pos, getStackInSlot(0), tileTag);
|
metaOfReplacedBlock = tag.getInteger("metaOfReplacedBlock");
|
||||||
|
mimicedTile = getTileFromStackWithTag(worldObj, pos, getStackInSlot(0), tileTag, metaOfReplacedBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -80,6 +92,7 @@ public class TileMimic extends TileInventory
|
||||||
|
|
||||||
tag.setBoolean("dropItemsOnBreak", dropItemsOnBreak);
|
tag.setBoolean("dropItemsOnBreak", dropItemsOnBreak);
|
||||||
tag.setTag("tileTag", tileTag);
|
tag.setTag("tileTag", tileTag);
|
||||||
|
tag.setInteger("metaOfReplacedBlock", metaOfReplacedBlock);
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +129,7 @@ public class TileMimic extends TileInventory
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TileEntity getTileFromStackWithTag(World world, BlockPos pos, ItemStack stack, NBTTagCompound tag)
|
public static TileEntity getTileFromStackWithTag(World world, BlockPos pos, ItemStack stack, NBTTagCompound tag, int replacementMeta)
|
||||||
{
|
{
|
||||||
if (stack != null && stack.getItem() instanceof ItemBlock)
|
if (stack != null && stack.getItem() instanceof ItemBlock)
|
||||||
{
|
{
|
||||||
|
@ -136,6 +149,17 @@ public class TileMimic extends TileInventory
|
||||||
|
|
||||||
tile.setWorldObj(world);
|
tile.setWorldObj(world);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_blockMetadata.setInt(tile, replacementMeta);
|
||||||
|
} catch (IllegalArgumentException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue