Items fantômes dans une GUI
-
Bonjour à tous.
J’ai le preoblème suivant : j’ai un container où un block externe va récupérer des objets dedans. Cependant, lorsque je viens de placer un itemstack manuellement dedans, je dois rouvrir et refermer l’interfacer pour que ça s’affiche correctement, par contre après pour les autres items tout va bien. Dans le côté technique ça fonctionne, mais l’affichage persiste. Je soupçonne le fait que j’exécute trop de trucs côté client, mais je ne parviens pas à trouver la chose qui pose problème. Voici la classe du container :
package pingo.virtualcraft.common; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; 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.minecraftforge.common.util.Constants; public class TileEntityItemScanner extends TileEntityMultiblock implements IInventory { private ItemStack[] inventory = new ItemStack[27]; private String name = "itemscanner"; public String getName() { return name; } public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); } public Packet getDescriptionPacket() { NBTTagCompound nbttagcompound = new NBTTagCompound(); this.writeToNBT(nbttagcompound); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 3, nbttagcompound); } public void readFromNBT(NBTTagCompound nbttag){ super.readFromNBT(nbttag); NBTTagList nbttaglist = nbttag.getTagList("Items", Constants.NBT.TAG_COMPOUND); this.inventory = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot"); if (j >= 0 && j < this.inventory.length) { this.inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } } public void writeToNBT(NBTTagCompound nbttag){ super.writeToNBT(nbttag); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.inventory.length; i++) { if (this.inventory* != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.inventory*.writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } nbttag.setTag("Items", nbttaglist); } @Override public void invalidate() { if (!worldObj.isRemote){ if (this.hasMaster) { if ((TileEntityMultiblock) this.master != null) ((TileEntityMultiblock) this.master).elements = ((TileEntityMultiblock) this.master).newMaster(); } } super.invalidate(); } @Override public int getSizeInventory() { return inventory.length; } @Override public ItemStack getStackInSlot(int slotId) { return inventory[slotId]; } @Override public ItemStack decrStackSize(int slotId, int quantity) { if (this.inventory[slotId] != null) { ItemStack itemstack; if (this.inventory[slotId].stackSize <= quantity) { itemstack = this.inventory[slotId]; this.inventory[slotId] = null; this.checkSorting(); this.iAmLookingForSomething(); this.checkSorting(); this.markDirty(); return itemstack; } else { itemstack = this.inventory[slotId].splitStack(quantity); if (this.inventory[slotId].stackSize == 0) { this.inventory[slotId] = null; } this.checkSorting(); this.iAmLookingForSomething(); this.checkSorting(); this.markDirty(); return itemstack; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int slotId) { if (this.inventory[slotId] != null) { ItemStack itemstack = this.inventory[slotId]; this.inventory[slotId] = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int slotId, ItemStack stack) { this.inventory[slotId] = stack; if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { int redrop = stack.stackSize - this.getInventoryStackLimit(); stack.stackSize = this.getInventoryStackLimit(); } this.checkSorting(); this.iAmLookingForSomething(); this.checkSorting(); this.markDirty(); } @Override public String getInventoryName() { return "container.EUsInjector"; } @Override public boolean hasCustomInventoryName() { return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int slot, ItemStack item) { return true; } public void checkSorting() { boolean areThereItems; for (int k = 0; 26 > k; k++) { areThereItems = false; for (int i = k; 27 > i; i++){ if (this.inventory* != null){ areThereItems = true; } } if (areThereItems) { while (this.inventory[k] == null){ for (int i = k; 26 > i; i++){ this.inventory* = this.inventory[i+1]; this.inventory[i+1] = null; } } } } } public void iAmLookingForSomething() { System.out.println("iAmLookingForSomething"); if (this.hasMaster && (!worldObj.isRemote) && this.inventory[0] != null) { this.inventory[0] = ((TileEntityMultiblockControler) this.master).giveStack(this.inventory[0]); checkSorting(); this.markDirty(); } } }
Pouvez-vous m’aider ?
Merci d’avance !
-
Un petit thumbs up ^^
Merci d’avance.