Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class TileEntityForge extends TileEntityLockable implements ITickable, ISidedInventory{
- public enum slotEnum {
- INPUT_SLOT, OUTPUT_SLOT , FUEL_SLOT , MOLD_SLOT }
- private static final int[] slotsTop = new int[] {
- slotEnum.INPUT_SLOT.ordinal(), slotEnum.FUEL_SLOT.ordinal() };
- private static final int[] slotsBottom = new int[] {
- slotEnum.OUTPUT_SLOT.ordinal()};
- private static final int[] slotsSides = new int[] {
- slotEnum.MOLD_SLOT.ordinal()};
- private ItemStack[] ForgeItemStacks = new ItemStack[7];
- /** The number of ticks that the Forge will keep burning */ private int ForgeBurnTime;
- /** The number of ticks that a fresh copy of the currently-burning item would keep the Forge burning for */ private int currentItemBurnTime;
- private int cookTime;
- private int totalCookTime;
- private String ForgeCustomName;
- /** * Returns the number of slots in the inventory. */ public int getSizeInventory() {
- return this.ForgeItemStacks.length;
- }
- /** * Returns the stack in the given slot. * * @param index The slot to retrieve from. */ public ItemStack getStackInSlot(int index) {
- return this.ForgeItemStacks[index];
- }
- /** * Removes up to a specified number of items from an inventory slot and returns them in a new stack. * * @param index The slot to remove from. * @param count The maximum amount of items to remove. */ public ItemStack decrStackSize(int index, int count) {
- if (this.ForgeItemStacks[index] != null) {
- if (this.ForgeItemStacks[index].stackSize <= count) {
- ItemStack itemstack1 = this.ForgeItemStacks[index];
- this.ForgeItemStacks[index] = null;
- return itemstack1;
- }
- else {
- ItemStack itemstack = this.ForgeItemStacks[index].splitStack(count);
- if (this.ForgeItemStacks[index].stackSize == 0) {
- this.ForgeItemStacks[index] = null;
- }
- return itemstack;
- }
- }
- else {
- return null;
- }
- }
- /** * Removes a stack from the given slot and returns it. * * @param index The slot to remove a stack from. */ public ItemStack getStackInSlotOnClosing(int index) {
- if (this.ForgeItemStacks[index] != null) {
- ItemStack itemstack = this.ForgeItemStacks[index];
- this.ForgeItemStacks[index] = null;
- return itemstack;
- }
- else {
- return null;
- }
- }
- /** * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). */ public void setInventorySlotContents(int index, ItemStack stack) {
- boolean flag = stack != null && stack.isItemEqual(this.ForgeItemStacks[index]) && ItemStack.areItemStackTagsEqual(stack, this.ForgeItemStacks[index]);
- this.ForgeItemStacks[index] = stack;
- if (stack != null && stack.stackSize > this.getInventoryStackLimit()) {
- stack.stackSize = this.getInventoryStackLimit();
- }
- if (index == 0 && !flag) {
- this.totalCookTime = this.getCookTime(stack);
- this.cookTime = 0;
- this.markDirty();
- }
- }
- /** * Gets the name of this command sender (usually username, but possibly "Rcon") */ public String getCommandSenderName() {
- return this.hasCustomName() ? this.ForgeCustomName : "container.forge";
- }
- /** * Returns true if this thing is named */ public boolean hasCustomName() {
- return this.ForgeCustomName != null && this.ForgeCustomName.length() > 0;
- }
- public void setCustomInventoryName(String p_145951_1_) {
- this.ForgeCustomName = p_145951_1_;
- }
- public void readFromNBT(NBTTagCompound compound) {
- super.readFromNBT(compound);
- NBTTagList nbttaglist = compound.getTagList("Items", 10);
- this.ForgeItemStacks = new ItemStack[this.getSizeInventory()];
- for (int i = 0;
- i < nbttaglist.tagCount();
- ++i) {
- NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
- int j = nbttagcompound.getByte("Slot");
- if (j >= 0 && j < this.ForgeItemStacks.length) {
- this.ForgeItemStacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
- }
- }
- this.ForgeBurnTime = compound.getShort("BurnTime");
- this.cookTime = compound.getShort("CookTime");
- this.totalCookTime = compound.getShort("CookTimeTotal");
- this.currentItemBurnTime = getItemBurnTime(this.ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()]);
- if (compound.hasKey("CustomName", 8)) {
- this.ForgeCustomName = compound.getString("CustomName");
- }
- }
- public void writeToNBT(NBTTagCompound compound) {
- super.writeToNBT(compound);
- compound.setShort("BurnTime", (short)this.ForgeBurnTime);
- compound.setShort("CookTime", (short)this.cookTime);
- compound.setShort("CookTimeTotal", (short)this.totalCookTime);
- NBTTagList nbttaglist = new NBTTagList();
- for (int i = 0;
- i < this.ForgeItemStacks.length;
- ++i) {
- if (this.ForgeItemStacks[i] != null) {
- NBTTagCompound nbttagcompound = new NBTTagCompound();
- nbttagcompound.setByte("Slot", (byte)i);
- this.ForgeItemStacks[i].writeToNBT(nbttagcompound);
- nbttaglist.appendTag(nbttagcompound);
- }
- }
- compound.setTag("Items", nbttaglist);
- if (this.hasCustomName()) {
- compound.setString("CustomName", this.ForgeCustomName);
- }
- }
- /** * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. */ public int getInventoryStackLimit() {
- return 64;
- }
- /** * Forge isBurning */ public boolean isBurning() {
- return this.ForgeBurnTime > 0;
- }
- @SideOnly(Side.CLIENT) public static boolean isBurning(IInventory p_174903_0_) {
- return p_174903_0_.getField(0) > 0;
- }
- /** * Like the old updateEntity(), except more generic. */ public void update() {
- boolean flag = this.isBurning();
- boolean flag1 = false;
- if (this.isBurning()) {
- --this.ForgeBurnTime;
- }
- if (!this.worldObj.isRemote) {
- if (this.isBurning() || this.ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()] != null && ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()] != null && ForgeItemStacks[slotEnum.MOLD_SLOT.ordinal()] != null) {
- if (!this.isBurning() && this.canSmelt()) {
- this.currentItemBurnTime = this.ForgeBurnTime = getItemBurnTime(this.ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()]);
- if (this.isBurning()) {
- flag1 = true;
- if (this.ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()] != null ) {
- --this.ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()].stackSize;
- if (this.ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()].stackSize == 0) {
- this.ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()] = ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()].getItem().getContainerItem(ForgeItemStacks[slotEnum.FUEL_SLOT.ordinal()]);
- }
- }
- }
- }
- if (this.isBurning() && this.canSmelt()) {
- ++this.cookTime;
- if (this.cookTime == this.totalCookTime) {
- this.cookTime = 0;
- this.totalCookTime = this.getCookTime(ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()]);
- this.smeltItem();
- flag1 = true;
- }
- }
- else {
- this.cookTime = 0;
- }
- }
- else if (!this.isBurning() && this.cookTime > 0) {
- this.cookTime = MathHelper.clamp_int(this.cookTime - 2, 0, this.totalCookTime);
- }
- if (flag != this.isBurning()) {
- flag1 = true;
- BlockForge.setState(this.isBurning(), this.worldObj, this.pos);
- }
- }
- if (flag1) {
- this.markDirty();
- }
- }
- public int getCookTime(ItemStack stack) {
- return 350;
- }
- private boolean canSmelt() {
- if (ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()] == null) {
- return false;
- }
- if (ForgeItemStacks[slotEnum.MOLD_SLOT.ordinal()] == null) {
- return false;
- }
- if(ItemStack.areItemsEqual(this.ForgeItemStacks[slotEnum.MOLD_SLOT.ordinal()] , ForgeRecipes.instance().getSmeltingMOLD(ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()]))){
- ItemStack itemstack = ForgeRecipes.instance().getSmeltingResult(ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()]);
- ItemStack MOLD = ForgeRecipes.instance().getSmeltingMOLD(ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()]);
- ItemStack MOLDSlot = this.ForgeItemStacks[slotEnum.MOLD_SLOT.ordinal()];
- if (itemstack == null || MOLD == null) return false;
- if (this.ForgeItemStacks[slotEnum.OUTPUT_SLOT.ordinal()] == null){
- return true;
- }
- if (!this.ForgeItemStacks[slotEnum.OUTPUT_SLOT.ordinal()].isItemEqual(itemstack)){
- return false;
- }
- if (!this.ForgeItemStacks[slotEnum.MOLD_SLOT.ordinal()].isItemEqual(MOLD)){
- return false;
- }
- int result = ForgeItemStacks[slotEnum.OUTPUT_SLOT.ordinal()].stackSize + itemstack.stackSize;
- return result <= getInventoryStackLimit() && result <= this.ForgeItemStacks[slotEnum.OUTPUT_SLOT.ordinal()].getMaxStackSize();
- }
- return false;
- }
- /** * Turn one item from the Forge source stack into the appropriate smelted item in the Forge result stack */
- public void smeltItem(){
- if (this.canSmelt()) {
- if(ItemStack.areItemsEqual(this.ForgeItemStacks[slotEnum.MOLD_SLOT.ordinal()] , ForgeRecipes.instance().getSmeltingMOLD(ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()]))){
- ItemStack itemstack = ForgeRecipes.instance().getSmeltingResult(ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()]);
- if (this.ForgeItemStacks[slotEnum.OUTPUT_SLOT.ordinal()] == null) {
- this.ForgeItemStacks[slotEnum.OUTPUT_SLOT.ordinal()] = itemstack.copy();
- }
- else if (this.ForgeItemStacks[slotEnum.OUTPUT_SLOT.ordinal()].getItem() == itemstack.getItem()) {
- this.ForgeItemStacks[slotEnum.OUTPUT_SLOT.ordinal()].stackSize += itemstack.stackSize;
- --ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()].stackSize;
- if (ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()].stackSize <= 0) {
- ForgeItemStacks[slotEnum.INPUT_SLOT.ordinal()] = null;
- }
- }
- }
- }
- }
- public static int getItemBurnTime(ItemStack p_145952_0_){
- if (p_145952_0_ == null) {
- return 0;
- }
- else {
- Item item = p_145952_0_.getItem();
- if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {
- Block block = Block.getBlockFromItem(item);
- if (block == Blocks.wooden_slab) {
- return 150;
- }
- if (block.getMaterial() == Material.wood) {
- return 300;
- }
- if (block == Blocks.coal_block) {
- return 16000;
- }
- }
- if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return 200;
- if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return 200;
- if (item instanceof ItemHoe && ((ItemHoe)item).getMaterialName().equals("WOOD")) return 200;
- if (item == Items.stick) return 100;
- if (item == Items.coal) return 1600;
- if (item == Items.lava_bucket) return 20000;
- if (item == Item.getItemFromBlock(Blocks.sapling)) return 100;
- if (item == Items.blaze_rod) return 2400;
- return net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(p_145952_0_);
- }
- }
- public static boolean isItemFuel(ItemStack p_145954_0_) {
- /** * Returns the number of ticks that the supplied fuel item will keep the Forge burning, or 0 if the item isn't * fuel */ return getItemBurnTime(p_145954_0_) > 0;
- }
- /** * Do not make give this method the name canInteractWith because it clashes with Container */ public boolean isUseableByPlayer(EntityPlayer player) {
- return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
- }
- public void openInventory(EntityPlayer player) {
- }
- public void closeInventory(EntityPlayer player) {
- }
- /** * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. */ public boolean isItemValidForSlot(int index, ItemStack stack) {
- return index == 2 ? false : (index != 1 ? true : isItemFuel(stack) || SlotForgeFuel.isBucket(stack));
- }
- public int[] getSlotsForFace(EnumFacing side) {
- return side == EnumFacing.DOWN ? slotsBottom : (side == EnumFacing.UP ? slotsTop : slotsSides);
- }
- /** * Returns true if automation can insert the given item in the given slot from the given side. Args: slot, item, * side */ public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
- return this.isItemValidForSlot(index, itemStackIn);
- }
- /** * Returns true if automation can extract the given item in the given slot from the given side. Args: slot, item, * side */ public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
- if (direction == EnumFacing.DOWN && index == 1) {
- Item item = stack.getItem();
- if (item != Items.water_bucket && item != Items.bucket) {
- return false;
- }
- }
- return true;
- }
- public String getGuiID() {
- return "minecraft:Forge";
- }
- public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
- return new ContainerForge(playerInventory, this);
- }
- public int getField(int id) {
- switch (id) {
- case 0: return this.ForgeBurnTime;
- case 1: return this.currentItemBurnTime;
- case 2: return this.cookTime;
- case 3: return this.totalCookTime;
- default: return 0;
- }
- }
- public void setField(int id, int value) {
- switch (id) {
- case 0: this.ForgeBurnTime = value;
- break;
- case 1: this.currentItemBurnTime = value;
- break;
- case 2: this.cookTime = value;
- break;
- case 3: this.totalCookTime = value;
- }
- }
- public int getFieldCount() {
- return 4;
- }
- public void clear() {
- for (int i = 0;
- i < this.ForgeItemStacks.length;
- ++i) {
- this.ForgeItemStacks[i] = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement