Jump to content

Jeerdus

Members
  • Posts

    104
  • Joined

  • Last visited

Everything posted by Jeerdus

  1. Thanks for the reply, but I think you didn't understand my question I have 4 slots in my machine 1. Item input 2. Cell input (it is always the same item) 3. Fuel slot 4. Output slot Now I'll give you an example: I have 1 Item that will go into the 1st slot. Now for the recipe, I require 2 cells that will go into the 2nd slot. Of course I will need some fuel, that will go into the 3rd slot. Simply, I want it go something like this, but only for certain recipes:
  2. Good day once again! I'm working on a "chemistry" mod and I made a machine which is supposed to extract elements from water, lava, iron, etc. Basically now I want to make so it requires 2 items to start smelting for only some recipes.
  3. Thanks, watched the tutorial and started to understand this thing! Thank you very much for your help!
  4. I would still appreciate help! I can't seem to be able to fix it by myself!
  5. Thank you very much! It works fine, except one thing. It speeds it up perfectly, but it doesn't update the GUI when I put the upgrades in or out of the slot. You have to reopen the tile entity for the GUI to update. Isn't there any quick fix?
  6. I am using it in: public int getCookProgressScaled(int i) { return (electrolysisCookTime * i) / finishTime; } public int getBurnTimeRemainingScaled(int i) { if (currentItemBurnTime == 0) { currentItemBurnTime = finishTime; } return (electrolysisBurnTime * i) / currentItemBurnTime; } and if (this.isBurning() && this.canSmelt()) { ++this.electrolysisCookTime; if (this.electrolysisCookTime == finishTime) { this.electrolysisCookTime = 0; this.smeltItem(); flag1 = true; } } Basically it's in the place where the number of ticks, which are required to smelt items, is supposed to be.
  7. Thank you for the help, but it's still not working. At least it isn't crashing now No matter how many Speed upgrades I put in, it's still the same speed. Also is there a way for the item to be a metadata item? If yes, then how would the code look like? Here's my tile entity code: package elementum; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.block.BlockFurnace; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemTool; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class TileEntityElectrolysisMachine extends TileEntity implements ISidedInventory { private static final int[] slots_top = new int[] {0}; private static final int[] slots_bottom = new int[] {3,4,5}; private static final int[] slots_back = new int[] {2}; private static final int[] slots_sides = new int[] {1}; private ItemStack electrolysisItemStacks[]; public int electrolysisBurnTime; public int currentItemBurnTime; public int electrolysisCookTime; private int finishTime; private int speedModifier; private String customName; private String localizedName; EntityPlayer entityplayer; public TileEntityElectrolysisMachine() { electrolysisItemStacks = new ItemStack[7]; electrolysisBurnTime = 0; currentItemBurnTime = 0; electrolysisCookTime = 0; speedModifier = 0; if(electrolysisItemStacks[6] != null && electrolysisItemStacks[6].getItem() == Elementum.upgrade){ finishTime = 1200 /(this.electrolysisItemStacks[6].stackSize + 1); } else { finishTime = 1200; } } /** * Returns the number of slots in the inventory. */ public int getSizeInventory() { return electrolysisItemStacks.length; } /** * Returns the stack in slot i */ public ItemStack getStackInSlot(int i) { return electrolysisItemStacks[i]; } public void setInventorySlotConatainers(int i, ItemStack itemstack) { electrolysisItemStacks[i] = itemstack; if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } } /** * Reads a tile entity from NBT. */ public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); electrolysisItemStacks = new ItemStack[getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i); byte byte0 = nbttagcompound1.getByte("Slot"); if (byte0 >= 0 && byte0 < electrolysisItemStacks.length) { electrolysisItemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } electrolysisBurnTime = nbttagcompound.getShort("BurnTime"); electrolysisCookTime = nbttagcompound.getShort("CookTime"); currentItemBurnTime = getItemBurnTime(electrolysisItemStacks[1]); } /** * Writes a tile entity to NBT. */ public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); nbttagcompound.setShort("BurnTime", (short)electrolysisBurnTime); nbttagcompound.setShort("CookTime", (short)electrolysisCookTime); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < electrolysisItemStacks.length; i++) { if (electrolysisItemStacks[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); electrolysisItemStacks[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } nbttagcompound.setTag("Items", nbttaglist); } public int getInventoryStackLimit() { return 64; } public int getCookProgressScaled(int i) { return (electrolysisCookTime * i) / finishTime; } public int getBurnTimeRemainingScaled(int i) { if (currentItemBurnTime == 0) { currentItemBurnTime = finishTime; } return (electrolysisBurnTime * i) / currentItemBurnTime; } public boolean isBurning() { return electrolysisBurnTime > 0; } /*public void updateEntity() { boolean flag = electrolysisBurnTime > 0; boolean flag1 = false; if (electrolysisBurnTime > 0) { electrolysisBurnTime--; } if (!worldObj.isRemote) { if (electrolysisBurnTime == 0 && canSmelt()) { currentItemBurnTime = electrolysisBurnTime = getItemBurnTime(electrolysisItemStacks[2]); if (electrolysisBurnTime > 0) { flag1 = true; if (electrolysisItemStacks[2] != null) { if (electrolysisItemStacks[2].stackSize == 0) { electrolysisItemStacks[2] = new ItemStack(electrolysisItemStacks[2].getItem().setFull3D()); } else { electrolysisItemStacks[2].stackSize--; } if (electrolysisItemStacks[2].stackSize == 0) { electrolysisItemStacks[2] = null; } } } } if (isBurning() && canSmelt()) { electrolysisCookTime++; if (electrolysisCookTime == finishTime) { electrolysisCookTime = 0; smeltItem(); flag1 = true; } } else { electrolysisCookTime = 0; } if (flag != (electrolysisBurnTime > 0)) { flag1 = true; } } if (flag1) { onInventoryChanged(); } }*/ public void updateEntity() { boolean flag = this.electrolysisBurnTime > 0; boolean flag1 = false; if (this.electrolysisBurnTime > 0) { this.electrolysisBurnTime--; } if (!this.worldObj.isRemote) { if (this.electrolysisBurnTime == 0 && this.canSmelt()) { this.currentItemBurnTime = this.electrolysisBurnTime = getItemBurnTime(this.electrolysisItemStacks[2]); if (this.electrolysisBurnTime > 0) { flag1 = true; if (this.electrolysisItemStacks[2] != null) { --this.electrolysisItemStacks[2].stackSize; if (this.electrolysisItemStacks[2].stackSize == 0) { this.electrolysisItemStacks[2] = this.electrolysisItemStacks[1].getItem().getContainerItemStack(electrolysisItemStacks[2]); } } } } if (this.isBurning() && this.canSmelt()) { ++this.electrolysisCookTime; if (this.electrolysisCookTime == finishTime) { this.electrolysisCookTime = 0; this.smeltItem(); flag1 = true; } } else { this.electrolysisCookTime = 0; } if (flag == this.electrolysisCookTime >= 0) { flag1 = true; BlockElectrolysisMachine.updateMachineBlockState(this.electrolysisCookTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord); } } if (flag1) { this.onInventoryChanged(); } } private boolean canSmelt() { if (electrolysisItemStacks[0] == null || electrolysisItemStacks[1] == null) { return false; } ItemStack itemstack = ElectrolysisMachineRecipes.getSmeltingResult(electrolysisItemStacks[0].getItem().itemID, electrolysisItemStacks[1].getItem().itemID); if (itemstack == null) { return false; } if (electrolysisItemStacks[3] == null) { return true; } if (electrolysisItemStacks[4] == null) { return true; } if (electrolysisItemStacks[5] == null) { return true; } if (electrolysisItemStacks[3] != null && electrolysisItemStacks[4] != null && electrolysisItemStacks[5] != null) { return false; } /*if (!electrolysisItemStacks[3].isItemEqual(itemstack)) { return false; } if (electrolysisItemStacks[3].stackSize < getInventoryStackLimit() && electrolysisItemStacks[3].stackSize < electrolysisItemStacks[3].getMaxStackSize()) { return true; }*/ else { //return electrolysisItemStacks[3].stackSize < itemstack.getMaxStackSize(); return false; } } public void smeltItem() { if (!canSmelt()) { return; } ItemStack itemstack = ElectrolysisMachineRecipes.getSmeltingResult(electrolysisItemStacks[0].getItem().itemID, electrolysisItemStacks[1].getItem().itemID); if (electrolysisItemStacks[3] == null) { electrolysisItemStacks[3] = itemstack.copy(); } else if(electrolysisItemStacks[3] != null) { if (electrolysisItemStacks[4] == null) { electrolysisItemStacks[4] = itemstack.copy(); } else if (electrolysisItemStacks[4] != null) { if (electrolysisItemStacks[5] == null) { electrolysisItemStacks[5] = itemstack.copy(); } } } /*else if (electrolysisItemStacks[3].itemID == itemstack.itemID) { electrolysisItemStacks[3].stackSize++; }*/ for (int i = 0; i < 2; i++) { if (electrolysisItemStacks[i].stackSize <= 0) { electrolysisItemStacks[i] = new ItemStack(electrolysisItemStacks[i].getItem().setFull3D()); } else { electrolysisItemStacks[i].stackSize--; } if (electrolysisItemStacks[i].stackSize <= 0) { electrolysisItemStacks[i] = null; } } } private static int getItemBurnTime(ItemStack itemstack) { if (itemstack == null) { return 0; } int i = itemstack.getItem().itemID; Item item = itemstack.getItem(); if (itemstack.getItem() instanceof ItemBlock && Block.blocksList[i] != null) { Block block = Block.blocksList[i]; if (block == Block.woodSingleSlab) { return 150; } if (block.blockMaterial == Material.wood) { return 300; } if (block == Block.coalBlock) { 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 (i == Item.stick.itemID) return 100; if (i == Item.coal.itemID) return 1600; if (i == Item.bucketLava.itemID) return 20000; if (i == Block.sapling.blockID) return 100; if (i == Item.blazeRod.itemID) return 2400; return GameRegistry.getFuelValue(itemstack); } public static boolean isItemFuel(ItemStack itemstack) { return getItemBurnTime(itemstack) > 0; } /** * Do not make give this method the name canInteractWith because it clashes with Container */ public boolean isUseableByPlayer(EntityPlayer entityplayer) { if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) { return false; } else { return entityplayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D; } } /** * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new * stack. */ public ItemStack decrStackSize(int i, int j) { if (electrolysisItemStacks[i] != null) { if (electrolysisItemStacks[i].stackSize <= j) { ItemStack itemstack = electrolysisItemStacks[i]; electrolysisItemStacks[i] = null; return itemstack; } ItemStack itemstack1 = electrolysisItemStacks[i].splitStack(j); if (electrolysisItemStacks[i].stackSize == 0) { electrolysisItemStacks[i] = null; } return itemstack1; } 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 i, ItemStack itemstack) { electrolysisItemStacks[i] = itemstack; if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } } /** * Returns the name of the inventory. */ public String getInvName() { return "container.electrolysisMachine"; } public void openChest() { } public void closeChest() { } /** * 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 i) { if (electrolysisItemStacks[i] != null) { ItemStack itemstack = electrolysisItemStacks[i]; electrolysisItemStacks[i] = null; return itemstack; } else { return null; } } @Override public boolean isInvNameLocalized() { return (this.customName != null) && (this.customName.length() > 0); } public void setCustomName(String name) { this.customName = name; } public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack) { return par1 == 3 ? false : (par1 == 2 ? isItemFuel(par2ItemStack) : true); } public void setGuiDisplayName(String displayName) { this.localizedName = displayName; } public int[] getAccessibleSlotsFromSide(int side) { return side == 0 ? slots_bottom : (side == 1 ? slots_top : side == 5 ? slots_back : slots_sides); } public boolean canInsertItem(int slot, ItemStack item, int side) { return this.isItemValidForSlot(slot, item); } public boolean canExtractItem(int slot, ItemStack item, int side) { return side != 0 || slot != 1 || item.itemID == Item.bucketEmpty.itemID; } }
  8. I don't want to change it in the vanilla furnace. I made my own custom furnace where the cooking time is set to 1200 ticks. The int finishTime is written in the place where the cooking time is supposed to be.
  9. I would like to know how to make the smelting speed when there is an item in slot 6. Think of it like in IC2 the Overclocker upgrade. How would you make such a thing? I made an int that sets the smelting speed of the furnace. I tried this code: if(this.electrolysisItemStacks[6].getItem() == Elementum.upgradeSpeed){ finishTime = 1200 /(this.electrolysisItemStacks[6].stackSize + 1); } else { finishTime = 1200; } but it crashed when I placed the block in the world.
  10. Here are my NBT functions from TileEntity file: public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); NBTTagList nbttaglist = nbttagcompound.getTagList("Items2"); electrolysisItemStacks = new ItemStack[getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound2 = (NBTTagCompound)nbttaglist.tagAt(i); byte byte0 = nbttagcompound2.getByte("Slot2"); if (byte0 >= 0 && byte0 < electrolysisItemStacks.length) { electrolysisItemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound2); } } electrolysisBurnTime = nbttagcompound.getShort("BurnTime2"); electrolysisCookTime = nbttagcompound.getShort("CookTime2"); currentItemBurnTime = getItemBurnTime(electrolysisItemStacks[1]); } public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); nbttagcompound.setShort("BurnTime2", (short)electrolysisBurnTime); nbttagcompound.setShort("CookTime2", (short)electrolysisCookTime); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < electrolysisItemStacks.length; i++) { if (electrolysisItemStacks[i] != null) { NBTTagCompound nbttagcompound2 = new NBTTagCompound(); nbttagcompound2.setByte("Slot2", (byte)i); electrolysisItemStacks[i].writeToNBT(nbttagcompound2); nbttaglist.appendTag(nbttagcompound2); } } nbttagcompound.setTag("Items2", nbttaglist); } And here are my NBT functions from the previous machine: public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); cellingItemStacks = new ItemStack[getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i); byte byte0 = nbttagcompound1.getByte("Slot"); if (byte0 >= 0 && byte0 < cellingItemStacks.length) { cellingItemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } cellingBurnTime = nbttagcompound.getShort("BurnTime"); cellingCookTime = nbttagcompound.getShort("CookTime"); currentItemBurnTime = getItemBurnTime(cellingItemStacks[1]); } public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); nbttagcompound.setShort("BurnTime", (short)cellingBurnTime); nbttagcompound.setShort("CookTime", (short)cellingCookTime); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < cellingItemStacks.length; i++) { if (cellingItemStacks[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); cellingItemStacks[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } nbttagcompound.setTag("Items", nbttaglist); }
  11. Good day once again, I have a problem with Custom furnace. After I put things inside the machine and then close Minecraft or exit to the menu, it doesn't save the things inside the furnace and also the fuel burn time. If you'll need any source code, just say so. FYI: I made one more furnace before and it works fine
  12. I want to name item with more then 120 metadatas the same. Because writing it like this: LanguageRegistry.addName(new ItemStack(ironCell, 1, 0), "Iron Cell"); LanguageRegistry.addName(new ItemStack(ironCell, 1, 1), "Iron Cell"); LanguageRegistry.addName(new ItemStack(ironCell, 1, 2), "Iron Cell"); LanguageRegistry.addName(new ItemStack(ironCell, 1, 3), "Iron Cell"); LanguageRegistry.addName(new ItemStack(ironCell, 1, 4), "Iron Cell"); LanguageRegistry.addName(new ItemStack(ironCell, 1, 5), "Iron Cell"); . . . would be unnecessary and really long, I'm asking if there is any other way to do this.
  13. Good day, I tried everything and I can't seem to get it to work. I have made a custom furnace and I want to make it change texture when active (things are "smelting"). I tried everything that I can do; tried vanilla code, tried some tutorials, but none of them worked. Here's the actual block code: package elementum; import java.util.Random; import elementum.Elementum; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockCellingMachine extends BlockContainer { private Random inputFurnaceRand; private final boolean isActive; private static boolean keepInventory = false; private static String textureName; @SideOnly(Side.CLIENT) private Icon topTexture; private Icon frontTexture; public BlockCellingMachine(int i, boolean flag) { super(i, Material.iron); inputFurnaceRand = new Random(); isActive = flag; this.textureName = "cellingMachine"; } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister Icon) { this.blockIcon = Icon.registerIcon(Elementum.modid + ":" + "basicSteelBlock"); this.frontTexture = Icon.registerIcon(isActive ? Elementum.modid + ":" + textureName + "_front_on" : Elementum.modid + ":" + textureName + "_front"); this.topTexture = Icon.registerIcon(Elementum.modid + ":" + textureName + "_top"); } @SideOnly(Side.CLIENT) public Icon getIcon(int side, int meta){ return meta == 0 && side == 3 ? this.frontTexture : (side == meta ? this.frontTexture : side == 1 ? this.topTexture : this.blockIcon) ; } public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); this.setDefaultDirection(par1World, par2, par3, par4); } private void setDefaultDirection(World par1World, int par2, int par3, int par4) { if (!par1World.isRemote) { int l = par1World.getBlockId(par2, par3, par4 - 1); int i1 = par1World.getBlockId(par2, par3, par4 + 1); int j1 = par1World.getBlockId(par2 - 1, par3, par4); int k1 = par1World.getBlockId(par2 + 1, par3, par4); byte b0 = 3; if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1]) { b0 = 3; } if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l]) { b0 = 2; } if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1]) { b0 = 5; } if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1]) { b0 = 4; } par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2); } } /*public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) { int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (l == 0) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2); } if (l == 1) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2); } if (l == 2) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2); } if (l == 3) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2); } }*/ /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if (par1World.isRemote) { return true; } else if (!par5EntityPlayer.isSneaking()) { TileEntityCellingMachine var10 = (TileEntityCellingMachine) par1World.getBlockTileEntity(par2, par3, par4); if (var10 != null) { par5EntityPlayer.openGui(Elementum.instance, 0, par1World, par2, par3, par4); } return true; } else { return false; } } /** * Update which block ID the furnace is using depending on whether or not it is burning */ public static void updateFurnaceBlockState(boolean active, World worldObj, int x, int y, int z) { int i = worldObj.getBlockMetadata(x, y, z); TileEntity tileentity = worldObj.getBlockTileEntity(x, y, z); keepInventory = true; if(active){ worldObj.setBlock(x, y, z, Elementum.cellingMachineActive.blockID); }else{ worldObj.setBlock(x, y, z, Elementum.cellingMachine.blockID); } keepInventory = false; worldObj.setBlockMetadataWithNotify(x, y, z, i, 2); if(tileentity != null){ tileentity.validate(); worldObj.setBlockTileEntity(x, y, z, tileentity); } } /** * Returns the TileEntity used by this block. */ public TileEntity getBlockEntity() { return new TileEntityCellingMachine(); } public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) { int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (l == 0) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2); } if (l == 1) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2); } if (l == 2) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2); } if (l == 3) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2); } if (par6ItemStack.hasDisplayName()) { ((TileEntityCellingMachine)par1World.getBlockTileEntity(par2, par3, par4)).setCustomName(par6ItemStack.getDisplayName()); } } /** * Called whenever the block is removed. */ public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) { if (!keepInventory) { TileEntityCellingMachine var7 = (TileEntityCellingMachine)par1World.getBlockTileEntity(par2, par3, par4); if (var7 != null) { for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8) { ItemStack itemstack = var7.getStackInSlot(var8); if (itemstack != null) { float f = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F; float f1 = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F; float f2 = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F; while (itemstack.stackSize > 0) { int k1 = this.inputFurnaceRand.nextInt(21) + 10; if (k1 > itemstack.stackSize) { k1 = itemstack.stackSize; } itemstack.stackSize -= k1; EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage())); if (itemstack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } float f3 = 0.05F; entityitem.motionX = (double)((float)this.inputFurnaceRand.nextGaussian() * f3); entityitem.motionY = (double)((float)this.inputFurnaceRand.nextGaussian() * f3 + 0.2F); entityitem.motionZ = (double)((float)this.inputFurnaceRand.nextGaussian() * f3); par1World.spawnEntityInWorld(entityitem); } } } par1World.func_96440_m(par2, par3, par4, par5); } } super.breakBlock(par1World, par2, par3, par4, par5, par6); } public boolean hasComparatorInputOverride() { return true; } public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5) { return Container.calcRedstoneFromInventory((IInventory)par1World.getBlockTileEntity(par2, par3, par4)); } public int idPicked(World world, int x, int y, int z){ return Elementum.cellingMachine.blockID; } @Override public TileEntity createNewTileEntity(World world) { return new TileEntityCellingMachine(); } }
  14. Alright. Fixed it now! Thank you everyone for your help Used: private static ItemStack getOutput(int i, int j) { if (i == Item.clay.itemID && j == Item.paper.itemID) { Random rand = new Random(); int randNum = rand.nextInt(10); if(randNum == 1){ return new ItemStack(Item.bone, 1); } if(randNum == 2){ return new ItemStack(Item.stick, 1); } else{ return new ItemStack(Item.arrow, 1); } } return null; }
  15. Thanks! Now I just have to figure out how to get random items from recipes.
  16. Tried that, it limits all the slots (even the coal one) Basicly I want to not stack it in the output slot, but stack it outside the slot (in inventory) EDIT: And about those recipes, I'll show you an example: Slot 1 = Item.arrow Slot 2 = Item.bone Output slot = 25% Item.ingotGold, 10% Item.ingotGold, 5% Item.diamond, 60% Block.cobblestone And becouse the item couldn't stack, I want to limit only the output slot to 1 item at a time. My recipes look like this: private static ItemStack getOutput(int i, int j) { if (i == Elementum.uraniumItem.itemID && j == Elementum.ironCell.itemID) { return new ItemStack(Elementum.uraniumCell, 1); } return null; }
  17. Good day, I made a fully functional double input furnace. Except now I want to make it so it creates random output. I suppose that I will need to make the output slot have maximum stack of 1, but in inventory I want for the items to stack. So I am asking for your help: How do I make the output slot have maximum stack of 1 and how to create the random output?
  18. I have a two input furnace and I want to say that when itemstack1 isn't Elementum.ironCell OR TileEntityCellingMachine.isItemFuel(itemstack1) // which means all items that power the furnace put the itemstack1 (which can be any item) into a slot number 0. For some weird reason it won't work. Here's the method: public ItemStack transferStackInSlot(EntityPlayer player, int slotNum) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(slotNum); if(slot != null && slot.getHasStack()){ ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if(slotNum == 3){ if(!this.mergeItemStack(itemstack1, 4, 40, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if(slotNum != 2 && slotNum != 1 && slotNum != 0){ if(itemstack1.getItem() != Elementum.ironCell || !TileEntityCellingMachine.isItemFuel(itemstack1)){ if(!this.mergeItemStack(itemstack1, 0, 1, false)){ return null; } } else if(TileEntityCellingMachine.isItemFuel(itemstack1)){ if (!this.mergeItemStack(itemstack1, 2, 3, false)){ return null; } } else if(itemstack1.getItem() == Elementum.ironCell){ if (!this.mergeItemStack(itemstack1, 1, 2, false)){ return null; } } else if(slotNum >= 4 && slotNum < 31){ if(!this.mergeItemStack(itemstack1, 31, 40, false)){ return null; } } else if(slotNum >= 31 && slotNum > 40 && !this.mergeItemStack(itemstack1, 31, 40, false)){ if(!this.mergeItemStack(itemstack1, 4, 31, false)){ return null; } } } else if(!this.mergeItemStack(itemstack1, 4, 31, false)){ return null; } if(itemstack1.stackSize == 0){ slot.putStack((ItemStack)null); } else{ slot.onSlotChanged(); } if(itemstack1.stackSize == itemstack.stackSize){ return null; } slot.onPickupFromSlot(player, itemstack1); } return itemstack; }
  19. Good day once again, I made a custom furnace recently, everything works fine except two things. The first problem is that my machine won't rotate towards the player. The second problem is that it doesn't change texture when active. Here's the Block class for ya: package elementum; import java.util.Random; import elementum.Elementum; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockCellingMachine extends BlockContainer { private Random inputFurnaceRand; private final boolean isActive; private static boolean keepInputFurnaceInventory = false; private static String textureName; @SideOnly(Side.CLIENT) private Icon topTexture; private Icon frontTexture; private Icon frontTextureActive; public BlockCellingMachine(int i, boolean flag) { super(i, Material.iron); inputFurnaceRand = new Random(); isActive = flag; this.textureName = "cellingMachine"; } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister Icon) { this.blockIcon = Icon.registerIcon(Elementum.modid + ":" + textureName); this.frontTexture = Icon.registerIcon(Elementum.modid + ":" + textureName + "_front_off"); this.frontTextureActive = Icon.registerIcon(Elementum.modid + ":" + textureName + "_front_on"); this.topTexture = Icon.registerIcon(Elementum.modid + ":" + textureName + "_top"); } @SideOnly(Side.CLIENT) public Icon getIcon(int side, int meta){ if(side == 1){ return this.topTexture; } if(side == 3 && isActive){ return this.frontTextureActive; } else if(side == 3){ return this.frontTexture; } return this.blockIcon; } public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); this.setDefaultDirection(par1World, par2, par3, par4); } private void setDefaultDirection(World par1World, int par2, int par3, int par4) { if (!par1World.isRemote) { int l = par1World.getBlockId(par2, par3, par4 - 1); int i1 = par1World.getBlockId(par2, par3, par4 + 1); int j1 = par1World.getBlockId(par2 - 1, par3, par4); int k1 = par1World.getBlockId(par2 + 1, par3, par4); byte b0 = 3; if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1]) { b0 = 3; } if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l]) { b0 = 2; } if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1]) { b0 = 5; } if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1]) { b0 = 4; } par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2); } } /*public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) { int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (l == 0) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2); } if (l == 1) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2); } if (l == 2) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2); } if (l == 3) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2); } }*/ /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if (par1World.isRemote) { return true; } else if (!par5EntityPlayer.isSneaking()) { TileEntityCellingMachine var10 = (TileEntityCellingMachine) par1World.getBlockTileEntity(par2, par3, par4); if (var10 != null) { par5EntityPlayer.openGui(Elementum.instance, 0, par1World, par2, par3, par4); } return true; } else { return false; } } /** * Update which block ID the furnace is using depending on whether or not it is burning */ public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4) { int var5 = par1World.getBlockMetadata(par2, par3, par4); TileEntity var6 = par1World.getBlockTileEntity(par2, par3, par4); keepInputFurnaceInventory = true; if (par0) { par1World.setBlock(par2, par3, par4, Elementum.cellingMachineActive.blockID); } else { par1World.setBlock(par2, par3, par4, Elementum.cellingMachine.blockID); } keepInputFurnaceInventory = false; par1World.setBlockMetadataWithNotify(par2, par3, par4, var5, 2); if (var6 != null) { var6.validate(); par1World.setBlockTileEntity(par2, par3, par4, var6); } } /** * Returns the TileEntity used by this block. */ public TileEntity getBlockEntity() { return new TileEntityCellingMachine(); } public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) { int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (l == 0) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2); } if (l == 1) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2); } if (l == 2) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2); } if (l == 3) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2); } if (par6ItemStack.hasDisplayName()) { ((TileEntityCellingMachine)par1World.getBlockTileEntity(par2, par3, par4)).setCustomName(par6ItemStack.getDisplayName()); } } /** * Called whenever the block is removed. */ public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) { if (!keepInputFurnaceInventory) { TileEntityCellingMachine var7 = (TileEntityCellingMachine)par1World.getBlockTileEntity(par2, par3, par4); if (var7 != null) { for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8) { ItemStack itemstack = var7.getStackInSlot(var8); if (itemstack != null) { float f = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F; float f1 = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F; float f2 = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F; while (itemstack.stackSize > 0) { int k1 = this.inputFurnaceRand.nextInt(21) + 10; if (k1 > itemstack.stackSize) { k1 = itemstack.stackSize; } itemstack.stackSize -= k1; EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage())); if (itemstack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } float f3 = 0.05F; entityitem.motionX = (double)((float)this.inputFurnaceRand.nextGaussian() * f3); entityitem.motionY = (double)((float)this.inputFurnaceRand.nextGaussian() * f3 + 0.2F); entityitem.motionZ = (double)((float)this.inputFurnaceRand.nextGaussian() * f3); par1World.spawnEntityInWorld(entityitem); } } } par1World.func_96440_m(par2, par3, par4, par5); } } super.breakBlock(par1World, par2, par3, par4, par5, par6); } public boolean hasComparatorInputOverride() { return true; } public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5) { return Container.calcRedstoneFromInventory((IInventory)par1World.getBlockTileEntity(par2, par3, par4)); } @Override public TileEntity createNewTileEntity(World world) { return new TileEntityCellingMachine(); } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.