Créer un gui et un container sur un bloc (type coffre)
-
Voila:
package com.harrypotter.sosoh.common.gui.container; import com.harrypotter.sosoh.common.ModHarryPotter; import com.harrypotter.sosoh.common.blocks.TileEntityChaudron; 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; import net.minecraft.util.ResourceLocation; public class ContainerChaudron extends Container { private TileEntityChaudron tileEntity; public ContainerChaudron(InventoryPlayer playerInventory, TileEntityChaudron teChaudron) { this.tileEntity = teChaudron; int yP = 21; int yS = 39; this.addSlotToContainer(new Slot(teChaudron, 1, 26, yP)); this.addSlotToContainer(new Slot(teChaudron, 2, 62, yP)); this.addSlotToContainer(new Slot(teChaudron, 3, 98, yP)); this.addSlotToContainer(new Slot(teChaudron, 4, 134, yP)); this.addSlotToContainer(new Slot(teChaudron, 5, 44, yS)); this.addSlotToContainer(new Slot(teChaudron, 6, 80, yS)); this.addSlotToContainer(new Slot(teChaudron, 7, 116, yS)); //Sceau et Fiole this.addSlotToContainer(new Slot(teChaudron, 8, 8, 90)); this.addSlotToContainer(new Slot(teChaudron, 9, 26, 90)); //Potions this.addSlotToContainer(new Slot(teChaudron, 10, 80, 90)); this.bindPlayerInventory(playerInventory); } private void bindPlayerInventory(InventoryPlayer playerInventory) { int i; for(i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 103 + i * 18 + 37)); } } for(i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 161 + 37)); } } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } public ItemStack transferStackInSlot(EntityPlayer player, int slotId){ ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(slotId); if(slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if(slotId < 9) { if(!this.mergeItemStack(itemstack1, 9, this.inventorySlots.size(), true)) { return null; } } else if(!this.mergeItemStack(itemstack1, 0, 9, false)) { return null; } else if(slotId == 10) { if(itemstack1 != null && (itemstack1.getItem() == ModHarryPotter.itemFiole)){ if(!this.mergeItemStack(itemstack1, 0, 1, false)) { return null; } } } if(itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; } public TileEntityChaudron getTile() { return tileEntity; } }Et:
package com.harrypotter.sosoh.common.blocks; import com.harrypotter.sosoh.common.ModHarryPotter; 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; public class TileEntityChaudron extends TileEntity implements IInventory{ private byte direction; private ItemStack[] inventory = new ItemStack[72]; private String customName; @Override public void readFromNBT(NBTTagCompound nbttag) { super.readFromNBT(nbttag); this.direction = nbttag.getByte("Direction"); NBTTagList nbttaglist = nbttag.getTagList("Items", blockMetadata); this.inventory = new ItemStack[this.getSizeInventory()]; if (nbttag.hasKey("CustomName")) { this.customName = nbttag.getString("CustomName"); } 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); nbttag.setByte("Direction", this.direction); 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); if (this.hasCustomInventoryName()) { nbttag.setString("CustomName", this.customName); } } 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()); this.worldObj.markBlockRangeForRenderUpdate(this.xCoord, this.yCoord, this.zCoord, this.xCoord, this.yCoord, this.zCoord); } @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.updateContainingBlockInfo(); return itemstack; } else { itemstack = this.inventory[slotId].splitStack(quantity); if (this.inventory[slotId].stackSize == 0) { this.inventory[slotId] = null; } this.updateContainingBlockInfo(); 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()) { stack.stackSize = this.getInventoryStackLimit(); } this.updateContainingBlockInfo(); } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.customName : "container.chaudron"; } @Override public boolean hasCustomInventoryName() { return this.customName != null && this.customName.length() > 0; } public void setCustomGuiName(String name) { this.customName = name; } @Override public int getInventoryStackLimit() { return 1; } @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 true; } } -
En fait je me demande si c’est pas aussi une question de slot custom. Le four utilise SlotFurnace, tu devrais regarder de ce côté.
-
J’ai adapter mon code, ca marche a moitie: je ne peux plus rien mettre dedans ^^ mon code:
package com.harrypotter.sosoh.common.gui.container; import com.harrypotter.sosoh.common.ModHarryPotter; import com.harrypotter.sosoh.common.blocks.TileEntityChaudron; 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.inventory.SlotFurnace; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; public class ContainerChaudron extends Container { private TileEntityChaudron tileEntity; public ContainerChaudron(InventoryPlayer playerInventory, TileEntityChaudron teChaudron) { this.tileEntity = teChaudron; int yP = 21; int yS = 39; this.addSlotToContainer(new Slot(teChaudron, 1, 26, yP)); this.addSlotToContainer(new Slot(teChaudron, 2, 62, yP)); this.addSlotToContainer(new Slot(teChaudron, 3, 98, yP)); this.addSlotToContainer(new Slot(teChaudron, 4, 134, yP)); this.addSlotToContainer(new Slot(teChaudron, 5, 44, yS)); this.addSlotToContainer(new Slot(teChaudron, 6, 80, yS)); this.addSlotToContainer(new Slot(teChaudron, 7, 116, yS)); //Sceau et Fiole this.addSlotToContainer(new Slot(teChaudron, 8, 8, 90)); this.addSlotToContainer(new SlotFurnace(playerInventory.player, teChaudron, 9, 26, 90)); //Potions this.addSlotToContainer(new Slot(teChaudron, 10, 80, 90)); this.bindPlayerInventory(playerInventory); } private void bindPlayerInventory(InventoryPlayer playerInventory) { int i; for(i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 103 + i * 18 + 37)); } } for(i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 161 + 37)); } } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } public ItemStack transferStackInSlot(EntityPlayer player, int slotId){ ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(slotId); if(slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (slotId == 9) { if(itemstack1 != null && (itemstack1.getItem() == ModHarryPotter.itemFiole)){ if (!this.mergeItemStack(itemstack1, 3, 39, true)) { return null; } } slot.onSlotChange(itemstack1, itemstack); } if(slotId < 9) { if(!this.mergeItemStack(itemstack1, 9, this.inventorySlots.size(), true)) { return null; } } else if(!this.mergeItemStack(itemstack1, 0, 9, false)) { return null; } if(itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; } public TileEntityChaudron getTile() { return tileEntity; } } -
Bizzarement, le gui est en mode double chest, mais le container en mode simple…
Gui:
package diabolicatrix.base.gui; import org.lwjgl.opengl.GL11; import diabolicatrix.base.container.ContainerTestChest; import diabolicatrix.base.tileentity.TileEntityBlockChest; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.util.ResourceLocation; public class GuiTestChest extends GuiContainer { private static final ResourceLocation textures = new ResourceLocation("t4:textures/gui/chesttest.png"); private TileEntityBlockChest tileChest; private IInventory playerInv; public GuiTestChest(TileEntityBlockChest tile, InventoryPlayer inventory) { super(new ContainerTestChest(tile, inventory)); this.tileChest = tile; this.playerInv = inventory; this.allowUserInput = false; this.ySize = 170; } protected void drawGuiContainerForegroundLayer(int x, int y) { this.fontRendererObj.drawString(this.tileChest.hasCustomInventoryName() ? this.tileChest.getInventoryName() : I18n.format(this.tileChest.getInventoryName(), new Object[0]), 8, 6, 4210752); this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName(), new Object[0]), 8, this.ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float partialRenderType, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(textures); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); } }Container:
package diabolicatrix.base.container; import diabolicatrix.base.tileentity.TileEntityBlockChest; 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 ContainerTestChest extends Container { private final TileEntityBlockChest tilechest; public ContainerTestChest(TileEntityBlockChest tile, InventoryPlayer inventory) { this.tilechest = tile; tile.openInventory(); for(int j = 0; j < 3; ++j) { for(int k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(tile, k + j * 9, 8 + k * 18, 18 + j * 18)); } } this.bindPlayerInventory(inventory); } private void bindPlayerInventory(InventoryPlayer inventory) { int j; for (j = 0; j < 3; ++j) { for (int k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(inventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 - 18)); } } for (j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(inventory, j, 8 + j * 18, 161 - 18)); } } public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(p_82846_2_); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (p_82846_2_ < this.tilechest.getSizeInventory()) { if (!this.mergeItemStack(itemstack1, this.tilechest.getSizeInventory(), this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, this.tilechest.getSizeInventory(), false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; } @Override public boolean canInteractWith(EntityPlayer player) { return this.tilechest.isUseableByPlayer(player); } }GuiHandler si jamais:
package diabolicatrix.base.gui; import cpw.mods.fml.common.network.IGuiHandler; import diabolicatrix.base.container.ContainerTestChest; import diabolicatrix.base.tileentity.TileEntityBlockChest; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class GuiHandler 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 TileEntityBlockChest) { return new ContainerTestChest((TileEntityBlockChest)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 TileEntityBlockChest) { return new GuiTestChest((TileEntityBlockChest)tile, player.inventory); } return null; } } -
Tu draw l’image d’un coffre double mais dans le code du container tu n’as que mit 27 slot (3 * 9 les deux boucles for) donc c’est normal que tu obtiens ce résultat.
-
Je ne comprend pas où je draw le double coffre, mon draw est identique à celui du tutoriel.
-
Ici :
@Override protected void drawGuiContainerBackgroundLayer(float partialRenderType, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); // On remet les couleurs à 0 this.mc.getTextureManager().bindTexture(textures); // On indique qu'on utilise la texture int k = (this.width - this.xSize) / 2; // On centre le GUI int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); // Et on le dessine } -
C’est ça le problème, il est identique au tutoriel(vidéo) et dans la vidéo, il est simple…
P.S: Ça fonctionne si je coupe la texture mais pas si la texture est double coffre, pourtant minecraft est supposé le couper lui même, non?
-
Il faut savoir que les tailles que tu mets sont en fonction de la taille de ta texture sur la base 256, donc si ta texture fait 512*512, il faudra diviser par 2.
-
Ça ne marche pas plus en 256 :S
-
Minecraft ne fait rien du tout, la fonction drawTexture est une fonction basique qui utilise le tesselator. Minecraft dessine le GUI du coffre en plusieurs parties.
-
Dans la classe du coffre de base Minecraft il y a deux draw et en effet le code coupe la texture.
Par contre le code que j’ai donné dans le tutoriel en vidéo n’a qu’un draw et ne fait pas cette coupure. Il faut donc une texture qui ne fait que la taille d’un coffre. -
Ah, d’accord merci beaucoup!
-
Salut ! J’ai une erreur sur le .getBlockTileEntity que je n’arrive pas à résoudre :
-
essaies avec getTileEntity ?
-
Dans mon guihandler, il y des erreurs partout :
http://www.noelshack.com/2017-28-3-1499887482-9.png
Auriez-vous une solution ?
-
Oui je t’invite à regarder la partie du GuiHandler du tuto car là ton GuiHandler est pas bon du tout.
EDIT : en fait pas précisé dans le tuto car eclipse le fait tout seul si tu fais bien dans l’ordre mais il faut que la classe implémente IGuiHandler.
-
Ok j’ai modifié ça mais il y a ça comme erreurs :
-
La version 1.7.10 du tutoriel est ici : https://www.minecraftforgefrance.fr/showthread.php?tid=2082
-
Bonjour , de 1 SUPER tuto !
mais le coffre ne s ouvre pas et il n affiche pas la texture pourrais tu m aider @robin4002 ?
mes 4 class:
public class tileNugarCoffre extends TileEntity implements IInventory { private ItemStack[] inventory = new ItemStack[72]; private String customName; public TileEntity tileEntity(World world) { return null; } public void readFromNBT(NBTTagCompound nbttag) { super.readFromNBT(nbttag); NBTTagList nbttaglist = nbttag.getTagList("Items", 0); this.inventory = new ItemStack[this.getSizeInventory()]; if (nbttag.hasKey("CustomName")) { this.customName = nbttag.getString("CustomName"); } for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = 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[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.inventory[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } nbttag.setTag("Items", nbttaglist); if (this.isInvNameLocalized()) { nbttag.setString("CustomName", this.customName); } } @Override public int getSizeInventory() { return inventory.length; } @Override public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument return this.inventory[slotIndex]; } public ItemStack decrStackSize(int slotIndex, int amount) { if (this.inventory[slotIndex] != null) { ItemStack itemstack; if (this.inventory[slotIndex].stackSize <= amount) { itemstack = this.inventory[slotIndex]; this.inventory[slotIndex] = null; this.markDirty(); return itemstack; } else { itemstack = this.inventory[slotIndex].splitStack(amount); if (this.inventory[slotIndex].stackSize == 0) { this.inventory[slotIndex] = null; } this.markDirty(); return itemstack; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int slotIndex) { if (this.inventory[slotIndex] != null) { ItemStack itemstack = this.inventory[slotIndex]; this.inventory[slotIndex] = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int slotIndex, ItemStack stack) { this.inventory[slotIndex] = stack; if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); } this.markDirty(); } @Override public String getInventoryName() { //J'ai décider qu'on ne pouvait pas mettre de nom custom return this.isInvNameLocalized() ? this.customName : "tile.nugarCoffre"; } @Override public boolean hasCustomInventoryName() { return false; } public boolean isInvNameLocalized(){ return this.customName != null && this.customName.length() > 0; } @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; } public void setCustomGuiName(String name) { this.customName = name; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { return true; } }public class NugarCoffre extends BlockContainer { public NugarCoffre(Material material) { super(material); this.setResistance(8.0F); this.setHarvestLevel("axe", 0); //Outil pour casser le bloc, pour le chiffre : 0=bois, 1=pierre, 2=fer, 3=diamant } public static ResourceLocation texture = new ResourceLocation(References.MOD_ID, "textures/chest/NugarChest/NugarChest.png"); @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { return null; } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { FMLNetworkHandler.openGui(player, NugarMod.instance, 1, world, x, y, z); return true; } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { TileEntity te = world.getTileEntity(x, y, z); if(te != null && stack.getItemDamage() == 3 && te instanceof tileNugarCoffre && stack.hasDisplayName()) { ((tileNugarCoffre)te).setCustomGuiName(stack.getDisplayName()); } } public void breakBlock(World world, int x, int y, int z, int side, int metadata) { dropContainerItem(world, x, y, z); super.breakBlock(world, x, y, z, Block.getBlockById(side), metadata); } protected void dropContainerItem(World world, int x, int y, int z) { tileNugarCoffre nugarcoffre = (tileNugarCoffre)world.getTileEntity(x, y, z); if (nugarcoffre != null) { for (int slotId = 0; slotId < nugarcoffre.getSizeInventory(); slotId++) { ItemStack stack = nugarcoffre.getStackInSlot(slotId); if (stack != 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; stack.stackSize > 0; world.spawnEntityInWorld(entityitem)) { int k1 = world.rand.nextInt(21) + 10; if (k1 > stack.stackSize) { k1 = stack.stackSize; } stack.stackSize -= k1; entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(stack.getItem(), k1, stack.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 (stack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy()); } } } } } } }public class GuiNugarCoffre extends GuiContainer{ public static ResourceLocation texture = new ResourceLocation( "textures/gui/container/Chest.png"); private tileNugarCoffre nugarCoffre; private IInventory playerInv; public GuiNugarCoffre(InventoryPlayer inventory, tileNugarCoffre tileEntity) { super(new ContainerNugarCOffre(inventory, tileEntity)); this.nugarCoffre = tileEntity; this.playerInv = inventory; this.ySize = 230; } protected void drawGuiContainerForegroundLayer(int par1, int par2) { this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 10, this.ySize - 98, 4210752); this.fontRendererObj.drawString(this.nugarCoffre.isInvNameLocalized() ? this.nugarCoffre.getInventoryName() : I18n.format(this.nugarCoffre.getInventoryName()), 8, 7, 0); } @Override protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(texture); int x = (this.width - this.xSize) / 2; int y = (this.height - this.ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); } }public class ContainerNugarCOffre extends Container { private tileNugarCoffre tileEntity; public ContainerNugarCOffre(InventoryPlayer playerInventory, tileNugarCoffre teChest) { this.tileEntity = teChest; for(int i = 0; i < 6; i++) { for(int j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(teChest, j + i * 9, 8 + j * 18, 18 + i * 18)); } } this.bindPlayerInventory(playerInventory); } private void bindPlayerInventory(InventoryPlayer playerInventory) { int i; for(i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 103 + i * 18 + 37)); } } for(i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 161 + 37)); } } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } public ItemStack transferStackInSlot(EntityPlayer player, int slotId) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(slotId); if(slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if(slotId < 9) { if(!this.mergeItemStack(itemstack1, 9, this.inventorySlots.size(), true)) { return null; } } else if(!this.mergeItemStack(itemstack1, 0, 9, false)) { return null; } if(itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; } }
