Non résolu Problème de synchro d'inventaire
-
j’ai réussi a mettre mon container sur le joueur grace a Robin mais il ne fonctionne pas très bien
je m’explique :
je clique partout et sa me prend de n’importe quel slot.
Il y a aussi une OOB dans la console quand je clique
mon container :package fr.eno.pyrion.gui.container; import javax.annotation.Nullable; import fr.eno.pyrion.events.EventRandoms; import net.minecraft.client.Minecraft; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ContainerPlayerCustom extends Container { private static final EntityEquipmentSlot[] VALID_EQUIPMENT_SLOTS = new EntityEquipmentSlot[] {EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET}; /** The crafting matrix inventory. */ public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2); public InventoryCraftResult craftResult = new InventoryCraftResult(); /** Determines if inventory manipulation should be handled. */ public boolean isLocalWorld; private static EntityPlayer player = Minecraft.getMinecraft().player; public ContainerPlayerCustom(InventoryPlayer playerInventory, boolean localWorld, EntityPlayer player) { System.out.println("container Custom"); this.isLocalWorld = localWorld; this.player = player; this.addSlotToContainer(new SlotCrafting(player, this.craftMatrix, this.craftResult, 0, 154, 28)); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { System.out.println("slots crafting"); this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 98 + j * 18, 18 + i * 18)); } } for (int k = 0; k < 4; ++k) { System.out.println("slots armor"); final EntityEquipmentSlot entityequipmentslot = VALID_EQUIPMENT_SLOTS[k]; this.addSlotToContainer(new Slot(playerInventory, 36 + (3 - k), 8, 8 + k * 18) { /** * Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 * in the case of armor slots) */ public int getSlotStackLimit() { return 1; } /** * Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace * fuel. */ public boolean isItemValid(ItemStack stack) { return stack.getItem().isValidArmor(stack, entityequipmentslot, player); } /** * Return whether this slot's stack can be taken from this slot. */ public boolean canTakeStack(EntityPlayer playerIn) { ItemStack itemstack = this.getStack(); return !itemstack.isEmpty() && !playerIn.isCreative() && EnchantmentHelper.hasBindingCurse(itemstack) ? false : super.canTakeStack(playerIn); } @Nullable @SideOnly(Side.CLIENT) public String getSlotTexture() { return ItemArmor.EMPTY_SLOT_NAMES[entityequipmentslot.getIndex()]; } }); } for (int k = 0; k < 4; ++k) { System.out.println("slots armor modified"); final EntityEquipmentSlot entityequipmentslot = VALID_EQUIPMENT_SLOTS[k]; this.addSlotToContainer(new Slot(playerInventory, 99 + k, 77, 8 + k * 18) { /** * Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 * in the case of armor slots) */ public int getSlotStackLimit() { return 1; } /** * Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace * fuel. */ public boolean isItemValid(ItemStack stack) { return stack.getItem().isValidArmor(stack, entityequipmentslot, player); } /** * Return whether this slot's stack can be taken from this slot. */ public boolean canTakeStack(EntityPlayer playerIn) { ItemStack itemstack = this.getStack(); return !itemstack.isEmpty() && !playerIn.isCreative() && EnchantmentHelper.hasBindingCurse(itemstack) ? false : super.canTakeStack(playerIn); } @Nullable @SideOnly(Side.CLIENT) public String getSlotTexture() { return ItemArmor.EMPTY_SLOT_NAMES[entityequipmentslot.getIndex()]; } }); } for (int l = 0; l < 3; ++l) { for (int j1 = 0; j1 < 9; ++j1) { System.out.println("slots inventory"); this.addSlotToContainer(new Slot(playerInventory, j1 + (l + 1) * 9, 8 + j1 * 18, 84 + l * 18)); } } for (int i1 = 0; i1 < 9; ++i1) { this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 142)); } this.addSlotToContainer(new Slot(playerInventory, 40, 152, 66) { @Nullable @SideOnly(Side.CLIENT) @Override public String getSlotTexture() { return "minecraft:items/empty_armor_slot_shield"; } }); } /** * Callback for when the crafting matrix is changed. */ @Override public void onCraftMatrixChanged(IInventory inventoryIn) { this.slotChangedCraftingGrid(this.player.world, this.player, this.craftMatrix, this.craftResult); } /** * Called when the container is closed. */ @Override public void onContainerClosed(EntityPlayer playerIn) { super.onContainerClosed(playerIn); this.craftResult.clear(); if (!playerIn.world.isRemote) { this.clearContainer(playerIn, playerIn.world, this.craftMatrix); } System.out.println("Container Closed"); } /** * Determines whether supplied player can use this container */ public boolean canInteractWith(EntityPlayer playerIn) { return true; } /** * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player * inventory and the other inventory(s). */ @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack); if (index == 0) { if (!this.mergeItemStack(itemstack1, 9, 45, true)) { return ItemStack.EMPTY; } slot.onSlotChange(itemstack1, itemstack); } else if (index >= 1 && index < 5) { if (!this.mergeItemStack(itemstack1, 9, 45, false)) { return ItemStack.EMPTY; } } else if (index >= 5 && index < 9) { if (!this.mergeItemStack(itemstack1, 9, 45, false)) { return ItemStack.EMPTY; } } else if (entityequipmentslot.getSlotType() == EntityEquipmentSlot.Type.ARMOR && !((Slot)this.inventorySlots.get(8 - entityequipmentslot.getIndex())).getHasStack()) { int i = 8 - entityequipmentslot.getIndex(); if (!this.mergeItemStack(itemstack1, i, i + 1, false)) { return ItemStack.EMPTY; } } else if (entityequipmentslot == EntityEquipmentSlot.OFFHAND && !((Slot)this.inventorySlots.get(45)).getHasStack()) { if (!this.mergeItemStack(itemstack1, 45, 46, false)) { return ItemStack.EMPTY; } } else if (index >= 9 && index < 36) { if (!this.mergeItemStack(itemstack1, 36, 45, false)) { return ItemStack.EMPTY; } } else if (index >= 36 && index < 45) { if (!this.mergeItemStack(itemstack1, 9, 36, false)) { return ItemStack.EMPTY; } } else if (!this.mergeItemStack(itemstack1, 9, 45, false)) { return ItemStack.EMPTY; } if (itemstack1.isEmpty()) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } if (itemstack1.getCount() == itemstack.getCount()) { return ItemStack.EMPTY; } ItemStack itemstack2 = slot.onTake(playerIn, itemstack1); if (index == 0) { playerIn.dropItem(itemstack2, false); } } return itemstack; } /** * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in * is null for the initial slot that was double-clicked. */ @Override public boolean canMergeSlot(ItemStack stack, Slot slotIn) { return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn); } }
Donc j’aimerai savoir comment je pourrai “connecter” mon container avec l’inventaire vanilla et comment je pourrais ne plus avoir une OOB
-
@Eno_gamer10
Salut,
pourquoi refaire un deuxième sujet pour le même problème? Sinon file nous l’exception en détail avec la stacktrace. -
oups, désolé je croyais l’avoir supprimé , mais maintenant c’est fait !
et voila l’exception :[18:45:37] [main/INFO] [STDOUT]: [fr.eno.pyrion.gui.inventory.GuiInventoryPlayer:initGui:72]: initGui [18:46:14] [Server thread/FATAL] [net.minecraft.server.MinecraftServer]: Error executing task java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 46, Size: 46 at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_211] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_211] at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_211] Caused by: java.lang.IndexOutOfBoundsException: Index: 46, Size: 46 at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_211] at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_211] at net.minecraft.inventory.Container.slotClick(Container.java:283) ~[Container.class:?] at net.minecraft.network.NetHandlerPlayServer.processClickWindow(NetHandlerPlayServer.java:1222) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketClickWindow.processPacket(CPacketClickWindow.java:47) ~[CPacketClickWindow.class:?] at net.minecraft.network.play.client.CPacketClickWindow.processPacket(CPacketClickWindow.java:12) ~[CPacketClickWindow.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_211] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_211] at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?] ... 5 more [18:46:15] [Server thread/FATAL] [net.minecraft.server.MinecraftServer]: Error executing task java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 46, Size: 46 at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_211] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_211] at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_211] Caused by: java.lang.IndexOutOfBoundsException: Index: 46, Size: 46 at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_211] at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_211] at net.minecraft.inventory.Container.slotClick(Container.java:283) ~[Container.class:?] at net.minecraft.network.NetHandlerPlayServer.processClickWindow(NetHandlerPlayServer.java:1222) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketClickWindow.processPacket(CPacketClickWindow.java:47) ~[CPacketClickWindow.class:?] at net.minecraft.network.play.client.CPacketClickWindow.processPacket(CPacketClickWindow.java:12) ~[CPacketClickWindow.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_211] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_211] at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?] ... 5 more [18:46:20] [Server thread/FATAL] [net.minecraft.server.MinecraftServer]: Error executing task java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 46, Size: 46 at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_211] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_211] at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_211] Caused by: java.lang.IndexOutOfBoundsException: Index: 46, Size: 46 at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_211] at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_211] at net.minecraft.inventory.Container.slotClick(Container.java:283) ~[Container.class:?] at net.minecraft.network.NetHandlerPlayServer.processClickWindow(NetHandlerPlayServer.java:1222) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketClickWindow.processPacket(CPacketClickWindow.java:47) ~[CPacketClickWindow.class:?] at net.minecraft.network.play.client.CPacketClickWindow.processPacket(CPacketClickWindow.java:12) ~[CPacketClickWindow.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_211] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_211] at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?] ... 5 more [18:46:37] [main/INFO] [STDOUT]: [fr.eno.pyrion.gui.container.ContainerPlayerCustom:onContainerClosed:144]: Container Closed
-
Bonsoir,
Chaque Slot prend un argument un inventaire et un identifieur. L’inventaire du joueur n’a que 46 emplacements (donc identifieur de 0 à 45) or tu essaies d’accéder à celui ayant l’identifieur 46.
Il faut que tes slots custom soit lié à un deuxième inventaire et non à l’inventaire de base du joueur qui ne peut pas gérer plus de 46 itemstacks.
Et comme ce deuxième inventaire va devoir être lié au joueur, le mieux pour ça est d’utiliser une capatibility. -
et est ce que ça ça marcherait ? :
EntityPlayer player = (EntityPlayer)event.getEntity(); net.minecraft.entity.player.InventoryPlayer inventory = new InventoryPlayer(player); player.inventory = inventory; System.out.println("Inv Modifié !")
dans l’entityConstructingEvent ?
-
Ça ne change rien, tu as toujours l’inventaire du player qui ne gère que 45 slots.
Il te faut un inventaire custom et une capa pour la gestion de l’enregistrement des données.
-
Merci Robin, j’ai vu qu’il avait un tuto sur les capa sur MFF justement ^^
et une derniere chose, comment je peux link mon inventaire a l’inventaire vanilla ?
parce que quand j’ouvre mon inventaire, il faut que je clicke sur les slots ou il y a des items pour qu’il apparaissent -
Alors là aucune idée, désolé
-
Essaie de voir en créant un inventaire qui étend de celui du joueur, mais il me semble que tu vas être limité sur les slots et que tu devras refaire les fonctions des containers (j’en suis plus si sûr), deuxieme choix, c’est de tout recréer et de tout réadapter.
(Ce week end si j’ai le temps de le finir je ferais un tutoriel sur plusieurs façon de le faire)