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;
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.prefab.TileInventory;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.tile.IRotatable;
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
@ -30,80 +29,95 @@ import calclavia.lib.render.RenderItemOverlayUtility;
*/
public class TilePlacer extends TileInventory implements IRotatable, IPacketReceiver
{
public TilePlacer()
{
super(Material.iron);
normalRender = false;
}
public TilePlacer ()
{
super(Material.iron);
normalRender = false;
}
@Override
public void onAdded()
{
work();
}
@Override
public void onAdded ()
{
if (!getWorldObj().isRemote)
work();
}
@Override
public void onNeighborChanged()
{
work();
}
@Override
public void onNeighborChanged ()
{
if (!getWorldObj().isRemote)
work();
}
public void work()
{
if (isIndirectlyPowered())
{
ForgeDirection dir = getDirection();
Vector3 check = position().translate(dir);
ItemStack placeStack = getStackInSlot(0);
public void work ()
{
if (isIndirectlyPowered())
{
ForgeDirection dir = getDirection();
Vector3 check = position().translate(dir);
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)
{
ItemStack copyPlaceStack = placeStack.copy();
decrStackSize(0, 1);
((ItemBlock) copyPlaceStack.getItem()).placeBlockAt(placeStack, null, world(), check.intX(), check.intY(), check.intZ(), 0, 0, 0, 0, copyPlaceStack.getItemDamage());
}
}
}
if (tile instanceof IInventory)
{
ItemStack candidate = InventoryUtility.takeTopItemFromInventory((IInventory) tile, dir.ordinal());
if (candidate != null)
this.incrStackSize(0, candidate);
}
}
placeStack = getStackInSlot(0);
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
return ResonantInduction.PACKET_TILE.getPacket(this, nbt);
}
if (world().isAirBlock(check.intX(), check.intY(), check.intZ()) && placeStack != null && placeStack.getItem() instanceof ItemBlock)
{
ItemStack copyPlaceStack = placeStack.copy();
decrStackSize(0, 1);
((ItemBlock) copyPlaceStack.getItem()).placeBlockAt(placeStack, null, world(), check.intX(), check.intY(), check.intZ(), 0, 0, 0, 0, copyPlaceStack.getItemDamage());
}
}
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
readFromNBT(PacketHandler.readNBTTagCompound(data));
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public Packet getDescriptionPacket ()
{
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
return ResonantInduction.PACKET_TILE.getPacket(this, nbt);
}
@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();
}
@Override
public void onReceivePacket (ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
readFromNBT(PacketHandler.readNBTTagCompound(data));
}
catch (Exception e)
{
e.printStackTrace();
}
}
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;
}
};
}
}