108 lines
2.6 KiB
Java
108 lines
2.6 KiB
Java
package tinker.tconstruct.logic;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
import net.minecraft.inventory.Container;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.network.INetworkManager;
|
|
import net.minecraft.network.packet.Packet;
|
|
import net.minecraft.network.packet.Packet132TileEntityData;
|
|
import net.minecraft.world.World;
|
|
import tinker.common.InventoryLogic;
|
|
import tinker.tconstruct.client.gui.ToolStationContainer;
|
|
import tinker.tconstruct.crafting.ToolBuilder;
|
|
|
|
/* Simple class for storing items in the block
|
|
*/
|
|
|
|
public class ToolStationLogic extends InventoryLogic
|
|
{
|
|
ItemStack previousTool;
|
|
String toolName;
|
|
|
|
public ToolStationLogic()
|
|
{
|
|
super(5);
|
|
toolName = "";
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getStackInSlotOnClosing (int var1)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public String getInvName ()
|
|
{
|
|
return "toolstation.crafting";
|
|
}
|
|
|
|
@Override
|
|
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
|
{
|
|
return new ToolStationContainer(inventoryplayer, this);
|
|
}
|
|
|
|
public void onInventoryChanged ()
|
|
{
|
|
buildTool(toolName);
|
|
if (this.worldObj != null)
|
|
{
|
|
this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
|
|
this.worldObj.updateTileEntityChunkAndDoNothing(this.xCoord, this.yCoord, this.zCoord, this);
|
|
}
|
|
}
|
|
|
|
public void buildTool (String name)
|
|
{
|
|
toolName = name;
|
|
ItemStack tool = ToolBuilder.instance.buildTool(inventory[1], inventory[2], inventory[3], name);
|
|
if (inventory[0] == null)
|
|
inventory[0] = tool;
|
|
else
|
|
{
|
|
NBTTagCompound tags = inventory[0].getTagCompound();
|
|
if (!tags.getCompoundTag("InfiTool").hasKey("Built"))
|
|
{
|
|
inventory[0] = tool;
|
|
}
|
|
}
|
|
/*if (container != null)
|
|
container.detectAndSendChanges();*/
|
|
}
|
|
|
|
public void setToolname (String name)
|
|
{
|
|
toolName = name;
|
|
buildTool (name);
|
|
}
|
|
|
|
void consumeItems ()
|
|
{
|
|
for (int i = 1; i <= 3; i++)
|
|
super.decrStackSize(i, 1);
|
|
|
|
/*if (container != null)
|
|
container.detectAndSendChanges();*/
|
|
}
|
|
|
|
public void dumpExtraItems (int usedSlots, EntityPlayer player)
|
|
{
|
|
if (!worldObj.isRemote)
|
|
{
|
|
for (int iter = 0; iter < inventory.length; iter++)
|
|
{
|
|
if (iter > usedSlots && inventory[iter] != null)
|
|
{
|
|
EntityItem entityitem = new EntityItem(worldObj, player.posX, player.posY - 1.0D, player.posZ, inventory[iter]);
|
|
worldObj.spawnEntityInWorld(entityitem);
|
|
entityitem.onCollideWithPlayer(player);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|