Créer un bloc type four (machine)
-
Dans ta fonction getClientGuiElement :
if(tile instanceof TileEntitySechoir) { return new SechoirContainer((TileEntitySechoir)tile, player.inventory); } if(tile instanceof TileEntityEntubeuse) { return new EntubeuseContainer((TileEntityEntubeuse)tile, player.inventory); }Le problème vient de là car il faut toujours retourner un Gui, donc tu dois changer les “return UnContainer” par des “return UnGui”.
PS: “Entubeuse”, quel nom !

-
Hum, je ne comprend pas, l’Alambic ne pose aucun soucis alors qu’il retourne un Container lui-aussi.
:::
(https://t2.ftcdn.net/jpg/00/03/53/61/500_F_3536130_VwfKdvaF345kuC0foyHZNXq8eo7dI5.jpg)
::: -
Non c’est un gui : " return new AlambicGUI((TileEntityAlambic)tile, player.inventory);"
-
Ouki! Sacrée poutre que tu me retires de l’oeil, je me persuadais moi-même qu’il n’y avait qu’une fonction dans cette classe… Bref merci pour ce point qui m’empêchait d’avancer.
Du coup la machine à deux slots fonctionnent bien, pas de soucis.
Celle à un seul par contre ne semble pas comprendre les recettes suggérées.Comme les autres fonctionnent par tableau de stacks mais que je suppose que ce n’est pas nécessaire et j’ai donc regardé la classe du four vanilla pour obtenir cette classe:
package fr.powergame.modpg2.common; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class SechoirRecipes { private static final SechoirRecipes smeltingBase = new SechoirRecipes(); @SuppressWarnings("rawtypes") private Map smeltingList = new HashMap(); // private Map <itemstack[], itemstack="">smeltingList = new HashMap<itemstack[], itemstack="">(); public SechoirRecipes() { this.addRecipe(new ItemStack(ModPg2.itemMetadata, 1, 21), new ItemStack(ModPg2.itemMetadata, 1, 22)); this.addRecipe(new ItemStack(ModPg2.itemMetadata, 1, 23), new ItemStack(ModPg2.itemMetadata, 1, 24)); } @SuppressWarnings("unchecked") public void addRecipe(ItemStack stack1, ItemStack stack2) { this.smeltingList.put(stack1, stack2); } public void addRecipe(Item item1, ItemStack stack) { this.addRecipe(new ItemStack(item1), stack); } // @SuppressWarnings("rawtypes") // 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() && stackList*.getItemDamage() == stackList2*.getItemDamage()) // { // isSame = true; // } // else // { // return false; // } // } // return isSame; // } @SuppressWarnings("rawtypes") 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 stack1, ItemStack stack2) { return stack2.getItem() == stack1.getItem() && (stack2.getItemDamage() == 32767 || stack2.getItemDamage() == stack1.getItemDamage()); } @SuppressWarnings("rawtypes") public Map getSmeltingList() { return this.smeltingList; } public static SechoirRecipes smelting() { return smeltingBase; } }Je ne sais pas ce que devient le smeltingList dans le cas où il n’y a qu’un slot d’input</itemstack[],></itemstack[],>
-
Tu as juste à remplacer les ItemStack[] par des ItemStacks.
PS : Tu n’as pas de crash, parce que tu essayes de cast un ItemStack[] en un ItemStack à la ligne 84; -
Euh non je n’ai pas de crash si c’est une question et j’ai retiré déjà tous les ItemStack[] que j’ai vu, le code ne fonctionne pas cela dit.
Tu as peut-être répondu avant que j’édit mon message pour la dernière fois, mauvais timing de ma part.
J’ai changé la fonction isSameKey et du coup les arguments de la fonction précédente et le mapping, enfin le “Map truc bidule” comme je dirais… -
Là ça devrait marcher, montre la classe de ton TE si les fonctions canSmelt, smelt ou updateEntity ont changé.
Et essaye de mettre workingTime >= workingTimeNeeded au lieu de workingTime == workingTimeNeeded dans ta fonction updateEntity(). -
J’ai essayé de faire le plus attention à changer les bons slots, à voir =d
Edit:
ItemStack itemstack = SechoirRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0]});Mon erreur était là à cause d’un oubli, j’avais laissé les recettes de l’alambic comme un idiot (je travaille trop tard visiblement)
Mais du coup, le new ItemStack[]{this.contents[0]} devient quoi? Je teste des choses mais c’pas conventionnel visiblement
-
ça dépend de ce que tu veux faire mais si tu n’as besoin que d’un seul slot tu n’es pas obligé d’utiliser une array d’ItemStack
-
Oui clairement je n’ai qu’un slot et donc pas besoin de cet array d’ItemStack
C’est mon “niveau” de java qui me bloque
Je teste " new ItemStack({this.contents[0]}) " ou encore " new ItemStack{this.contents[0]} " mais eclipse semble se demander ce que j’essaie de faire.
-
new ItemStack[]{this.contents[0]}
-
Euh, mais précédemment j’ai changé des fonctions pour enlever l’array partout ailleurs comme:
package fr.powergame.modpg2.common; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class SechoirRecipes { private static final SechoirRecipes smeltingBase = new SechoirRecipes(); @SuppressWarnings("rawtypes") private Map smeltingList = new HashMap(); public SechoirRecipes() { this.addRecipe(new ItemStack(ModPg2.itemMetadata, 1, 21), new ItemStack(ModPg2.itemMetadata, 1, 22)); this.addRecipe(new ItemStack(ModPg2.itemMetadata, 1, 23), new ItemStack(ModPg2.itemMetadata, 1, 24)); } @SuppressWarnings("unchecked") public void addRecipe(ItemStack stack1, ItemStack stack2) { this.smeltingList.put(stack1, stack2); } public void addRecipe(Item item1, ItemStack stack) { this.addRecipe(new ItemStack(item1), stack); } @SuppressWarnings("rawtypes") 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 stack1, ItemStack stack2) { return stack2.getItem() == stack1.getItem() && (stack2.getItemDamage() == 32767 || stack2.getItemDamage() == stack1.getItemDamage()); } @SuppressWarnings("rawtypes") public Map getSmeltingList() { return this.smeltingList; } public static SechoirRecipes smelting() { return smeltingBase; } }Sinon je n’aurais rien eu à changer à ce niveau là dans la TileEntity BrockenSwing
-
Pour transformer cet array “new ItemStack[]{this.contents[0]}” en variable simple, suffit de l’écrire comme ça “this.contents[0]”.
-
Ok nickel.
Du coup this.content[0] est un ItemStack apparement, je suis plus lent à apprendre que je ne le pensais.Tout fonctionne, merci d’avoir pris de votre temps pour m’aider à régler ces “détails” en somme.
-
this.contents[0] est un item stack car this.contents est un tableau de item stack, et à partir du moment ou un met “[un nombre]” derrière le nom d’un tableau, le type de ce qu’on obtient est le même que celui du tableau, mais c’est une variable toute simple :“ItemStack unstack = this.content[0];”.
-
Super tuto
je viens de le lire et j’ai voulu le faire, mais j’ai un petit souci, quand je veux clique droit sur mon block, rien ne ce passe…
J’ai vérifier le code et tenté de résoudre mon problème mais impossible.
Pouvez-vous me guider pour tenter de trouver mon problème ? car la je sèche, mais j’aimerai essayé de le trouver

Merci d’avance
-
passe le code de ton GuiHandler
-
@‘Riizn’:
passe le code de ton GuiHandler
C’est le Decomposer qui ne fonctionne pas, le composer c’est ok (c’est un coffre)
package be.hydroen.chimicraft.gui; import be.hydroen.chimicraft.container.ContainerComposer; import be.hydroen.chimicraft.container.ContainerDecomposer; import be.hydroen.chimicraft.tileentity.TileEntityComposer; import be.hydroen.chimicraft.tileentity.TileEntityDecomposer; import cpw.mods.fml.common.network.IGuiHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class GuiHandlerChimiCraft implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityComposer) { return new ContainerComposer((TileEntityComposer)tile, player.inventory); } if(tile instanceof TileEntityDecomposer) { return new ContainerDecomposer((TileEntityDecomposer)tile, player.inventory); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityComposer) { return new GuiComposer((TileEntityComposer)tile, player.inventory); } if(tile instanceof TileEntityDecomposer) { return new GuiDecomposer((TileEntityDecomposer)tile, player.inventory); } return null; } } -
Pas de problème ici, il faut le code du bloc, du tile entity, et du container.
-
@‘robin4002’:
Pas de problème ici, il faut le code du bloc, du tile entity, et du container.
Voila voila et merci pour le coup de mains
:::Block
package be.hydroen.chimicraft.blocks; import be.hydroen.chimicraft.common.ModChimiCraft; import be.hydroen.chimicraft.tileentity.TileEntityComposer; import be.hydroen.chimicraft.tileentity.TileEntityDecomposer; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class BlockDecomposer extends BlockContainer { public BlockDecomposer(Material material) { super(Material.rock); this.setResistance(8.0F); this.setHarvestLevel("pickaxe", 1); this.setBlockTextureName(ModChimiCraft.MODID + ":decomposer"); this.setCreativeTab(ModChimiCraft.creativeTabsChimiCraft); } @Override public TileEntity createNewTileEntity(World world, int metadata) { if(metadata == 1) { return new TileEntityDecomposer(); } return null; } @Override public boolean hasTileEntity(int metadata) { return true; } public boolean onBlockActived(World world, int x, int y, int z, EntityPlayer player, int side, float hitx, float hity, float hitz) { if(world.isRemote) { return true; } else { player.openGui(ModChimiCraft.instance, 1, world, x, y, z); return true; } } public void breakBlock(World world, int x, int y, int z, Block block, int metadata) //Loot les objets du bloc sur le sol { TileEntity tileentity = world.getTileEntity(x, y, z); if (tileentity instanceof IInventory) { IInventory inv = (IInventory)tileentity; for (int i1 = 0; i1 < inv.getSizeInventory(); ++i1) { ItemStack itemstack = inv.getStackInSlot(i1); if (itemstack != null) { float f = world.rand.nextFloat() * 0.8F + 0.1F; float f1 = world.rand.nextFloat() * 0.8F + 0.1F; EntityItem entityitem; for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) { int j1 = world.rand.nextInt(21) + 10; if (j1 > itemstack.stackSize) { j1 = itemstack.stackSize; } itemstack.stackSize -= j1; entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); float f3 = 0.05F; entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3); entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F); entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3); if (itemstack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } } } } world.func_147453_f(x, y, z, block); } super.breakBlock(world, x, y, z, block, metadata); } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityComposer) { if(stack.hasDisplayName()) { ((TileEntityComposer)tile).setCustomName(stack.getDisplayName()); } } } }TileEntity
package be.hydroen.chimicraft.tileentity; import be.hydroen.chimicraft.recipes.DecomposerRecipes; 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.tileentity.TileEntity; public class TileEntityDecomposer extends TileEntity implements IInventory { private ItemStack[] contents = new ItemStack[4]; private int workingTime = 0; //Temps de cuisson actuel private int workingTimeNeeded = 200 ; //Temps de cuisson nécessaire @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); NBTTagList nbttaglist = new NBTTagList(); for(int i = 0; i < this.contents.length; ++i) //pour les slots { 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);//On les enregistre en short compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); 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.workingTimeNeeded = compound.getShort("workingTimeNeeded"); } @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 "tile.decomposer"; } @Override public boolean hasCustomInventoryName() { return false; } @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 slot, ItemStack stack) { return slot == 3 ? false : true; } public boolean isBurning() { return this.workingTime > 0; } private boolean canSmelt() { if (this.contents[0] == null || this.contents[1] == null || this.contents[2] == null) //Si les trois premiers slots sont vides { return false; //On ne peut pas lancer le processus } else { ItemStack itemstack = DecomposerRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); if (itemstack == null) return false; //rapport avec les recettes if (this.contents[3] == null) return true; //vérifications du slot d'output if (!this.contents[3].isItemEqual(itemstack)) return false; //ici aussi int result = contents[3].stackSize + itemstack.stackSize; return result <= getInventoryStackLimit() && result <= this.contents[3].getMaxStackSize(); //Et là aussi décidément } } @Override public void updateEntity() //Méthode exécutée à chaque tick { if(this.isBurning() && this.canSmelt()) //Si on "cuit" et que notre recette et toujours bonne, on continue { ++this.workingTime; //incrémentation } if(this.canSmelt() && !this.isBurning()) //Si la recette est bonne mais qu'elle n'est toujours pas lancée, on la lance { this.workingTime = 1; //La méthode isBurning() renverra true maintenant (1>0) } if(this.canSmelt() && this.workingTime == this.workingTimeNeeded) //Si on est arrivé au bout du temps de cuisson et que la recette est toujours bonne { this.smeltItem(); //on "cuit" les items this.workingTime = 0; //et on réinitialise le temps de cuisson } if(!this.canSmelt()) //Si la recette la recette n'est plus bonne { this.workingTime= 0; //le temps de cuisson est de 0 } } public void smeltItem() { if (this.canSmelt()) { ItemStack itemstack = DecomposerRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); //On récupère l'output de la recette if (this.contents[3] == null) //Si il y a rien dans le slot d'output { this.contents[3] = itemstack.copy(); //On met directement l'ItemStack } else if (this.contents[3].getItem() == itemstack.getItem()) //Et si l'item que l'on veut est le même que celui qu'il y a déjà { this.contents[3].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack } –this.contents[0].stackSize; //On décrémente les slots d'input –this.contents[1].stackSize; –this.contents[2].stackSize; if (this.contents[0].stackSize <= 0) //Si les slots sont vides, on remet à null le slot { this.contents[0] = null; } if (this.contents[1].stackSize <= 0) { this.contents[1] = null; } if (this.contents[2].stackSize <= 0) { this.contents[2] = null; } } } }Container
package be.hydroen.chimicraft.container; import be.hydroen.chimicraft.tileentity.TileEntityDecomposer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerDecomposer extends Container { private TileEntityDecomposer tileDecomposer; public ContainerDecomposer(TileEntityDecomposer tile, InventoryPlayer inventory) { this.tileDecomposer = tile; this.addSlotToContainer(new Slot(tile, 0, 49, 75)); //lancez votre jeu en debug pour calibrer vos slots this.addSlotToContainer(new Slot(tile, 1, 89, 75)); this.addSlotToContainer(new Slot(tile, 2, 129, 75)); this.addSlotToContainer(new SlotResult(tile, 3, 89, 135)); // Slot créé this.bindPlayerInventory(inventory); } 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, 17 + j * 18, 171 + i * 18)); } } for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(inventory, i, 17 + i * 18, 229)); } } 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.tileDecomposer.getSizeInventory()) { if (!this.mergeItemStack(itemstack1, this.tileDecomposer.getSizeInventory(), this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, this.tileDecomposer.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.tileDecomposer.closeInventory(); } @Override public boolean canInteractWith(EntityPlayer player) { return this.tileDecomposer.isUseableByPlayer(player); } }:::