Machine Recipe Complex
-
Oui pourtant
public class ContainerOreExtractor extends Container { private TileEntityOreExtractor tileCrusher; private int workingTime; private int workingTimeNeeded; public ContainerOreExtractor(TileEntityOreExtractor tile, InventoryPlayer inventory) { this.tileCrusher = tile; this.addSlotToContainer(new Slot((IInventory)tile, 0, 8, 17));//dust 1 this.addSlotToContainer(new Slot((IInventory)tile, 1, 8, 53));//coal this.addSlotToContainer(new Slot((IInventory)tile, 2, 150, 17));//upgrade this.addSlotToContainer(new OreExtractorSlotResult(tile, 3, 64, 17));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 4, 82, 17));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 5, 100, 17));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 6, 118, 17));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 7, 64, 35));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 8, 82, 35));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 9, 100, 35));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 10, 118, 35));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 11, 64, 53));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 12, 82, 53));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 13, 100, 53));//result this.addSlotToContainer(new OreExtractorSlotResult(tile, 14, 118, 53));//result this.bindPlayerInventory(inventory); } @Override public boolean canInteractWith(EntityPlayer player) { return this.tileCrusher.isUseableByPlayer(player); } private void bindPlayerInventory(InventoryPlayer inventory) { int i; for (i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142)); } } public ItemStack transferStackInSlot(EntityPlayer player, int quantity) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(quantity); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (quantity < this.tileCrusher.getSizeInventory()) { if (!this.mergeItemStack(itemstack1, this.tileCrusher.getSizeInventory(), this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, this.tileCrusher.getSizeInventory(), false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; } public void onContainerClosed(EntityPlayer player) { super.onContainerClosed(player); this.tileCrusher.closeInventory(); } public void detectAndSendChanges() { super.detectAndSendChanges(); for(int i = 0; i < this.crafters.size(); ++i) { ICrafting icrafting = (ICrafting)this.crafters.get(i); if(this.workingTime != this.tileCrusher.workingTime) { icrafting.sendProgressBarUpdate(this, 0, this.tileCrusher.workingTime); } if(this.workingTimeNeeded != this.tileCrusher.workingTimeNeeded) { icrafting.sendProgressBarUpdate(this, 1, this.tileCrusher.workingTimeNeeded); } } this.workingTime = this.tileCrusher.workingTime; this.workingTimeNeeded = this.tileCrusher.workingTimeNeeded; } @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int value) { if(id == 0) { this.tileCrusher.workingTime = value; } if(id == 1) { this.tileCrusher.workingTimeNeeded = value; } } } -
Ton container est bien mais vérifies bien pour le .copy, parce que c’est probable que ce soit ça.
-
Pourtant oui ligne 62 du container
-
Il faut aussi que tu vérifiés dans ta fonction smelt de tile entity
-
oui pourtant il est present
package com.google.SpyMan.Mechanicalcraft.common.blockOreExtractor; import com.google.SpyMan.Mechanicalcraft.common.Items.SpeedUpgrade; import com.google.SpyMan.Mechanicalcraft.common.Items.SpeedUpgradeThree; import com.google.SpyMan.Mechanicalcraft.common.Items.SpeedUpgradeTwo; import com.google.SpyMan.Mechanicalcraft.common.MechanicalCraft; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; 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.minecraft.tileentity.TileEntityFurnace; public class TileEntityOreExtractor extends TileEntity implements IInventory { private byte direction; private ItemStack[] contents = new ItemStack[15]; protected int workingTime = 0; protected int workingTimeNeeded = 200; protected int workingTimeNeededDefault = 200; protected int burnTime = 0; protected int burnTimeTotal = 0; @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.direction = compound.getByte("Direction"); NBTTagList nbttaglist = compound.getTagList("Items", 10); 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.burnTime = compound.getShort("burnTime"); this.burnTimeTotal = compound.getShort("burnTimeTotal"); //this.workingTimeNeeded = compound.getShort("workingTimeNeeded"); } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); NBTTagList nbttaglist = new NBTTagList(); compound.setByte("Direction", this.direction); 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("burnTime", (short)this.burnTime); compound.setShort("burnTimeTotal", (short)this.burnTimeTotal); //compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded); } public byte getDirection() { return direction; } public void setDirection(byte direction) { this.direction = direction; this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); } 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()); } public int getSizeInventory() { return this.contents.length; } public void openInventory() {} public void closeInventory() {} public String getInventoryName() { return MechanicalCraft.oreExtractor.getLocalizedName(); } public boolean hasCustomInventoryName() { return false; } public int getInventoryStackLimit() { return 64; } 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; } public ItemStack getStackInSlot(int slotIndex) { return this.contents[slotIndex]; } 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; } } public ItemStack getStackInSlotOnClosing(int slotIndex) { if(this.contents[slotIndex] != null) { ItemStack itemstack = this.contents[slotIndex]; this.contents[slotIndex] = null; return itemstack; } else { return null; } } public void setInventorySlotContents(int slotIndex, ItemStack stack) { this.contents[slotIndex] = stack; if(stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); } this.markDirty(); } public boolean isItemValidForSlot(int slot, ItemStack stack) { return slot == 2 ? false : true; } public boolean isBurning() { return this.workingTime > 0; } protected boolean canSmelt() { if(this.contents[0] == null) { return false; } else { ItemStack itemstack = OreExtractorRecipes.smelting().getSmeltingResult(new ItemStack[] {this.contents[0]}); 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 smeltItem() { if(this.canSmelt()) { ItemStack itemstack = OreExtractorRecipes.smelting().getSmeltingResult(new ItemStack[] {this.contents[0]}); 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.decrStackSize(0, 1); } } public void updateEntity() { if(this.burnTime > 0) { burnTime–; } if(this.canSmelt()) { if(this.burnTime <= 0) { int time = TileEntityFurnace.getItemBurnTime(contents[1]); if (time > 0) { this.decrStackSize(1, 1); this.burnTimeTotal = time; this.burnTime = time; } } if(burnTime > 0) { workingTime++; } } if (this.workingTime >= this.workingTimeNeeded) { this.smeltItem(); this.workingTime = 0; } if (!this.canSmelt() || burnTime <= 0) { this.workingTime = 0; } // Update WorkingTime –> Speed Upgrade if (contents[2] != null) { if (contents[2].getItem() == MechanicalCraft.speedUpgrade) { workingTimeNeeded = SpeedUpgrade.getSpeedUp(); } else if (contents[2].getItem() == MechanicalCraft.speedUpgradeTwo) { workingTimeNeeded = SpeedUpgradeTwo.getSpeedUp(); } else if (contents[2].getItem() == MechanicalCraft.speedUpgradeThree) { workingTimeNeeded = SpeedUpgradeThree.getSpeedUp(); } } else { workingTimeNeeded = workingTimeNeededDefault; } } @SideOnly(Side.CLIENT) public int getCookProgress() { return this.workingTime * 24 / this.workingTimeNeeded; } @SideOnly(Side.CLIENT) public int getBurnTime() { return this.burnTime * 14 / this.burnTimeTotal; } }Recipes
package com.google.SpyMan.Mechanicalcraft.common.blockOreExtractor; import com.google.SpyMan.Mechanicalcraft.common.MechanicalCraft; 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; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Random; public class OreExtractorRecipes { private static final OreExtractorRecipes smeltingBase = new OreExtractorRecipes(); private Map <itemstack[], itemstack="">smeltingList = new HashMap<itemstack[], itemstack="">(); private Item[] resultList = new Item[] { MechanicalCraft.brokenTinOre, MechanicalCraft.brokenCopperOre, MechanicalCraft.brokenZincOre, MechanicalCraft.brokenIronOre, MechanicalCraft.brokenGoldOre, MechanicalCraft.brokenCoalOre, MechanicalCraft.brokenDiamondOre, MechanicalCraft.brokenEmeraldOre, MechanicalCraft.brokenRedstoneOre, MechanicalCraft.brokenLapisOre }; public OreExtractorRecipes() { Random item = new Random(); Random quantityRandom = new Random(); int i = item.nextInt(9); int quantity = quantityRandom.nextInt(3); this.addRecipe(Blocks.gravel, new ItemStack(resultList*, quantity, 0)); } public void addRecipe(ItemStack input1, ItemStack output1) { ItemStack[] stackList = new ItemStack[] {input1}; this.smeltingList.put(stackList, output1); } public void addRecipe(Item input1, ItemStack output1) { this.addRecipe(new ItemStack(input1), output1); } public void addRecipe(Block input1, ItemStack output1) { this.addRecipe(new ItemStack(input1), output1); } public ItemStack getSmeltingResult(ItemStack[] stack) { Iterator<map.entry<itemstack[], itemstack="">> iterator = this.smeltingList.entrySet().iterator(); Map.Entry <itemstack[], itemstack="">entry; do { if(!iterator.hasNext()) { return null; } entry = (Map.Entry<itemstack[], itemstack="">)iterator.next(); } while(!this.isSameKey(stack, (ItemStack[])entry.getKey())); return (ItemStack)entry.getValue(); } private boolean isSameKey(ItemStack[] stackList, ItemStack[] stackList2) { boolean isSame = false; if(stackList[0].getItem() == stackList2[0].getItem()) { isSame = true; } else { return false; } return isSame; } public Map <itemstack[], itemstack="">getSmeltingList() { return this.smeltingList; } public static OreExtractorRecipes smelting() { return smeltingBase; } } ```</itemstack[],></itemstack[],></itemstack[],></map.entry<itemstack[],></itemstack[],></itemstack[],> -
Effectivement bizarre… Explique plus en détail ce que ça te fait
Et aussi là je te précise que ton random n’est pas vraiment random vu que ce sera le mémé Item pour toute la session de jeu
-
alors quand le craft est terminer j’ai un item en resultat dans un de mes slots result, sauf que cet item n’est pas vraiment “réel” :
Je ne peut pas le stacker –> il se remove quand je le stack
Cela vien de mes recipes car j’ai verifié la choseEt aussi pour les ramdons comment je peut faire?
-
Ah OK, pour le random, il faut que tu le fasses quand la recette à terminé (au getSmeltingResult), et peut-être que ça résoudra ton problème du même coup
-
Ok ça c’est pour la quantity mais le random de l’item comment je peut faire ?
-
Soit dans ta liste de recette tu met le tableau d’item à la place du stack, soit tu fait un mémé random pour tt les items avec le tableau que tu as déjà crée
-
J’ai essayé de verifier si l’item dans le slot est celui que je veut et de lancer le craft avec un random mais ce ne fonctionne poins
-
? Ai pas totalement compris
Je réexplique : pour tes recettes, au lieu de faire une map avec <ce que=“” ça=“” use,=“” ce=“” donne=“” (item)=“”>, tu fais <ce que=“” ça=“” use,=“” ce=“” peut=“” donner=“” <item[]=“”>, et ensuite dans la fonction getSmeltingResult(), tu prends un item au hasard.</ce></ce>
-
Je n’y arrive poins

J’ai essayé mais après le craft n’a pas de result
Voici ma class avant modification :[font=Courier Newpublic class ]%(#345f99)[OreExtractorRecipes ]{ private static final OreExtractorRecipes smeltingBase = new OreExtractorRecipes()%(#aaa9a7)[; ] private Map<ItemStack[], ItemStack> smeltingList = new HashMap<ItemStack[], ItemStack>()%(#aaa9a7)[; ] private Item[] resultList = new Item[] { MechanicalCraft.brokenTinOre%(#aaa9a7)[, ] MechanicalCraft.brokenCopperOre%(#aaa9a7)[, ] MechanicalCraft.brokenZincOre%(#aaa9a7)[, ] MechanicalCraft.brokenIronOre%(#aaa9a7)[, ] MechanicalCraft.brokenGoldOre%(#aaa9a7)[, ] MechanicalCraft.brokenCoalOre%(#aaa9a7)[, ] MechanicalCraft.brokenDiamondOre%(#aaa9a7)[, ] MechanicalCraft.brokenEmeraldOre%(#aaa9a7)[, ] MechanicalCraft.brokenRedstoneOre%(#aaa9a7)[, ] MechanicalCraft.%(#666965)[brokenLapisOre ] }%(#aaa9a7)[; ] Random itemRand = new Random()%(#aaa9a7)[; ] Random quantityRand = new Random()%(#aaa9a7)[; ] public OreExtractorRecipes() { this.addRecipe(Blocks.gravel, new ItemStack(resultList[itemRand.nextInt(10)], quantityRand.nextInt((3) + 1), 0))%(#aaa9a7)[; ] } public void addRecipe(ItemStack *input1*, ItemStack *output1*) { ItemStack[] stackList = new ItemStack[] {*input1*}%(#aaa9a7)[; ] this.smeltingList.put(stackList, *output1*)%(#aaa9a7)[; ] } public void addRecipe(Item *input1*, ItemStack *output1*) { this.addRecipe(new ItemStack(*input1*), *output1*)%(#aaa9a7)[; ] } public void addRecipe(Block *input1*, ItemStack *output1*) { this.addRecipe(new ItemStack(*input1*), *output1*)%(#aaa9a7)[; ] } public ItemStack getSmeltingResult(ItemStack[] *stack*) { Iterator<Map.Entry<ItemStack[], ItemStack>> iterator = this.smeltingList.entrySet().iterator()%(#aaa9a7)[; ] Map.Entry<ItemStack[], ItemStack> entry%(#aaa9a7)[; ] %(#0187df)[do ] { if(!iterator.hasNext()) { return null%(#aaa9a7)[; ] } entry = (Map.Entry<ItemStack[], ItemStack>)iterator.next()%(#aaa9a7)[; ] } while(!this.isSameKey(*stack*, (ItemStack[])entry.getKey()))%(#aaa9a7)[; ] return (ItemStack)entry.getValue()%(#aaa9a7)[; ] } private boolean isSameKey(ItemStack[] *stackList*, ItemStack[] *stackList2*) { boolean isSame = false%(#aaa9a7)[; ] if(*stackList*[0].getItem() == *stackList2*[0].getItem()) { isSame = true%(#aaa9a7)[; ] } %(#0187df)[else ] { return false%(#aaa9a7)[; ] } return isSame%(#aaa9a7)[; ] } public Map<ItemStack[], ItemStack> getSmeltingList() { return this.smeltingList%(#aaa9a7)[; ] } public static OreExtractorRecipes smelting() { return smeltingBase%(#aaa9a7)[; ] } } -
Cette liste :
%(#0187df)[[size=small]**private**] %(#345f99)[[size=small]Map]%(#aaa9a7)[[size=small]<]%(#345f99)[[size=small]ItemStack]%(#666600)[[size=small][][/font]]%(#aaa9a7)[[size=small],] %(#345f99)[[size=small]ItemStack]%(#aaa9a7)[[size=small]>] %(#666965)[[size=small]smeltingList ]%(#aaa9a7)[[size=small]=] %(#0187df)[[size=small]**new**] %(#afb8c5)[[size=small]HashMap]%(#aaa9a7)[[size=small]<]%(#345f99)[[size=small]ItemStack]%(#666600)[[size=small][][/font]]%(#aaa9a7)[[size=small],] %(#345f99)[[size=small]ItemStack]%(#aaa9a7)[[size=small]>]%(#666600)[[size=small]()]%(#aaa9a7)[[size=small];]devient
%(#0187df)[[size=small]**private**] %(#345f99)[[size=small]Map]%(#aaa9a7)[[size=small]<]%(#345f99)[[size=small]ItemStack]%(#666600)[[size=small][][/font]]%(#aaa9a7)[[size=small],] %(#345f99)[[size=small]ItemStack[]]%(#aaa9a7)[[size=small]>] %(#666965)[[size=small]smeltingList ]%(#aaa9a7)[[size=small]=] %(#0187df)[[size=small]**new**] %(#afb8c5)[[size=small]HashMap]%(#aaa9a7)[[size=small]<]%(#345f99)[[size=small]ItemStack]%(#666600)[[size=small][][/font]]%(#aaa9a7)[[size=small],] %(#345f99)[[size=small]ItemStack[]]%(#aaa9a7)[[size=small]>]%(#666600)[[size=small]()]%(#aaa9a7)[[size=small];]Ducoup ceci
%(#0187df)[[size=small]**this**]%(#666600)[[size=small].]%(#afb8c5)[[size=small]addRecipe]%(#666600)[[size=small](]%(#345f99)[[size=small]Blocks]%(#666600)[[size=small].]%(#666965)[[size=small]gravel]%(#aaa9a7)[[size=small],] %(#0187df)[[size=small]**new**] %(#afb8c5)[[size=small]ItemStack]%(#666600)[[size=small](]%(#666965)[[size=small]resultList]%(#666600)[[size=small][[/font]]%(#666965)[[size=small]itemRand]%(#666600)[[size=small].]%(#afb8c5)[[size=small]nextInt]%(#666600)[[size=small](]%(#feff06)[[size=small]10]%(#666600)[[size=small])]]%(#aaa9a7)[[size=small],] %(#666965)[[size=small]quantityRand]%(#666600)[[size=small].]%(#afb8c5)[[size=small]nextInt]%(#666600)[[size=small]((]%(#feff06)[[size=small]3]%(#666600)[[size=small])] %(#aaa9a7)[[size=small]+] %(#feff06)[[size=small]1]%(#666600)[[size=small])]%(#aaa9a7)[[size=small],] %(#feff06)[[size=small]0]%(#666600)[[size=small]))]%(#aaa9a7)[[size=small];]devient ceci
%(#0187df)[[size=small]**this**]%(#666600)[[size=small].]%(#afb8c5)[[size=small]addRecipe]%(#666600)[[size=small](]%(#345f99)[[size=small]Blocks]%(#666600)[[size=small].]%(#666965)[[size=small]gravel]%(#aaa9a7)[[size=small],] %(#666965)[[size=small]resultList]%(#aaa9a7)[[size=small]; //Il faut donc que tu transformes resultList en un array d'itemstacks]Et la fonction getSmeltingResult devient ça (après le while) :
ItemStack result = [size=small((][size=smallItemStack[]][size=small)][size=smallentry][size=small.][size=smallgetValue][size=small())[random.nextInt(…)];] [size=smallresult.stackSize = random.nextInt(…);] [size=small**return**] result[size=small;] ``` Et il faut bien sur que tu changes toutes les fonctions addRecipe. -
J’ai une erreur ici: ```java
(ItemStack[])entry.getValue()qui me dit "cannot cast ….ItemStack to .....ItemStack[]" ```java [font=Courier Newpublic class ]%(#345f99)[OreExtractorRecipes ]{ private static final OreExtractorRecipes smeltingBase = new OreExtractorRecipes()%(#aaa9a7)[; ] private Map<ItemStack[], ItemStack[]> smeltingList = new HashMap<ItemStack[], ItemStack[]>()%(#aaa9a7)[; ] private ItemStack[] resultList = new ItemStack[] { new ItemStack(MechanicalCraft.brokenTinOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenCopperOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenZincOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenIronOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenGoldOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenCoalOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenDiamondOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenEmeraldOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenRedstoneOre)%(#aaa9a7)[, ] new ItemStack(MechanicalCraft.brokenLapisOre) }%(#aaa9a7)[; ] Random itemRand = new Random()%(#aaa9a7)[; ] Random quantityRand = new Random()%(#aaa9a7)[; ] public OreExtractorRecipes() { this.addRecipe(Blocks.gravel, resultList)%(#aaa9a7)[; ] } public void addRecipe(ItemStack *input1*, ItemStack[] *output1*) { ItemStack[] stackList = new ItemStack[] {*input1*}%(#aaa9a7)[; ] this.smeltingList.put(stackList, *output1*)%(#aaa9a7)[; ] } public void addRecipe(Item *input1*, ItemStack[] *output1*) { this.addRecipe(new ItemStack(*input1*), *output1*)%(#aaa9a7)[; ] } public void addRecipe(Block *input1*, ItemStack[] *output1*) { this.addRecipe(new ItemStack(*input1*), *output1*)%(#aaa9a7)[; ] } public ItemStack getSmeltingResult(ItemStack[] stack) { Iterator<Map.Entry<ItemStack[], ItemStack[]>> iterator = this.smeltingList.entrySet().iterator()%(#aaa9a7)[; ] Map.Entry<ItemStack[], ItemStack> entry%(#aaa9a7)[; ] %(#0187df)[do ] { if(!iterator.hasNext()) { return null%(#aaa9a7)[; ] } entry = (Map.Entry<ItemStack[], ItemStack>)iterator.next()%(#aaa9a7)[; ] } while(!this.isSameKey(*stack*, (ItemStack[])entry.getKey()))%(#aaa9a7)[; ] ItemStack result = ((ItemStack[])entry.getValue())[itemRand.nextInt(10)]%(#aaa9a7)[; ] result.stackSize = quantityRand.nextInt((3) + 1)%(#aaa9a7)[; ] return result%(#aaa9a7)[; ] } private boolean isSameKey(ItemStack[] *stackList*, ItemStack[] *stackList2*) { boolean isSame = false%(#aaa9a7)[; ] if(*stackList*[0].getItem() == *stackList2*[0].getItem()) { isSame = true%(#aaa9a7)[; ] } %(#0187df)[else ] { return false%(#aaa9a7)[; ] } return isSame%(#aaa9a7)[; ] } public Map<ItemStack[], ItemStack[]> getSmeltingList() { return this.smeltingList%(#aaa9a7)[; ] } public static OreExtractorRecipes smelting() { return smeltingBase%(#aaa9a7)[; ] } -
Ah oui, change ça :
java Map.Entry <itemstack[], itemstack="">entry;par ça : ```java
Map.Entry <itemstack[], itemstack[]=“”>entry;Et également ça : ```java entry = (Map.Entry<itemstack[], itemstack="">)iterator.next(); ``` par ça : ```java entry = (Map.Entry<itemstack[], itemstack[]="">)iterator.next(); ```.</itemstack[],></itemstack[],></itemstack[],></itemstack[],> -
Merci y a plus d’erreurs.
Mon Craft peut sortir plusieurs items différents, pour cela j’ai créer plusieurs slotresults (12 en tout). Comment faire pour qu’il soi tous utilisés si par exemple l’un est plein ou que l’item n’est pas le même et bien que le suivant se remplisse? -
Il faut que tu fasses une fonction qui vérifies si un slot est libre (item correcpondant, taille…), si le slot est libre, tu ajoutes l’item, sinon, tu fait la même chose avec le slot d’après. je sais qu’il y a une fonction comme ça dans le InventoryPlayer, essaye de regarder.
-
J’ai regardé dans la class InventoryPlayer j’ai je n’est pas trouvé la fonction en question
-
playerInventory.addItemStackToInventory