Made the mimics actually render chests and other TESRs properly - need to add non-opaque mimics for wider selection and for chests to not look like crud.

This commit is contained in:
WayofTime 2016-08-22 19:55:15 -04:00
parent 80bf140ee5
commit 117e692969
5 changed files with 191 additions and 23 deletions

View file

@ -14,6 +14,7 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
@ -30,8 +31,8 @@ import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.block.base.BlockStringContainer;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.tile.TileMimic;
import WayofTime.bloodmagic.util.Utils;
public class BlockMimic extends BlockStringContainer implements IVariantProvider
{
@ -64,13 +65,27 @@ public class BlockMimic extends BlockStringContainer implements IVariantProvider
if (tileMimic != null && tileMimic.getStackInSlot(0) != null)
{
Block mimicBlock = Block.getBlockFromItem(tileMimic.getStackInSlot(0).getItem());
if (mimicBlock == null)
{
return FULL_BLOCK_AABB;
}
IBlockState mimicState = mimicBlock.getStateFromMeta(tileMimic.getStackInSlot(0).getItemDamage());
return mimicState.getSelectedBoundingBox(world, pos);
if (mimicBlock != this)
{
return mimicState.getSelectedBoundingBox(world, pos);
}
}
return FULL_BLOCK_AABB;
}
@Override
public int getLightOpacity(IBlockState state)
{
//Overriden for now so that in the future I don't have to.
return this.lightOpacity;
}
@Override
public int getMetaFromState(IBlockState state)
{
@ -87,27 +102,10 @@ public class BlockMimic extends BlockStringContainer implements IVariantProvider
{
TileMimic mimic = (TileMimic) world.getTileEntity(pos);
if (mimic == null || player.isSneaking())
if (mimic == null)
return false;
if (player.getHeldItem(hand) != null && player.getHeldItem(hand).getItem() == new ItemStack(this).getItem())
return false;
if (mimic.getStackInSlot(0) != null && player.getHeldItem(hand) != null)
return false;
if (!mimic.dropItemsOnBreak && !player.capabilities.isCreativeMode)
return super.onBlockActivated(world, pos, state, player, hand, heldItem, side, hitX, hitY, hitZ);
Utils.insertItemToTile(mimic, player);
if (player.capabilities.isCreativeMode)
{
mimic.dropItemsOnBreak = mimic.getStackInSlot(0) == null;
}
world.notifyBlockUpdate(pos, state, state, 3);
return true;
return mimic.onBlockActivated(world, pos, state, player, hand, heldItem, side);
}
@Override
@ -122,7 +120,15 @@ public class BlockMimic extends BlockStringContainer implements IVariantProvider
{
Block block = ((ItemBlock) stack.getItem()).getBlock();
IBlockState mimicState = block.getStateFromMeta(stack.getItemDamage());
return block.getActualState(mimicState, world, pos);
if (block != this)
{
if (block.getRenderType(mimicState) == EnumBlockRenderType.ENTITYBLOCK_ANIMATED)
{
return ModBlocks.bloodLight.getDefaultState(); //Small and invisible-ish, basically this is returned in order to not render over the animated block (TESR)
}
return block.getActualState(mimicState, world, pos);
}
}
}
return state;

View file

@ -0,0 +1,24 @@
package WayofTime.bloodmagic.client.render.block;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.tile.TileMimic;
@SideOnly(Side.CLIENT)
public class RenderMimic extends TileEntitySpecialRenderer<TileMimic>
{
public void renderTileEntityAt(TileMimic mimic, double x, double y, double z, float partialTicks, int destroyStage)
{
if (mimic.getStackInSlot(0) != null)
{
TileEntity testTile = mimic.mimicedTile;
if (mimic != null)
{
TileEntityRendererDispatcher.instance.renderTileEntityAt(testTile, x, y, z, partialTicks, destroyStage);
}
}
}
}

View file

@ -6,7 +6,9 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
@ -36,7 +38,7 @@ public class ItemBlockMimic extends ItemBlock
IBlockState iblockstate = world.getBlockState(pos);
Block block = iblockstate.getBlock();
if (player.isSneaking())
if (!player.isSneaking())
{
return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);
}
@ -54,6 +56,10 @@ public class ItemBlockMimic extends ItemBlock
ItemStack replacedStack = block.getItem(world, pos, iblockstate);
// ItemStack replacedStack = new ItemStack(block, 1, block.getMetaFromState(iblockstate));
NBTTagCompound tileTag = getTagFromTileEntity(tileReplaced);
if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1))
{
SoundType soundtype = this.block.getSoundType();
@ -80,9 +86,26 @@ public class ItemBlockMimic extends ItemBlock
public boolean canReplaceTile(int meta, TileEntity tile)
{
if (tile instanceof TileEntityChest)
{
return true;
}
return tile == null;
}
public NBTTagCompound getTagFromTileEntity(TileEntity tile)
{
NBTTagCompound tag = new NBTTagCompound();
if (tile != null)
{
return tile.writeToNBT(tag);
}
return tag;
}
@Override
public int getMetadata(int meta)
{

View file

@ -33,6 +33,7 @@ import WayofTime.bloodmagic.client.render.RenderAlchemyArray;
import WayofTime.bloodmagic.client.render.RenderAltar;
import WayofTime.bloodmagic.client.render.RenderDemonCrucible;
import WayofTime.bloodmagic.client.render.RenderItemRoutingNode;
import WayofTime.bloodmagic.client.render.block.RenderMimic;
import WayofTime.bloodmagic.client.render.entity.BloodLightRenderFactory;
import WayofTime.bloodmagic.client.render.entity.MeteorRenderFactory;
import WayofTime.bloodmagic.client.render.entity.MimicRenderFactory;
@ -50,6 +51,7 @@ import WayofTime.bloodmagic.registry.ModItems;
import WayofTime.bloodmagic.tile.TileAlchemyArray;
import WayofTime.bloodmagic.tile.TileAltar;
import WayofTime.bloodmagic.tile.TileDemonCrucible;
import WayofTime.bloodmagic.tile.TileMimic;
import WayofTime.bloodmagic.tile.routing.TileRoutingNode;
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
import WayofTime.bloodmagic.util.helper.InventoryRenderHelperV2;
@ -90,6 +92,7 @@ public class ClientProxy extends CommonProxy
ClientRegistry.bindTileEntitySpecialRenderer(TileAltar.class, new RenderAltar());
ClientRegistry.bindTileEntitySpecialRenderer(TileRoutingNode.class, new RenderItemRoutingNode());
ClientRegistry.bindTileEntitySpecialRenderer(TileDemonCrucible.class, new RenderDemonCrucible());
ClientRegistry.bindTileEntitySpecialRenderer(TileMimic.class, new RenderMimic());
}
@Override

View file

@ -1,24 +1,76 @@
package WayofTime.bloodmagic.tile;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.util.Utils;
public class TileMimic extends TileInventory
{
public boolean dropItemsOnBreak = true;
public NBTTagCompound tileTag = new NBTTagCompound();
public TileEntity mimicedTile = null;
public TileMimic()
{
super(1, "mimic");
}
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side)
{
if (performSpecialAbility())
{
return true;
}
if (player.isSneaking())
return false;
if (player.getHeldItem(hand) != null && player.getHeldItem(hand).getItem() == new ItemStack(ModBlocks.mimic).getItem())
return false;
if (getStackInSlot(0) != null && player.getHeldItem(hand) != null)
return false;
if (!dropItemsOnBreak && !player.capabilities.isCreativeMode)
return false;
Utils.insertItemToTile(this, player);
mimicedTile = getTileFromStackWithTag(worldObj, pos, getStackInSlot(0), tileTag);
if (player.capabilities.isCreativeMode)
{
dropItemsOnBreak = getStackInSlot(0) == null;
}
world.notifyBlockUpdate(pos, state, state, 3);
return true;
}
public boolean performSpecialAbility()
{
return false;
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
dropItemsOnBreak = tag.getBoolean("dropItemsOnBreak");
tileTag = tag.getCompoundTag("tileTag");
mimicedTile = getTileFromStackWithTag(worldObj, pos, getStackInSlot(0), tileTag);
}
@Override
@ -27,10 +79,70 @@ public class TileMimic extends TileInventory
super.writeToNBT(tag);
tag.setBoolean("dropItemsOnBreak", dropItemsOnBreak);
tag.setTag("tileTag", tileTag);
return tag;
}
public static void replaceMimicWithBlockActual(TileMimic mimic)
{
World world = mimic.getWorld();
BlockPos pos = mimic.getPos();
replaceMimicWithBlockActual(world, pos, mimic.getStackInSlot(0), mimic.tileTag);
}
public static boolean replaceMimicWithBlockActual(World world, BlockPos pos, ItemStack stack, NBTTagCompound tileTag)
{
if (stack != null && stack.getItem() instanceof ItemBlock)
{
Block block = ((ItemBlock) stack.getItem()).getBlock();
IBlockState state = block.onBlockPlaced(world, pos, EnumFacing.UP, 0, 0, 0, stack.getItemDamage(), null);
if (world.setBlockState(pos, state, 3))
{
TileEntity tile = world.getTileEntity(pos);
if (tile != null)
{
tileTag.setInteger("x", pos.getX());
tileTag.setInteger("y", pos.getY());
tileTag.setInteger("z", pos.getZ());
tile.readFromNBT(tileTag);
return true;
}
}
}
return false;
}
public static TileEntity getTileFromStackWithTag(World world, BlockPos pos, ItemStack stack, NBTTagCompound tag)
{
if (stack != null && stack.getItem() instanceof ItemBlock)
{
Block block = ((ItemBlock) stack.getItem()).getBlock();
if (block instanceof ITileEntityProvider)
{
TileEntity tile = ((ITileEntityProvider) block).createNewTileEntity(world, stack.getItemDamage());
if (tag != null)
{
NBTTagCompound copyTag = tag.copy();
copyTag.setInteger("x", pos.getX());
copyTag.setInteger("y", pos.getY());
copyTag.setInteger("z", pos.getZ());
tile.readFromNBT(copyTag);
}
tile.setWorldObj(world);
return tile;
}
}
return null;
}
@Override
public void dropItems()
{