Problème GUI
-
Ah non, j’avais pas vu qq chose, le problème vient d’autre part ^^
Essaye de vérifier si les id de tes slots sont bien cnfigurés (dans le Container) et si tu place les items dans les bons slots.
-
J’ai déjà verifié les slots
-
private int workingTimeNeeded = 0;C’est ça qui pose un problème il faut que la valeur soit > 0 et pour + de sécurité met ça comme fonction updateEntity() :
public void updateEntity() { if(this.isBurning() && this.canSmelt()) { ++this.workingTime; //System.out.println(workingTime + "/" + workingTimeNeeded); C'est ici que j'ai vu le problème } if(this.canSmelt() && !this.isBurning()) { this.workingTime = 1; } if(this.canSmelt() && this.workingTime >= this.workingTimeNeeded) //Au lieu de == mettre >= au cas où { this.smeltItem(); this.workingTime = 0; } if(!this.canSmelt()) { this.workingTime = 0; } }EDIT : et change pas ta fonction isBurning(), surtout pas, il faut laisser ```java
return this.workingTime > 0;EDIT 2: En fait pour informer la fonction isBurning n'est pas vraiment utile pour le fonctionnement, elle est + utile pour le rendu quand on veut par exemple rendre une texture différente selon si il est en pleine cuissson ou non (comme le four de minecraft), du coup la fonction updateEntity pourrai ressembler à ça : ```java public void updateEntity() { if(this.canSmelt()) { ++this.workingTime; } if(this.workingTime >= this.workingTimeNeeded) { this.smeltItem(); this.workingTime = 0; } if(!this.canSmelt()) { this.workingTime = 0; } } -
D’accord, mais ma machine est un four avec trois slots en entré (un pour le charbon, et les 2 autres pour le craft) et un dernier pour le résultat du craft
Comment je peut faire un slot pour le combustible ?
et aussi appliqué la texture des flammes et les flèche de progression comme le four de minecraft ? -
Pour la barre de progression : http://www.minecraftforgefrance.fr/showthread.php?tid=2017#bonus
Et pour le slot du carburant (c’est en 1.8 mais c’est l’idée qu’il faut reprendre pas tout le code) : http://www.minecraftforgefrance.fr/showthread.php?tid=2716# -
Comment je peut regler ce tout petit problème ?
-
Tu n’as pas spécifié la largeur et la hauteur de ton gui dans ton constructeur
-
Si pourtant
:::
[font=Consolas**public **]GuiAlloyer(TileEntityAlloyer tile, InventoryPlayer inventory)
{
super(**new **ContainerAlloyer(tile, inventory))%(#aaa9a7)[;
] this.**tileAlloyer **= tile%(#aaa9a7)[;
] this.**playerInv **= inventory%(#aaa9a7)[;
] this.**allowUserInput **= false%(#aaa9a7)[;
] this.**ySize **= 256%(#aaa9a7)[;
] this.**xSize **= 256%(#aaa9a7)[;
]}%(#278c3c)[***@Override
***]**protected void **drawGuiContainerBackgroundLayer(**float **partialRenderTick, **int **x, **int **y)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F)%(#aaa9a7)[;
] this.mc.%(#afb8c5)getTextureManager.%(#afb8c5)bindTexture%(#aaa9a7)[;
] **int ****k **= (this.**width **- this.xSize) / 2%(#aaa9a7)[;
] **int ****l **= (this.**height **- this.ySize) / 2%(#aaa9a7)[;
] this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize)%(#aaa9a7)[;
] this.drawTexturedModalRect(k, l, 176, 14, xSize, ySize)%(#aaa9a7)[;
]}:::
-
this.xSize = 256; Sachant que c’est sur une base 256, tu affiches la texture en entier (même chose pour l’axe Y)
-
Là j’ai carrément plus rien

-
Ça rend pas trop mal :
Gui :package com.google.SpyMan.Mechanicalcraft.common.BlockAlloyer; import org.lwjgl.opengl.GL11; import com.google.SpyMan.Mechanicalcraft.common.MechanicalCraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.util.ResourceLocation; public class GuiAlloyer extends GuiContainer { private static final ResourceLocation texture = new ResourceLocation(MechanicalCraft.MOD_ID,"textures/gui/container/GuiAlloyer1.png"); private TileEntityAlloyer tileAlloyer; private IInventory playerInv; public GuiAlloyer(TileEntityAlloyer tile, InventoryPlayer inventory) { super(new ContainerAlloyer(tile, inventory)); this.tileAlloyer = tile; this.playerInv = inventory; this.allowUserInput = false; this.ySize = 200; this.xSize = 200; } @Override protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(texture); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, 175, 200); 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 = this.tileAlloyer.getCookProgress(); this.drawTexturedModalRect(k + 47, l + 46, 0, 2, 100, i); } } protected void drawGuiContainerForegroundLayer(int x, int y) { this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 9, this.ySize - 127, 4210752); } }Container :
package com.google.SpyMan.Mechanicalcraft.common.BlockAlloyer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerAlloyer extends Container { private TileEntityAlloyer tileAlloyer; 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(); } } -
Les valeurs dépendent de ta texture : déjà il faut regarder si ta texture fait du 256x256
-
Merci de votre aide, mais il me reste encore un problème, la flèche de progression de s’affiche pas et comment modifie ton la vitesse de craft ?
-
Euh, c’est normal que workingTimeNeeded soit toujours égal à 0 (cela correspond à un craft instantané), c’est cette valeur qui contrôle la vitesse (en ticks ton si tu met 20 ça fera 1 seconde) et si tu l’augmentes, normalement la flèche s’affichera.
-
ça ne fonctionne pas
c’est toujours instantané -
Je viens de m’apercevoir que la barre de progression s’affiche en fonction du nombre de craft quelle peut faire et pas en fonction du craft en cour
-
Comment ça en fonction du nombre de craft qu’elle peut faire ?
Et attention au double-post ^^
-
le craft se lance mais la progress bar augmente en fonction du nombre de craft terminé mais pas pour le craft en cour
J’ai mit workingTimeNeeded = 200 ça change rien
-
Ah oui c’est bizarre… Je vais regarder où il pourrait avoir une autre erreur
EDIT:
@SideOnly(Side.CLIENT) public int getCookProgress() { return this.workingTime * 41 / this.workingTimeNeeded; }Le 41 est censé être la largeur de ta barre, sauf que sur ta texture, la barre fait 24 pixels, donc mets ça à 24.
Si ça marche pas, la seule autre source possible de l’erreur est la synchro client-serveur.
-
C’est déjà fait depuis longtemps
c’est que tu a pas le dernier src.zip