Machine avec plusieurs input
-
Bonjour ! ou reBonjour !
J’ai créé une machine il y a très peu de temps grace au tuto de BrokenSwing mais j’aimerai avoir un craft avec plusieurs item en input dans chaque slot
Exemple: “3 sticks dans le premier slot , 2 sticks dans le 2ème slot et enfin 1 charbon dans le 3ème slot donne 4 buches”
La question a déja été posée dans le tuto en question mais aucune réponse n’a vraiment été donnée.Voici quelques classes potentiellement utile pour qu’on me fournisse de l’aide:
La tile entity de ma machine :
package com.iutils.infinite.tileentities; import com.iutils.infinite.recipes.CompressorRecipes; 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.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants; public class CompressorTE extends TileEntity implements IInventory { private ItemStack[] contents = new ItemStack[4]; private String customName; private int workingTime = 0; private int workingTimeNeeded = 200; @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING)) { this.customName = compound.getString("CustomName"); } NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND); this.contents = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; if (j >= 0 && j < this.contents.length) { this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } this.workingTime = compound.getShort("workingTime"); this.workingTimeNeeded = compound.getShort("workingTimeNeeded"); } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); NBTTagList nbttaglist = new NBTTagList(); if (this.hasCustomInventoryName()) { compound.setString("CustomName", this.customName); } for (int i = 0; i < this.contents.length; ++i) { if (this.contents* != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.contents*.writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } compound.setTag("Items", nbttaglist); compound.setShort("workingTime",(short)this.workingTime); compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded); } public Packet getDescriptionPacket() { NBTTagCompound nbttagcompound = new NBTTagCompound(); this.writeToNBT(nbttagcompound); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound); } public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); } @Override public int getSizeInventory() { return this.contents.length; } @Override public ItemStack getStackInSlot(int slotIndex) { return this.contents[slotIndex]; } @Override public ItemStack decrStackSize(int slotIndex, int amount) { if (this.contents[slotIndex] != null) { ItemStack itemstack; if (this.contents[slotIndex].stackSize <= amount) { itemstack = this.contents[slotIndex]; this.contents[slotIndex] = null; this.markDirty(); return itemstack; } else { itemstack = this.contents[slotIndex].splitStack(amount); if (this.contents[slotIndex].stackSize == 0) { this.contents[slotIndex] = null; } this.markDirty(); return itemstack; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int slotIndex) { if (this.contents[slotIndex] != null) { ItemStack itemstack = this.contents[slotIndex]; this.contents[slotIndex] = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int slotIndex, ItemStack stack) { this.contents[slotIndex] = stack; if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); } this.markDirty(); } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.customName : "tile.compressor.name"; } @Override public boolean hasCustomInventoryName() { return this.customName != null && !this.customName.isEmpty(); } public void setCustomName(String customName) { this.customName = customName; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int slotIndex, ItemStack stack) { return true; } public boolean isBurning() { return this.workingTime > 0; } private boolean canSmelt() { if (this.contents[0] == null || this.contents[1] == null || this.contents[2] == null) { return false; } else { ItemStack itemstack = CompressorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); if (itemstack == null) return false; if (this.contents[3] == null) return true; if (!this.contents[3].isItemEqual(itemstack)) return false; int result = contents[3].stackSize + itemstack.stackSize; return result <= getInventoryStackLimit() && result <= this.contents[3].getMaxStackSize(); } } public void updateEntity() { if(this.isBurning() && this.canSmelt()) { ++this.workingTime; } if(this.canSmelt() && !this.isBurning()) { this.workingTime = 1; } if(this.canSmelt() && this.workingTime == this.workingTimeNeeded) { this.smeltItem(); this.workingTime = 0; } if(!this.canSmelt()) { this.workingTime= 0; } System.out.println("wT = " + workingTime); System.out.println("wTN = " + workingTimeNeeded); } public void smeltItem() { if (this.canSmelt()) { ItemStack itemstack = CompressorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); if (this.contents[3] == null) { this.contents[3] = itemstack.copy(); } else if (this.contents[3].getItem() == itemstack.getItem()) { this.contents[3].stackSize += itemstack.stackSize; } –this.contents[0].stackSize; –this.contents[1].stackSize; –this.contents[2].stackSize; if (this.contents[0].stackSize <= 0) { this.contents[0] = null; } if (this.contents[1].stackSize <= 0) { this.contents[1] = null; } if (this.contents[2].stackSize <= 0) { this.contents[2] = null; } } } }
La classe des recipes :
package com.iutils.infinite.recipes; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class CompressorRecipes { private static final CompressorRecipes smeltingBase = new CompressorRecipes(); private Map smeltingList = new HashMap(); public CompressorRecipes() { this.addRecipe(Items.apple, Items.apple, Items.arrow, new ItemStack(Items.iron_helmet)); this.addRecipe(Items.apple, Items.apple, Items.apple, new ItemStack(Items.golden_apple)); } public void addRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack3, ItemStack stack4) { ItemStack[] stackList = new ItemStack[]{stack1, stack2, stack3}; this.smeltingList.put(stackList, stack4); } public void addRecipe(Item item1, Item item2, Item item3, ItemStack stack) { this.addRecipe(new ItemStack(item1), new ItemStack(item2), new ItemStack(item3), stack); } public void addRecipe(Block block1, Item item2, Item item3, ItemStack stack) { this.addRecipe(Item.getItemFromBlock(block1), item2, item3, stack); } public void addRecipe(Block block1, Block block2, Item item3, ItemStack stack) { this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), item3, stack); } public void addRecipe(Block block1, Block block2, Block block3, ItemStack stack) { this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), Item.getItemFromBlock(block3), stack); } public ItemStack getSmeltingResult(ItemStack[] stack) { Iterator iterator = this.smeltingList.entrySet().iterator(); Entry entry; do { if (!iterator.hasNext()) { return null; } entry = (Entry)iterator.next(); } while (!this.isSameKey(stack, (ItemStack[])entry.getKey())); return (ItemStack)entry.getValue(); } private boolean isSameKey(ItemStack[] stackList, ItemStack[] stackList2) { boolean isSame = false; for(int i=0; i<=2; i++) { if(stackList*.getItem() == stackList2*.getItem()) { isSame = true; } else { return false; } } return isSame; } public Map getSmeltingList() { return this.smeltingList; } public static CompressorRecipes smelting() { return smeltingBase; } }
En espérant que quelqu’un puisse m’aider !
-
Salut, alors je pense qu’il faudrait que tout simplement dans la fonction “isSameKey(ItemStack[] stackList, ItemStack[] stackList2)” de ta classe “CompressorRecipes” tu checkes si la taille du stack en input est plus grande ou égale à la taille spécifiée dans la recette (qu’il faudra changer). Il faudra aussi changer la fonction “smeltItem()” de ta machine pour que les items disparaissent correctement de leurs slots respectifs.
-
Je sais vraiment pas comment faire pour enlever le nombre d’items que j’ai mis dans la recette parce que je doit récupérer des données de la class CompressorRecipes