Nouveau coffre
-
Bonjour à tous,
comme le titre l’indique, je souhaite créer de nouveau coffres avec différentes capacités mais je sais pas comment faire, j’ai suivi le tuto de robin avec les GUI et tout ça, mais il ne se passe rien ^^
ContainerBigChest
package fr.craftesys.craftesys.blocs; 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 ContainerBigChest extends Container { private TileEntityBigChest tileEntity; public ContainerBigChest(InventoryPlayer playerInventory, TileEntityBigChest 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; } }
class TileEntityBigChest
package fr.craftesys.craftesys.blocs; 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.minecraftforge.common.util.Constants; public class TileEntityBigChest extends TileEntity implements IInventory { private ItemStack[] inventory = new ItemStack[72]; private String customName; public void readFromNBT(NBTTagCompound nbttag) { super.readFromNBT(nbttag); NBTTagList nbttaglist = nbttag.getTagList("Items", Constants.NBT.TAG_COMPOUND); 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* != 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); } } @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.markDirty(); return itemstack; } else { itemstack = this.inventory[slotId].splitStack(quantity); if(this.inventory[slotId].stackSize == 0) { this.inventory[slotId] = null; } 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()) { stack.stackSize = this.getInventoryStackLimit(); } this.markDirty(); } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.customName : "container.bigchest"; } @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 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 slotId, ItemStack stack) { return true; } }
class GuiBigChest
package fr.craftesys.craftesys.blocs; 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; import org.lwjgl.opengl.GL11; import fr.craftesys.craftesys.blocs.ContainerBigChest; import fr.craftesys.craftesys.blocs.TileEntityBigChest; public class GuiBigChest extends GuiContainer { public static ResourceLocation texture = new ResourceLocation("craftesys:textures/gui/container/bigChest.png"); private TileEntityBigChest bigChest; private IInventory playerInventory; public GuiBigChest(InventoryPlayer inventory, TileEntityBigChest tileEntity) { super(new ContainerBigChest(inventory, tileEntity)); this.bigChest = tileEntity; this.playerInventory = inventory; this.ySize = 230; } protected void drawGuiContainerForegroundLayer(int par1, int par2) { this.fontRendererObj.drawString(this.playerInventory.hasCustomInventoryName() ? this.playerInventory.getInventoryName() : I18n.format(this.playerInventory.getInventoryName()), 8, 129, 0); this.fontRendererObj.drawString(this.bigChest.hasCustomInventoryName() ? this.bigChest.getInventoryName() : I18n.format(this.bigChest.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); } }
mais pourtant, quand j’ouvre le coffre rien de plus
-
Euhh ta classe bloc ?
-
oups
si je pense pas à faire le plus important, c’est normal que ça marche pas –’
-
d’ailleurs, je vois pas vraiment comment faire le faire le coffre ….
-
@‘sventus’:
d’ailleurs, je vois pas vraiment comment faire le faire le coffre ….
c’est à dire ? Tu bloques sur quoi ?
-
Apparemment sur la classe bloc…
Suffit de créer une classe extends BlockContainer dans les fonctions qui te demande d’ajouter tu return ton tileentity.
Enregistrer ton bloc et ton tileentity et si tu as pas fail quelque part ou si je t’ai pas dis de bêtise ça devrait fonctionner.