Made the Block Placer function with the chest on its rear

This commit is contained in:
tgame14 2014-03-19 17:15:51 +02:00
parent 73f13f5712
commit 2917c31ce9

View file

@ -1,28 +1,27 @@
package resonantinduction.mechanical.process.edit; package resonantinduction.mechanical.process.edit;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.ResonantInduction;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.content.module.TileRender; import calclavia.lib.content.module.TileRender;
import calclavia.lib.content.module.prefab.TileInventory; import calclavia.lib.content.module.prefab.TileInventory;
import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.PacketHandler; import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.tile.IRotatable; import calclavia.lib.prefab.tile.IRotatable;
import calclavia.lib.render.RenderItemOverlayUtility; import calclavia.lib.render.RenderItemOverlayUtility;
import calclavia.lib.utility.inventory.InventoryUtility;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.ResonantInduction;
import universalelectricity.api.vector.Vector3;
/** /**
* @since 18/03/14 * @since 18/03/14
@ -30,80 +29,95 @@ import calclavia.lib.render.RenderItemOverlayUtility;
*/ */
public class TilePlacer extends TileInventory implements IRotatable, IPacketReceiver public class TilePlacer extends TileInventory implements IRotatable, IPacketReceiver
{ {
public TilePlacer() public TilePlacer ()
{ {
super(Material.iron); super(Material.iron);
normalRender = false; normalRender = false;
} }
@Override @Override
public void onAdded() public void onAdded ()
{ {
work(); if (!getWorldObj().isRemote)
} work();
}
@Override @Override
public void onNeighborChanged() public void onNeighborChanged ()
{ {
work(); if (!getWorldObj().isRemote)
} work();
}
public void work() public void work ()
{ {
if (isIndirectlyPowered()) if (isIndirectlyPowered())
{ {
ForgeDirection dir = getDirection(); ForgeDirection dir = getDirection();
Vector3 check = position().translate(dir); Vector3 check = position().translate(dir);
ItemStack placeStack = getStackInSlot(0); ItemStack placeStack = null;
if (getStackInSlot(0) == null)
{
ForgeDirection op = dir.getOpposite();
TileEntity tile = getWorldObj().getBlockTileEntity(x() + op.offsetX, y() + op.offsetY, z() + op.offsetZ);
if (world().isAirBlock(check.intX(), check.intY(), check.intZ()) && placeStack != null && placeStack.getItem() instanceof ItemBlock) if (tile instanceof IInventory)
{ {
ItemStack copyPlaceStack = placeStack.copy(); ItemStack candidate = InventoryUtility.takeTopItemFromInventory((IInventory) tile, dir.ordinal());
decrStackSize(0, 1); if (candidate != null)
((ItemBlock) copyPlaceStack.getItem()).placeBlockAt(placeStack, null, world(), check.intX(), check.intY(), check.intZ(), 0, 0, 0, 0, copyPlaceStack.getItemDamage()); this.incrStackSize(0, candidate);
} }
} }
} placeStack = getStackInSlot(0);
@Override if (world().isAirBlock(check.intX(), check.intY(), check.intZ()) && placeStack != null && placeStack.getItem() instanceof ItemBlock)
public Packet getDescriptionPacket() {
{ ItemStack copyPlaceStack = placeStack.copy();
NBTTagCompound nbt = new NBTTagCompound(); decrStackSize(0, 1);
writeToNBT(nbt); ((ItemBlock) copyPlaceStack.getItem()).placeBlockAt(placeStack, null, world(), check.intX(), check.intY(), check.intZ(), 0, 0, 0, 0, copyPlaceStack.getItemDamage());
return ResonantInduction.PACKET_TILE.getPacket(this, nbt); }
} }
}
@Override @Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra) public Packet getDescriptionPacket ()
{ {
try NBTTagCompound nbt = new NBTTagCompound();
{ writeToNBT(nbt);
readFromNBT(PacketHandler.readNBTTagCompound(data)); return ResonantInduction.PACKET_TILE.getPacket(this, nbt);
} }
catch (Exception e)
{
e.printStackTrace();
}
}
@Override @Override
@SideOnly(Side.CLIENT) public void onReceivePacket (ByteArrayDataInput data, EntityPlayer player, Object... extra)
protected TileRender newRenderer() {
{ try
return new TileRender() {
{ readFromNBT(PacketHandler.readNBTTagCompound(data));
@Override }
public boolean renderDynamic(Vector3 position, boolean isItem, float frame) catch (Exception e)
{ {
if (!isItem) e.printStackTrace();
{ }
GL11.glPushMatrix(); }
RenderItemOverlayUtility.renderItemOnSides(TilePlacer.this, getStackInSlot(0), position.x, position.y, position.z);
GL11.glPopMatrix();
}
return false; @Override
} @SideOnly(Side.CLIENT)
}; protected TileRender newRenderer ()
} {
return new TileRender()
{
@Override
public boolean renderDynamic (Vector3 position, boolean isItem, float frame)
{
if (!isItem)
{
GL11.glPushMatrix();
RenderItemOverlayUtility.renderItemOnSides(TilePlacer.this, getStackInSlot(0), position.x, position.y, position.z);
GL11.glPopMatrix();
}
return false;
}
};
}
} }