• Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Erreur connexion joueur "java.lang.IndexOutOfBoundsException" [1.12.2]

    Support pour les moddeurs
    1.12.2
    2
    2
    85
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PasTrik
      PasTrik last edited by PasTrik

      Bonjour à tous,

      J’ai essayé d’ajouter un slot à l’inventaire du joueur en créant un container qui va remplacer celui de base, problème, quand le joueur se connecte, j’ai cette erreur :

      java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 46, Size: 46
      	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_211]
      	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_211]
      	at net.minecraft.util.Util.runTask(Util.java:51) [Util.class:?]
      	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1088) [Minecraft.class:?]
      	at net.minecraft.client.Minecraft.run(Minecraft.java:398) [Minecraft.class:?]
      	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_211]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_211]
      	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_211]
      	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
      	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_211]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_211]
      	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_211]
      	at net.minecraftforge.legacydev.Main.start(Main.java:86) [legacydev-0.2.3.1-fatjar.jar:0.2.3.1+4+372be23]
      	at net.minecraftforge.legacydev.MainClient.main(MainClient.java:29) [legacydev-0.2.3.1-fatjar.jar:0.2.3.1+4+372be23]
      Caused by: java.lang.IndexOutOfBoundsException: Index: 46, Size: 46
      	at java.util.ArrayList.rangeCheck(ArrayList.java:657) ~[?:1.8.0_211]
      	at java.util.ArrayList.get(ArrayList.java:433) ~[?:1.8.0_211]
      	at net.minecraft.inventory.Container.getSlot(Container.java:120) ~[Container.class:?]
      	at net.minecraft.inventory.Container.setAll(Container.java:527) ~[Container.class:?]
      	at net.minecraft.client.network.NetHandlerPlayClient.handleWindowItems(NetHandlerPlayClient.java:1187) ~[NetHandlerPlayClient.class:?]
      	at net.minecraft.network.play.server.SPacketWindowItems.processPacket(SPacketWindowItems.java:59) ~[SPacketWindowItems.class:?]
      	at net.minecraft.network.play.server.SPacketWindowItems.processPacket(SPacketWindowItems.java:13) ~[SPacketWindowItems.class:?]
      	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_211]
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_211]
      	at net.minecraft.util.Util.runTask(Util.java:50) ~[Util.class:?]
      	... 15 more
      

      Voici mon code :

      • ArtefactContainer :
      public class ArtefactContainer extends Container {
      	private static final EntityEquipmentSlot[] VALID_EQUIPMENT_SLOTS = new EntityEquipmentSlot[]{EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET};
      	public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
      	public InventoryCraftResult craftResult = new InventoryCraftResult();
      	public boolean isLocalWorld;
      	private final EntityPlayer player;
      
      	public ArtefactContainer(InventoryPlayer playerInventory, boolean localWorld, EntityPlayer playerIn) {
      
      		this.isLocalWorld = localWorld;
      		this.player = playerIn;
      		this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 154, 28));
      
      		for (int i = 0; i < 2; ++i) {
      			for (int j = 0; j < 2; ++j) {
      				this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 98 + j * 18, 18 + i * 18));
      			}
      		}
      
      		for (int k = 0; k < 4; ++k) {
      			final EntityEquipmentSlot entityequipmentslot = VALID_EQUIPMENT_SLOTS[k];
      			this.addSlotToContainer(new Slot(playerInventory, 36 + (3 - k), 8, 8 + k * 18) {
      				public int getSlotStackLimit() {
      					return 1;
      				}
      
      				public boolean isItemValid(ItemStack stack) {
      					return stack.getItem().isValidArmor(stack, entityequipmentslot, player);
      				}
      
      				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) {
      				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, 80, 62) {
      			@Nullable
      			@SideOnly(Side.CLIENT)
      			public String getSlotTexture() {
      				return "minecraft:items/empty_armor_slot_shield";
      			}
      		});
      
      		this.addSlotToContainer(new Slot(playerInventory, 46, 77, 8));
      
      	}
      
      	public void onCraftMatrixChanged(IInventory inventoryIn) {
      		this.slotChangedCraftingGrid(this.player.world, this.player, this.craftMatrix, this.craftResult);
      	}
      
      	public void onContainerClosed(EntityPlayer playerIn) {
      		super.onContainerClosed(playerIn);
      		this.craftResult.clear();
      
      		if (!playerIn.world.isRemote) {
      			this.clearContainer(playerIn, playerIn.world, this.craftMatrix);
      		}
      	}
      
      	public boolean canInteractWith(EntityPlayer playerIn) {
      		return true;
      	}
      
      	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 < 46) {
      				if (!this.mergeItemStack(itemstack1, 9, 36, 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;
      	}
      
      	public boolean canMergeSlot(ItemStack stack, Slot slotIn) {
      		return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn);
      	}
      }
      
      • CommonEventHandler :
      @Mod.EventBusSubscriber
      public class CommonEventHandler {
      
      	@SubscribeEvent
      	public static void onEntityConnect(EntityJoinWorldEvent e) {
      		if(e.getEntity() instanceof EntityPlayerMP) {
      			EntityPlayerMP p = (EntityPlayerMP) e.getEntity();
      
      			p.inventoryContainer = new ArtefactContainer(p.inventory, !e.getWorld().isRemote, p);
      			p.openContainer = p.inventoryContainer;
      		}
      	}
      
      }
      
      N 1 Reply Last reply Reply Quote 0
      • Moved from Discussion générale by  robin4002 robin4002 
      • N
        Nasen @PasTrik last edited by

        @pastrik
        Sa peut t’aider pour crée ton inventaire custom
        https://github.com/Lemonszz/SingleSlot

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Design by Woryk
        Contact / Mentions Légales

        MINECRAFT FORGE FRANCE © 2018

        Powered by NodeBB