AppliedOnce Posted September 28, 2013 Posted September 28, 2013 Hi, is there a way I can turn this code: package com.xetosphere.arcane.tileentity; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import com.xetosphere.arcane.item.ModItems; import com.xetosphere.arcane.lib.Strings; import com.xetosphere.arcane.recipe.DuplicatorRecipes; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TileDuplicator extends TileARC implements IInventory { private ItemStack[] inventory; public static final int INVENTORY_SIZE = 3; public static final int INPUT_INVENTORY_INDEX = 0; public static final int DUST_INVENTORY_INDEX = 1; public static final int OUTPUT_INVENTORY_INDEX = 2; public int duplicatorDupleTime; public int currentItemDupleTime; public int duplicatorDupledTime2; public TileDuplicator() { inventory = new ItemStack[iNVENTORY_SIZE]; } public int getSizeInventory() { return inventory.length; } public ItemStack getStackInSlot(int slot) { return inventory[slot]; } public ItemStack decrStackSize(int slot, int ammount) { ItemStack itemStack = getStackInSlot(slot); if (itemStack != null) { if (itemStack.stackSize <= ammount) { setInventorySlotContents(slot, null); } else { itemStack = itemStack.splitStack(ammount); if (itemStack.stackSize == 0) { setInventorySlotContents(slot, null); } } } return itemStack; } public ItemStack getStackInSlotOnClosing(int slot) { ItemStack itemStack = getStackInSlot(slot); if (itemStack != null) { setInventorySlotContents(slot, null); } return itemStack; } public void setInventorySlotContents(int slot, ItemStack itemStack) { inventory[slot] = itemStack; if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) { itemStack.stackSize = getInventoryStackLimit(); } } public String getInvName() { return this.hasCustomName() ? this.getCustomName() : Strings.CONTAINER_DUPLICATOR_NAME; } public int getInventoryStackLimit() { return 64; } public void openChest() { } public void closeChest() { } public void readFromNBT(NBTTagCompound nbtTagCompound) { super.readFromNBT(nbtTagCompound); NBTTagList tagList = nbtTagCompound.getTagList("Items"); inventory = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < tagList.tagCount(); ++i) { NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(i); byte slot = tagCompound.getByte("Slot"); if (slot >= 0 && slot < inventory.length) { inventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound); } this.duplicatorDupleTime = nbtTagCompound.getShort("FuseTime"); this.duplicatorDupledTime2 = nbtTagCompound.getShort("TimeSpent"); } } public void writeToNBT(NBTTagCompound nbtTagCompound) { super.writeToNBT(nbtTagCompound); nbtTagCompound.setShort("FuseTime", (short) this.duplicatorDupleTime); nbtTagCompound.setShort("TimeSpent", (short) this.duplicatorDupledTime2); NBTTagList tagList = new NBTTagList(); for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) { if (inventory[currentIndex] != null) { NBTTagCompound tagCompound = new NBTTagCompound(); tagCompound.setByte("Slot", (byte) currentIndex); inventory[currentIndex].writeToNBT(tagCompound); tagList.appendTag(tagCompound); } } nbtTagCompound.setTag("Items", tagList); } public boolean isInvNameLocalized() { return this.hasCustomName(); } public boolean isItemValidForSlot(int i, ItemStack itemStack) { return true; } public String toString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(super.toString()); stringBuilder.append("TileDuplicator Data - "); for (int i = 0; i < inventory.length; i++) { if (i != 0) { stringBuilder.append(", "); } if (inventory[i] != null) { stringBuilder.append(String.format("inventory[%d]: %s", i, inventory[i].toString())); } else { stringBuilder.append(String.format("inventory[%d]: empty", i)); } } stringBuilder.append("\n"); return stringBuilder.toString(); } @SideOnly(Side.CLIENT) public int getCookProgressTimeScaled(int par1) { return this.duplicatorDupledTime2 * par1 / 400; } @SideOnly(Side.CLIENT) public int getBurnTimeRemainingScaled(int par1) { if (this.currentItemDupleTime == 0) { this.currentItemDupleTime = 400; } return this.duplicatorDupleTime * par1 / this.currentItemDupleTime; } public boolean isBurning() { return this.duplicatorDupleTime > 0; } public void updateEntity() { boolean flag = this.duplicatorDupleTime > 0; boolean flag1 = false; if (this.duplicatorDupleTime > 0) { --this.duplicatorDupleTime; } if (!this.worldObj.isRemote) { if (this.duplicatorDupleTime == 0 && this.canSmelt()) { this.currentItemDupleTime = this.duplicatorDupleTime = getItemBurnTime(this.inventory[DUST_INVENTORY_INDEX]); if (this.duplicatorDupleTime > 0) { flag1 = true; if (this.inventory[DUST_INVENTORY_INDEX] != null) { --this.inventory[DUST_INVENTORY_INDEX].stackSize; if (this.inventory[DUST_INVENTORY_INDEX].stackSize == 0) { this.inventory[DUST_INVENTORY_INDEX] = this.inventory[DUST_INVENTORY_INDEX].getItem().getContainerItemStack(inventory[DUST_INVENTORY_INDEX]); } } } } if (this.isBurning() && this.canSmelt()) { ++this.duplicatorDupledTime2; if (this.duplicatorDupledTime2 == 400) { this.duplicatorDupledTime2 = 0; this.smeltItem(); flag1 = true; } } else { this.duplicatorDupledTime2 = 0; } if (flag != this.duplicatorDupleTime > 0) { flag1 = true; } } if (flag1) { this.onInventoryChanged(); } } private boolean canSmelt() { if (this.inventory[iNPUT_INVENTORY_INDEX] == null) { return false; } else { ItemStack itemstack = DuplicatorRecipes.dupling().getDuplingResult(this.inventory[iNPUT_INVENTORY_INDEX]); if (itemstack == null) return false; if (this.inventory[OUTPUT_INVENTORY_INDEX] == null) return true; if (!this.inventory[OUTPUT_INVENTORY_INDEX].isItemEqual(itemstack)) return false; int result = inventory[OUTPUT_INVENTORY_INDEX].stackSize + itemstack.stackSize; return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize()); } } public void smeltItem() { if (this.canSmelt()) { ItemStack itemstack = DuplicatorRecipes.dupling().getDuplingResult(this.inventory[iNPUT_INVENTORY_INDEX]); if (this.inventory[OUTPUT_INVENTORY_INDEX] == null) { this.inventory[OUTPUT_INVENTORY_INDEX] = itemstack.copy(); } else if (this.inventory[OUTPUT_INVENTORY_INDEX].isItemEqual(itemstack)) { inventory[OUTPUT_INVENTORY_INDEX].stackSize += itemstack.stackSize; } --this.inventory[iNPUT_INVENTORY_INDEX].stackSize; if (this.inventory[iNPUT_INVENTORY_INDEX].stackSize <= 0) { this.inventory[iNPUT_INVENTORY_INDEX] = null; } } } public static int getItemBurnTime(ItemStack itemStack) { if (itemStack == null) { return 0; } int i = itemStack.getItem().itemID; int meta = itemStack.getItemDamage(); if (i == ModItems.magicDust.itemID && meta == 0) return 400; return GameRegistry.getFuelValue(itemStack); } public static boolean isItemFuel(ItemStack itemStack) { return getItemBurnTime(itemStack) > 0; } } and change it so that when I take a diamond in, it will take longer time till it finishes compared to when I put something else inside it. Quote
AppliedOnce Posted September 29, 2013 Author Posted September 29, 2013 Anyone knows how to deal with this? Quote
coolAlias Posted September 29, 2013 Posted September 29, 2013 Just make a method that returns the time required to 'cook' and replace all instances of '400' with that method. public static int getTimeRequired(ItemStack stack) { if (stack.itemID == Item.diamond.itemID) return 800; else return 400; } Something like that. Quote http://i.imgur.com/NdrFdld.png[/img]
AppliedOnce Posted September 29, 2013 Author Posted September 29, 2013 This gave me net.minecraft.util.ReportedException. Saying this: 2013-09-29 20:26:19 [iNFO] [sTDERR] net.minecraft.util.ReportedException: Rendering screen 2013-09-29 20:26:19 [iNFO] [sTDERR] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1045) 2013-09-29 20:26:19 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:944) 2013-09-29 20:26:19 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:836) 2013-09-29 20:26:19 [iNFO] [sTDERR] at net.minecraft.client.main.Main.main(Main.java:93) 2013-09-29 20:26:19 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2013-09-29 20:26:19 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2013-09-29 20:26:19 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2013-09-29 20:26:19 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source) 2013-09-29 20:26:19 [iNFO] [sTDERR] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) 2013-09-29 20:26:19 [iNFO] [sTDERR] at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2013-09-29 20:26:19 [iNFO] [sTDERR] Caused by: java.lang.NullPointerException 2013-09-29 20:26:19 [iNFO] [sTDERR] at com.xetosphere.arcane.tileentity.TileDuplicator.getTimeRequired(TileDuplicator.java:305) 2013-09-29 20:26:19 [iNFO] [sTDERR] at com.xetosphere.arcane.tileentity.TileDuplicator.getCookProgressTimeScaled(TileDuplicator.java:174) 2013-09-29 20:26:19 [iNFO] [sTDERR] at com.xetosphere.arcane.client.gui.inventory.GuiDuplicator.drawGuiContainerBackgroundLayer(GuiDuplicator.java:49) 2013-09-29 20:26:19 [iNFO] [sTDERR] at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:111) 2013-09-29 20:26:19 [iNFO] [sTDERR] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1036) 2013-09-29 20:26:19 [iNFO] [sTDERR] ... 9 more I put getTimeRequired(inventory[iNPUT_INVENTORY_INDEX]) at all places where there was 400 before exept for the place where the fuel gets how long it should burn. I also get a nullpointer exception telling me this: at com.xetosphere.arcane.tileentity.TileDuplicator.getTimeRequired(TileDuplicator.java:305) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at com.xetosphere.arcane.tileentity.TileDuplicator.getCookProgressTimeScaled(TileDuplicator.java:174) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at com.xetosphere.arcane.client.gui.inventory.GuiDuplicator.drawGuiContainerBackgroundLayer(GuiDuplicator.java:49) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:111) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1036) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:944) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at net.minecraft.client.Minecraft.run(Minecraft.java:836) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at net.minecraft.client.main.Main.main(Main.java:93) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at java.lang.reflect.Method.invoke(Unknown Source) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) 2013-09-29 20:26:19 [iNFO] [sTDOUT] at net.minecraft.launchwrapper.Launch.main(Launch.java:27) Quote
AppliedOnce Posted September 29, 2013 Author Posted September 29, 2013 Seems like I got it to work, I just had to check if the input inventory wasn't equal to null. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.