C’est bon, ça marche. Merci de m’avoir aider.
Voici le code :
package fr.kraniax.arrow; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; import fr.kraniax.arrow.item.ItemArrow; import fr.kraniax.arrow.proxy.CommonProxy; import net.minecraft.server.MinecraftServer; @Mod(modid = Reference.MODID, name = Reference.MOD_NAME, version = Reference.VERSION) public class Main { @SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.SERVER_PROXY) public static CommonProxy proxy; @Mod.Instance(Reference.MODID) public static Main instance; @EventHandler public void preInit(FMLPreInitializationEvent e) { ItemArrow.init(); ItemArrow.GameRegistry(); proxy.registerRenders(); } @EventHandler public void init(FMLInitializationEvent e) { proxy.registerRenders(); NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); } @EventHandler public void postInit(FMLPostInitializationEvent e) { } } package fr.kraniax.arrow.item; import cpw.mods.fml.common.registry.GameRegistry; import fr.kraniax.arrow.Reference; import fr.kraniax.arrow.item.quiver.ItemQuiver; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; public class ItemArrow { public static Item compoundBow; public static Item quiver; public static void init() { compoundBow = new CompoundBow().setUnlocalizedName("compound_bow").setCreativeTab(CreativeTabs.tabCombat).setTextureName(Reference.MODID + ":compound_bow"); quiver = new ItemQuiver().setUnlocalizedName("quiver").setCreativeTab(CreativeTabs.tabCombat).setTextureName(Reference.MODID + ":quiver"); } public static void GameRegistry() { GameRegistry.registerItem(compoundBow, "compound_bow"); GameRegistry.registerItem(quiver, "quiver"); } } package fr.kraniax.arrow.proxy; import cpw.mods.fml.common.network.IGuiHandler; import fr.kraniax.arrow.item.quiver.ContainerQuiver; import fr.kraniax.arrow.item.quiver.GuiQuiver; import fr.kraniax.arrow.item.quiver.InventoryQuiver; import fr.kraniax.arrow.item.quiver.ItemQuiver; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class CommonProxy implements IGuiHandler{ public void registerRenders() { } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: // The last parameter must be a multiple of 9 (e.g: 9, 18, 27, 54) // Condition to check if the player has the right item in hand if (player.getHeldItem() == null || !(player.getHeldItem().getItem() instanceof ItemQuiver)) return null; return new ContainerQuiver(player.inventory, new InventoryQuiver(player.getHeldItem(), 54)); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: // The last parameter must be a multiple of 9 (e.g: 9, 18, 27, 54) // Condition to check if the player has the right item in hand if (player.getHeldItem() == null || !(player.getHeldItem().getItem() instanceof ItemQuiver)) return null; return new GuiQuiver(player.inventory, new InventoryQuiver(player.getHeldItem(), 54)); } return null; } } package fr.kraniax.arrow.item.quiver; import fr.kraniax.arrow.Reference; 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.minecraftforge.common.util.Constants; public class InventoryQuiver implements IInventory { public ItemStack[] content; public int size; public InventoryQuiver(ItemStack container, int size) { this.size = size; this.content = new ItemStack[size]; if (!container.hasTagCompound()) container.setTagCompound(new NBTTagCompound()); this.readFromNBT(container.getTagCompound()); } /** * This methods reads the content of the NBTTagCompound inside the container * * @param comp the container NBTTagCompound */ public void readFromNBT(NBTTagCompound comp) { NBTTagList nbtlist = comp.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < nbtlist.tagCount(); i++) { NBTTagCompound comp1 = nbtlist.getCompoundTagAt(i); int slot = comp1.getInteger("Slot"); this.content[slot] = ItemStack.loadItemStackFromNBT(comp1); } } /** * This methods saves the content inside the container * * @param comp the NBTTagCompound to write in */ public void writeToNBT(NBTTagCompound comp) { NBTTagList nbtlist = new NBTTagList(); for (int i = 0; i < this.size; i++) { if (this.content[i] != null) { NBTTagCompound comp1 = new NBTTagCompound(); comp1.setInteger("Slot", i); this.content[i].writeToNBT(comp1); nbtlist.appendTag(comp1); } } comp.setTag("Inventory", nbtlist); } @Override public int getSizeInventory() { return this.size; } @Override public ItemStack getStackInSlot(int index) { return this.content[index]; } @Override public ItemStack decrStackSize(int index, int amount) { ItemStack stack = getStackInSlot(index); if (stack != null) { if (stack.stackSize > amount) { stack = stack.splitStack(amount); if (stack.stackSize == 0) this.content[index] = null; } else { this.content[index] = null; } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int index) { ItemStack stack = getStackInSlot(index); if (stack != null) this.content[index] = null; return stack; } @Override public void setInventorySlotContents(int index, ItemStack stack) { this.content[index] = stack; } @Override public String getInventoryName() { return Reference.MODID + ".container.backpack"; } @Override public boolean hasCustomInventoryName() { return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public void markDirty() {} @Override public void openInventory() {} @Override public void closeInventory() {} @Override public boolean isUseableByPlayer(EntityPlayer player) { return true; } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return !(stack.getItem() instanceof ItemQuiver); } } package fr.kraniax.arrow.item.quiver; import org.lwjgl.opengl.GL11; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; public class GuiQuiver extends GuiContainer{ public static final ResourceLocation texture = new ResourceLocation("arrow", "textures/gui/container/generic_54.png"); protected InventoryQuiver inv; protected InventoryPlayer playerInv; public int rows; public GuiQuiver(InventoryPlayer playerInv, InventoryQuiver inv) { super(new ContainerQuiver(playerInv, inv)); this.playerInv = playerInv; this.inv = inv; this.allowUserInput = false; this.rows = inv.getSizeInventory() / 9; this.ySize = 114 + this.rows * 18; } @Override protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { this.fontRendererObj.drawString(I18n.format(this.inv.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 prt, int p_146976_2_, int p_146976_3_) { 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, this.xSize, this.rows * 18 + 17); this.drawTexturedModalRect(k, l + this.rows * 18 + 17, 0, 126, this.xSize, 96); } } package fr.kraniax.arrow.item.quiver; 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.nbt.NBTTagCompound; public class ContainerQuiver extends Container{ public InventoryQuiver invBackpack; public boolean needsUpdate; public int rows; public ContainerQuiver(InventoryPlayer playerInv, InventoryQuiver inv) { this.invBackpack = inv; this.rows = inv.getSizeInventory() / 9; int i = (this.rows - 4) * 18; int j; int k; for (j = 0; j < this.rows; ++j) { for (k = 0; k < 9; ++k) { this.addSlotToContainer(new SlotQuiver(inv, k + j * 9, 8 + k * 18, 18 + j * 18)); } } for (j = 0; j < 3; ++j) { for (k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(playerInv, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i)); } } for (j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(playerInv, j, 8 + j * 18, 161 + i)); } } @Override public boolean canInteractWith(EntityPlayer player) { return true; } public void writeToNBT(ItemStack stack) { if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound()); invBackpack.writeToNBT(stack.getTagCompound()); } @Override public ItemStack transferStackInSlot(EntityPlayer player, int index) { ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); // Prevents backpack-ception (backpack inside backpack) with shift-click if (itemstack.getItem() instanceof ItemQuiver) return null; if (index < this.invBackpack.getSizeInventory()) { if (!this.mergeItemStack(itemstack1, this.invBackpack.getSizeInventory(), this.inventorySlots.size(), true)) return null; } else if (!this.mergeItemStack(itemstack1, 0, this.invBackpack.getSizeInventory(), false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); } else { slot.onSlotChanged(); this.needsUpdate = true; } } return itemstack; } /** * @param buttonPressed left click, right click, wheel click, etc. * @param flag category (e.g.: hotbar keys) */ @Override public ItemStack slotClick(int slotIndex, int buttonPressed, int flag, EntityPlayer player) { // Prevents from removing current backpack if (flag == 2 && buttonPressed == player.inventory.currentItem) return null; if (slotIndex - this.invBackpack.getSizeInventory() - 27 == player.inventory.currentItem) return null; this.needsUpdate = true; return super.slotClick(slotIndex, buttonPressed, flag, player); } @Override public void onContainerClosed(EntityPlayer player) { this.writeToNBT(player.getHeldItem()); super.onContainerClosed(player); } } package fr.kraniax.arrow.item.quiver; import cpw.mods.fml.common.registry.GameRegistry; import fr.kraniax.arrow.Main; import fr.kraniax.arrow.Reference; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ItemQuiver extends Item{ public static final String NAME = "quiver"; public ItemQuiver() { this.maxStackSize = 1; } @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { player.openGui(Main.instance, 0, world, (int) player.posX, (int) player.posY, (int) player.posZ); return stack; } /** * @param stack * ItemStack used * @param held * true if the player is holding this item */ @Override public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean held) {} } package fr.kraniax.arrow.item.quiver; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class SlotQuiver extends Slot{ public SlotQuiver(IInventory inv, int index, int x, int y) { super(inv, index, x, y); } /** * Method used to prevent backpack-ception (backpacks inside backpacks) */ @Override public boolean isItemValid(ItemStack stack) { return !(stack.getItem() instanceof ItemQuiver); } }