Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package simcraft.machines.workshop;
- import java.util.LinkedList;
- import java.util.List;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraftforge.common.ForgeDirection;
- import net.minecraftforge.common.ISidedInventory;
- import simcraft.core.RegBlocks;
- import simcraft.core.SimCraft;
- import simcraft.core.interf.IBenchHammer;
- import simcraft.core.network.NetworkClientTileEntityEventListener;
- import simcraft.core.network.NetworkTileEntityEventListener;
- import simcraft.core.recipes.RecipesAdvIronBnch;
- import simcraft.machines.TileEntityCommonWorkbench;
- public class TileEntityIronWorkBench extends TileEntityCommonWorkbench implements IInventory, IBenchHammer, NetworkTileEntityEventListener, NetworkClientTileEntityEventListener
- {
- public EntityPlayer player;
- /** Determines if the check for adjacent Iron Work Benches has taken place. */
- public boolean adjacentModelChecked = false;
- /** Contains the chest tile located adjacent to this one (if any) */
- public TileEntityIronWorkBench adjacentModelZNeg;
- /** Contains the chest tile located adjacent to this one (if any) */
- public TileEntityIronWorkBench adjacentModelXPos;
- /** Contains the chest tile located adjacent to this one (if any) */
- public TileEntityIronWorkBench adjacentModelXNeg;
- /** Contains the chest tile located adjacent to this one (if any) */
- public TileEntityIronWorkBench adjacentModelZPosition;
- /** The number of players currently using this chest */
- public int numUsingPlayers;
- /** Server sync counter (once per 20 ticks) */
- private int ticksSinceSync;
- /**
- * Integers for Hammer
- */
- public int HammerSlot1Time = 0;
- public int currentItemHammerSlot1Time = 0;
- public boolean CrushHammer;
- public TileEntityIronWorkBench()
- {
- super(27);
- this.CrushHammer = false;
- }
- /**
- * Returns the number of slots in the inventory.
- */
- public int getSizeInventory()
- {
- return 27;
- }
- public String getInvName() {
- return "IronWorkBench";
- }
- /**
- * Reads a tile entity from NBT.
- */
- public void readFromNBT(NBTTagCompound var1)
- {
- super.readFromNBT(var1);
- this.HammerSlot1Time = var1.getShort("Slot1Time");
- }
- /**
- * Writes a tile entity to NBT.
- */
- public void writeToNBT(NBTTagCompound var1)
- {
- super.writeToNBT(var1);
- var1.setShort("Slot1Time", (short)this.HammerSlot1Time);
- }
- /**
- * Do not make give this method the name canInteractWith because it clashes with Container
- */
- public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
- {
- return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
- }
- public int getProgressSlot1(int var1)
- {
- return this.HammerSlot1Time * var1 / this.getHammerTime1();
- }
- public int getHammerTime1()
- {
- int var1 = 1;
- if (this.inventory[10] != null)
- {
- var1 = 200;
- }
- return var1;
- }
- private boolean canCrushSlot1()
- {
- if (this.inventory[10] == null)
- {
- return false;
- }
- else
- {
- ItemStack var1 = RecipesAdvIronBnch.Crushing().getCrushingResult(this.inventory[10]);
- return var1 == null ? false : (this.inventory[11] == null ? true : (!this.inventory[11].isItemEqual(var1) ? false : (this.inventory[11].stackSize < this.getInventoryStackLimit() && this.inventory[11].stackSize < this.inventory[11].getMaxStackSize() ? true : this.inventory[11].stackSize < var1.getMaxStackSize())));
- }
- }
- public void CrushSlot1()
- {
- if (this.canCrushSlot1())
- {
- ItemStack var1 = RecipesAdvIronBnch.Crushing().getCrushingResult(this.inventory[10]);
- if (this.inventory[11] == null)
- {
- this.inventory[11] = var1.copy();
- }
- else if (this.inventory[11].itemID == var1.itemID)
- {
- this.inventory[11].stackSize += var1.stackSize;
- }
- if (SimCraft.globalFunctions.isSimulating())
- {
- onNetworkEvent(1);
- }
- if (!this.worldObj.isRemote)
- {
- SimCraft.network.initiateTileEntityEvent(this, 1, true);
- }
- updateContainingBlockInfo();
- if (this.inventory[10].getItem().hasContainerItem())
- {
- this.inventory[10] = new ItemStack(this.inventory[10].getItem().getContainerItem());
- }
- else
- {
- --this.inventory[10].stackSize;
- }
- if (this.inventory[10].stackSize <= 0)
- {
- this.inventory[10] = null;
- }
- }
- }
- /**
- * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
- * like when you close a workbench GUI.
- */
- public ItemStack getStackInSlotOnClosing(int var1)
- {
- if (this.inventory[var1] == null)
- {
- return null;
- }
- else
- {
- ItemStack var2 = this.inventory[var1];
- this.inventory[var1] = null;
- return var2;
- }
- }
- /**
- * Causes the TileEntity to reset all it's cached values for it's container block, blockID, metaData and in the case
- * of chests, the adjcacent chest check
- */
- public void updateContainingBlockInfo()
- {
- super.updateContainingBlockInfo();
- this.adjacentModelChecked = false;
- }
- /**
- * Performs the check for adjacent chests to determine if this chest is double or not.
- */
- public void checkForAdjacentModel()
- {
- if (!this.adjacentModelChecked)
- {
- this.adjacentModelChecked = true;
- this.adjacentModelZNeg = null;
- this.adjacentModelXPos = null;
- this.adjacentModelXNeg = null;
- this.adjacentModelZPosition = null;
- if (this.worldObj.getBlockId(this.xCoord - 1, this.yCoord, this.zCoord) == RegBlocks.BlockIronWorkBench.blockID)
- {
- this.adjacentModelXNeg = (TileEntityIronWorkBench)this.worldObj.getBlockTileEntity(this.xCoord - 1, this.yCoord, this.zCoord);
- }
- if (this.worldObj.getBlockId(this.xCoord + 1, this.yCoord, this.zCoord) == RegBlocks.BlockIronWorkBench.blockID)
- {
- this.adjacentModelXPos = (TileEntityIronWorkBench)this.worldObj.getBlockTileEntity(this.xCoord + 1, this.yCoord, this.zCoord);
- }
- if (this.worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord - 1) == RegBlocks.BlockIronWorkBench.blockID)
- {
- this.adjacentModelZNeg = (TileEntityIronWorkBench)this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord - 1);
- }
- if (this.worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord + 1) == RegBlocks.BlockIronWorkBench.blockID)
- {
- this.adjacentModelZPosition = (TileEntityIronWorkBench)this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord + 1);
- }
- if (this.adjacentModelZNeg != null)
- {
- this.adjacentModelZNeg.updateContainingBlockInfo();
- }
- if (this.adjacentModelZPosition != null)
- {
- this.adjacentModelZPosition.updateContainingBlockInfo();
- }
- if (this.adjacentModelXPos != null)
- {
- this.adjacentModelXPos.updateContainingBlockInfo();
- }
- if (this.adjacentModelXNeg != null)
- {
- this.adjacentModelXNeg.updateContainingBlockInfo();
- }
- }
- }
- /**
- * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count
- * ticks and creates a new spawn inside its implementation.
- */
- public void updateEntity()
- {
- super.updateEntity();
- this.checkForAdjacentModel();
- boolean var1 = this.HammerSlot1Time > 0;
- boolean var2 = false;
- if (this.inventory[10] == null && !this.adjacentModelChecked)
- {
- this.HammerSlot1Time = 0;
- }
- if (++this.ticksSinceSync % 20 * 4 == 0)
- {
- this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, RegBlocks.BlockIronWorkBench.blockID, 1, this.numUsingPlayers);
- }
- if (!this.worldObj.isRemote)
- {
- if (this.canCrushSlot1())
- {
- if (this.HammerSlot1Time > this.getHammerTime1())
- {
- var2 = true;
- if (SimCraft.globalFunctions.isSimulating())
- {
- onNetworkEvent(10);
- }
- if (!this.worldObj.isRemote)
- {
- SimCraft.network.initiateTileEntityEvent(this, 10, true);
- }
- }
- }
- }
- if (this.HammerSlot1Time > 210)
- {
- if (SimCraft.globalFunctions.isSimulating())
- {
- onNetworkEvent(11);
- }
- if (!this.worldObj.isRemote)
- {
- SimCraft.network.initiateTileEntityEvent(this, 11, true);
- }
- }
- if (var2)
- {
- this.onInventoryChanged();
- }
- }
- /**
- * Called when a client event is received with the event number and argument, see World.sendClientEvent
- */
- public boolean receiveClientEvent(int par1, int par2)
- {
- if (par1 == 1)
- {
- this.numUsingPlayers = par2;
- return true;
- }
- else
- {
- return super.receiveClientEvent(par1, par2);
- }
- }
- public void openChest()
- {
- if (this.numUsingPlayers < 0)
- {
- this.numUsingPlayers = 0;
- }
- ++this.numUsingPlayers;
- this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, RegBlocks.BlockIronWorkBench.blockID, 1, this.numUsingPlayers);
- this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID);
- this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord - 1, this.zCoord, this.getBlockType().blockID);
- }
- public void closeChest()
- {
- if (this.getBlockType() != null && this.getBlockType() instanceof blockWorkBench)
- {
- --this.numUsingPlayers;
- this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, RegBlocks.BlockIronWorkBench.blockID, 1, this.numUsingPlayers);
- this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID);
- this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord - 1, this.zCoord, this.getBlockType().blockID);
- }
- }
- /**
- * invalidates a tile entity
- */
- public void invalidate()
- {
- this.updateContainingBlockInfo();
- this.checkForAdjacentModel();
- if (this.audioSource != null)
- {
- SimCraft.soundsManager.removeSources(this);
- this.audioSource = null;
- }
- super.invalidate();
- }
- public int getStartInventorySide(int side) {
- if (side == 0) return 11;
- if (side == 1) return 12;
- if (side == 2) return 13;
- if (side == 3) return 14;
- if (side == 4) return 15;
- return 10;
- }
- public int getSizeInventorySide(int side) {
- return 10;
- }
- /**
- * Boolean Flag when wrench is used on TileEntity
- */
- public boolean CrushHammer() {
- return true;
- }
- public void CrushHammerInt()
- {
- SimCraft.network.initiateClientTileEntityEvent(this, 12);
- }
- public void Working()
- {
- this.HammerSlot1Time = this.HammerSlot1Time + 10;
- if (SimCraft.globalFunctions.isSimulating())
- {
- onNetworkEvent(0);
- }
- if (!this.worldObj.isRemote)
- {
- SimCraft.network.initiateTileEntityEvent(this, 0, true);
- }
- }
- /**
- * Creates the SoundSource
- */
- public void onNetworkEvent(int var1)
- {
- if (this.audioSource == null && this.getStartSoundFile() != null)
- {
- this.audioSource = SimCraft.soundsManager.createSource(this, this.getStartSoundFile());
- }
- switch (var1)
- {
- case 0:
- if (this.audioSource != null)
- {
- this.audioSource.stop();
- if (this.getStartSoundFile() != null)
- {
- SimCraft.soundsManager.playOnce(this, this.getStartSoundFile());
- }
- }
- break;
- case 1:
- if (this.audioSource != null)
- {
- this.audioSource.stop();
- if (this.getBreakSoundFile() != null)
- {
- SimCraft.soundsManager.playOnce(this, this.getBreakSoundFile());
- }
- }
- break;
- case 10:
- {
- this.HammerSlot1Time = 0;
- this.CrushSlot1();
- break;
- }
- case 11:
- {
- this.HammerSlot1Time = 0;
- break;
- }
- case 12:
- {
- this.Working();
- break;
- }
- }
- }
- public boolean canUpdate()
- {
- return SimCraft.globalFunctions.isSimulating();
- }
- public void onNetworkEvent(EntityPlayer var1, int var2)
- {
- switch (var2)
- {
- case 12:
- {
- this.Working();
- break;
- }
- }
- }
- public String getStartSoundFile()
- {
- return "machines/hammeriron.ogg";
- }
- public String getBreakSoundFile()
- {
- return "machines/rocks.ogg";
- }
- public boolean isStackValidForSlot(int i, ItemStack itemstack) {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement