Problème GUI
-
La vitesse de craft c’est la variable workingTimeNeeded dans ton TE et pour la barre de progression c’est a peu preès ça :
if(this.tileAlloyer.isBurning()) { /* * this.drawTexturedModalRect(x, y, u, v, width, height) * * x: correspond à la coordonnée x du gui (in-game) où s'affichera la texture de la barre de progression. * y: correspond à la coordonnée y du gui (in-game) où s'affichera la texture de la barre de progression. * u: correspond à la position x de votre barre de progression sur votre texture (dans les ressources, l'image .png). * v: correspond à la position y de votre barre de progression sur votre texture (dans les ressources, l'image .png). * width: correspond à la largeur du morceau de texture que vous voulez afficher. * height: correspond à la hauteur du morceau de texture que vous voulez afficher. */ int i = tileAlloyer.getCookProgress() * 41 / 24; //Fix parce que ya pas les bonne valeurs dans ton TE this.drawTexturedModalRect(k + 80, l + 35, 176, 14, i, 24); } -
Mais pourquoi la variable workingTimeNeeded ne change pas le vitesse craft
-
Si ça ne change pas la durée de craft c’est sûrement parce que tu ne repose pas un bloc pour tester, tu utilise le bloc déjà posé contenant l’ancienne valeur de workingTimeNeeded, essai en reposant un bloc
-
enfin workingTimeNeeded a fait effet, mais cette maudite progress bar est toujours basé sur les craft terminés et pas ceux en cour
-
C’est à dire les craft terminés ? Dans ton TE tu as ça ?
@SideOnly(Side.CLIENT) public int getCookProgress() { return this.workingTime * 24 / this.workingTimeNeeded; }Et dans ton gui :
if(this.tileAlloyer.isBurning()) { int i = tileAlloyer.getCookProgress(); this.drawTexturedModalRect(k + 80, l + 35, 176, 14, i, 24); } -
Oui biensur
-
“int i = this.tileAlloyer.getCookProgress() * 41 / 24;”
Retire le “* 41 / 24”
-
Ton container :
public class ContainerAlloyer extends Container { private TileEntityAlloyer tileAlloyer; private int workingTime; private int workingTimeNeeded; public ContainerAlloyer(TileEntityAlloyer tile, InventoryPlayer inventory) { this.tileAlloyer = tile; this.addSlotToContainer(new Slot((IInventory)tile, 0, 43, 17));//dust 1 this.addSlotToContainer(new Slot((IInventory)tile, 1, 69, 17));//dust 2 this.addSlotToContainer(new Slot((IInventory)tile, 2, 56, 53));//coal this.addSlotToContainer(new AlloyerSlotResult(tile, 3, 116, 35));//result this.bindPlayerInventory(inventory); } @Override public boolean canInteractWith(EntityPlayer player) { return this.tileAlloyer.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.tileAlloyer.getSizeInventory()) { if (!this.mergeItemStack(itemstack1, this.tileAlloyer.getSizeInventory(), this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, this.tileAlloyer.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.tileAlloyer.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.tileAlloyer.workingTime) { icrafting.sendProgressBarUpdate(this, 0, this.tileAlloyer.workingTime); } if(this.workingTimeNeeded != this.tileAlloyer.workingTimeNeeded) { icrafting.sendProgressBarUpdate(this, 1, this.tileAlloyer.workingTimeNeeded); } } this.workingTime = this.tileAlloyer.workingTime; this.workingTimeNeeded = this.tileAlloyer.workingTimeNeeded; } @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int value) { if(id == 0) { this.tileAlloyer.workingTime = value; } if(id == 1) { this.tileAlloyer.workingTimeNeeded = value; } } }Et tu dois bien sûr passer en public les 2 variables de durée dans ton TE
-
Toujours pas

-
Merci !!! ça marche

Mais comment je peut faire le combustible maintenant ? j’ai essayé pas mal de choses sans resusltat -
Tu veux faire quoi comme système ? Un combustible spécifique à chaque recette ? Une liste de combustibles utilisables pour faire cuire tes recettes ? Utiliser les combustibles de minecraft ? Une liste de combustibles spécifique à chaque recette ?
-
Tu dois faire deux variables : une du temps total de cuisson et une du temps actuel (burnTime), tu fais une fonction qui return le burnTime en fonction de l’item qui est appelée si le slots n’est pas null et si le burnTime = 0 et tu décrémente le burnTime tous les ticks.
Et bien sur dans canSmelt(), tu rajoute if(this.burnTime <= 0) return false;Pour la fonction qui return le burnTime en fonction du l’item, je te conseille de prendre celle du four.
-
Pour les combustible ceux de minecraft suffiront.
Et pour l’animation des flammes ?
Machine utilise 3 (et un quatrième qui est le result) slots pour le craft donc si le prend mon troisieme slot pour le charbon il faut que je retire un slots du craftMon craft est basé sur 3 items et non 2, comment je modifie ça ?
-
Pour les slots, tu dois en avoir 4, 2 pour les inputs, 1 pour l’output et 1 pour le carburant :
Recipes :
public class AlloyerRecipes { private static final AlloyerRecipes smeltingBase = new AlloyerRecipes(); private Map <itemstack[], itemstack="">smeltingList = new HashMap<itemstack[], itemstack="">(); public AlloyerRecipes() { this.addRecipe(MechanicalCraft.copperDust, MechanicalCraft.tinDust, new ItemStack(MechanicalCraft.bronzeIngot, 2, 0)); this.addRecipe(MechanicalCraft.tinDust, MechanicalCraft.copperDust, new ItemStack(MechanicalCraft.bronzeIngot, 2, 0)); } public void addRecipe(ItemStack input1, ItemStack input2, ItemStack output1) { ItemStack[] stackList = new ItemStack[] {input1, input2}; this.smeltingList.put(stackList, output1); } public void addRecipe(Item input1, Item input2 ,ItemStack output1) { this.addRecipe(new ItemStack(input1), new ItemStack(input2), output1); } public ItemStack getSmeltingResult(ItemStack[] stack) { Iterator<entry<itemstack[], itemstack="">> iterator = this.smeltingList.entrySet().iterator(); Entry <itemstack[], itemstack="">entry; do { if(!iterator.hasNext()) { return null; } entry = (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; for(int i = 0; i < 2; i++) { if(stackList*.getItem() == stackList2*.getItem()) { isSame = true; } else { return false; } } return isSame; } public Map <itemstack[], itemstack="">getSmeltingList() { return this.smeltingList; } public static AlloyerRecipes smelting() { return smeltingBase; } }Pour les flammes, si tu parles des particules -> regarde le code du four de minecraft | si tu parles de la texture dans le GUI -> il faut faire pareil que pour la barre de progression de la recette</itemstack[],></itemstack[],></itemstack[],></entry<itemstack[],></itemstack[],></itemstack[],>
-
@‘AymericRed’:
Tu dois faire deux variables : une du temps total de cuisson et une du temps actuel (burnTime), tu fais une fonction qui return le burnTime en fonction de l’item qui est appelée si le slots n’est pas null et si le burnTime = 0 et tu décrémente le burnTime tous les ticks.
Et bien sur dans canSmelt(), tu rajoute if(this.burnTime <= 0) return false;Pour la fonction qui return le burnTime en fonction du l’item, je te conseille de prendre celle du four.
D’accord mais j’en fait quoi de la deuxième variable (burnTimeToatal) ?
-
Inspire-toi de ce que j’ai fait ici au pire : http://www.minecraftforgefrance.fr/showthread.php?tid=2716#classetileentity
Mais le principe est de savoir combien de temps le carburant actuel va encore brûler et savoir de savoir combien de temps le carburant actuel permet de brûler :
Exemple :
Charbon -> brûle pendant 500 (au hasard) et il reste 250
Scaling de la texture = 250 * hauteur de la texture / 500
Bois -> brûle pendant 15 et il reste 3
Scaling de la texture = 3 * largeur de la texture / 15Pour savoir si il faut prendre la hauteur ou la largeur il suffit de te demander sur quel axe évolue ta texture ?
Dans le four de minecraft la barre de progression évolue à l’horizontal -> largeur de la texture
Dans le four de minecraft la barre de progression du carburant évolue à la verticale -> hauteur de la textureEnsuite il suffit de récupéré le scaling dans le gui
Scaling sur la largeur -> this.drawTexturedModalRect(x, y, u, v, scaling, hauteur);
Scaling sur la hauteur -> this.drawTexturedModalRect(x, y, u, v, largeur, scaling);Du coup dans ton TE il te faut 2 variable pour le carburant une qui est décrémentée à chaque tick et une autre qui est changé quand
un nouveau carburant est consommé -
Brokenswing a tout résumé, burnTumeTotal sert pour la texture, au moment où tu get le burnTime de l’item, tu affectés à burnTumeTotal la valeur de burnTime
-
Là mon craft ne demarre pas
-
1. Pourquoi “protected static” pour tes variables dans le TE ? Jamais static à part pour certains cas
2. Dans la fonction canSmelt() :
Pourquoi tester si le slot du carburant est vide ? Il faut juste qu’il reste du burnTime
Et pourquoi mettre 3 items pour dans le tableau en paramètre de la fonction getSmeltingResult(ItemStack[] stacks) ? Il faut en mettre 2
3. Enlève la fonction getBurnTime(ItemStack stack)Et je suis encore en train de voir le reste
-
package com.google.SpyMan.Mechanicalcraft.common.BlockAlloyer; 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; import net.minecraft.tileentity.TileEntityFurnace; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TileEntityAlloyer extends TileEntity implements IInventory { private byte direction; public byte getDirection() { return direction; } public void setDirection(byte direction) { this.direction = direction; this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); } private ItemStack[] contents = new ItemStack[4]; protected int workingTime = 0; protected int workingTimeNeeded = 200; protected int burnTime = 0; protected int burnTimeTotal = 0; @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("workingTimeNeeded", (short)this.workingTimeNeeded); } @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.workingTimeNeeded = compound.getShort("workingTimeNeeded"); } public int getSizeInventory() { return this.contents.length; } 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 String getInventoryName() { return "tile.Alloyer"; } 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 void openInventory() {} public void closeInventory() {} 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) { return false; } else { ItemStack itemstack = AlloyerRecipes.smelting().getSmeltingResult(new ItemStack[] {this.contents[0], this.contents[1]}); 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() { System.out.println(burnTime + "/" + burnTimeTotal); if(this.burnTime > 0) { burnTime–; } if(this.canSmelt()) { if(this.burnTime <= 0) { int time = TileEntityFurnace.getItemBurnTime(contents[2]); this.decrStackSize(2, 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; } } public void smeltItem() { if(this.canSmelt()) { ItemStack itemstack = AlloyerRecipes.smelting().getSmeltingResult(new ItemStack[] {this.contents[0], this.contents[1]}); 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); this.decrStackSize(1, 1); } } @SideOnly(Side.CLIENT) public int getCookProgress() { return this.workingTime * 24 / this.workingTimeNeeded; } }