Bonjour, j’ai tenté de créer un item de type sac avec un gui/container mais je comprend pas trop pourquoi il quand le click droit pour l’ouvrir le jeu crash
| java.lang.NullPointerException: Unexpected error |
| at net.minecraftforge.fml.common.network.NetworkRegistry.getLocalGuiContainer(NetworkRegistry.java:273) |
| at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:110) |
| at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2723) |
| at net.spyman.utils.common.items.ItemBag.onItemRightClick(ItemBag.java:22) |
| at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:176) |
| at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClick(PlayerControllerMP.java:527) |
| at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1629) |
| at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2281) |
| at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2058) |
| at net.minecraft.client.Minecraft.runTick(Minecraft.java:1846) |
| at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1118) |
| at net.minecraft.client.Minecraft.run(Minecraft.java:406) |
| at net.minecraft.client.main.Main.main(Main.java:118) |
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) |
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| at java.lang.reflect.Method.invoke(Method.java:498) |
| at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) |
| at net.minecraft.launchwrapper.Launch.main(Launch.java:28) |
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) |
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| at java.lang.reflect.Method.invoke(Method.java:498) |
| at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) |
| at GradleStart.main(GradleStart.java:26) |
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) |
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| at java.lang.reflect.Method.invoke(Method.java:498) |
| at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) |
| [font=Source Code Propublic class ]ItemBag extends %(#345f99)[Item |
| ]{ |
| public ItemBag() |
| { |
| |
| } |
| |
| %(#278c3c)[*@Override |
| *] public ActionResult<ItemStack> onItemRightClick(ItemStack *itemStack*, World *world*, EntityPlayer *player*, EnumHand *hand*) |
| { |
| *player*.openGui(SpyUtil.INSTANCE, 0, *world*, (int) *player*.posX, (int) *player*.posY, (int) *player*.posZ)%(#aaa9a7)[; |
| ] return new ActionResult(EnumActionResult.PASS, *itemStack*)%(#aaa9a7)[; |
| ] } |
| } |
| [font=Source Code Propublic class ]InventoryItemBag implements %(#345f99)[IInventory |
| ]{ |
| public ItemStack[] inventorySlots%(#aaa9a7)[; |
| ] public int inventoryStackLimit = 64%(#aaa9a7)[; |
| ] %(#8242ff)[ |
| ] public int inventorySize = 54%(#aaa9a7)[; |
| ] |
| public InventoryItemBag(ItemStack *container*, int *size*) |
| { |
| this.inventorySize = *size*%(#aaa9a7)[; |
| ] this.inventorySlots = new ItemStack[*size*]%(#aaa9a7)[; |
| ] |
| if (!*container*.hasTagCompound()) |
| { |
| *container*.setTagCompound(new NBTTagCompound())%(#aaa9a7)[; |
| ] } |
| |
| this.readFromNBT(*container*.getTagCompound())%(#aaa9a7)[; |
| ] } |
| |
| public void readFromNBT(NBTTagCompound *comp*) |
| { |
| NBTTagList nbtlist = *comp*.getTagList("Inventory", Constants.NBT.TAG_COMPOUND)%(#aaa9a7)[; |
| ] |
| for (int %(#666965)_= 0; %(#666965)_< nbtlist.tagCount(); %(#666965)*++) { |
| NBTTagCompound comp1 = nbtlist.getCompoundTagAt(%(#666965)*)%(#aaa9a7)[; |
| ] int slot = comp1.getInteger("Slot")%(#aaa9a7)[; |
| ] this.inventorySlots[slot] = ItemStack.loadItemStackFromNBT(comp1)%(#aaa9a7)[; |
| ] } |
| } |
| |
| public void writeToNBT(NBTTagCompound *comp*) |
| { |
| NBTTagList nbtlist = new NBTTagList()%(#aaa9a7)[; |
| ] |
| for (int %(#666965)_= 0; %(#666965)_< this.inventorySize; %(#666965)*++) |
| { |
| if (this.inventorySlots[%(#666965)*] != null) |
| { |
| NBTTagCompound comp1 = new NBTTagCompound()%(#aaa9a7)[; |
| ] comp1.setInteger("Slot", %(#666965)*)%(#aaa9a7)[; |
| ] this.inventorySlots[%(#666965)*].writeToNBT(comp1)%(#aaa9a7)[; |
| ] nbtlist.appendTag(comp1)%(#aaa9a7)[; |
| ] } |
| } |
| *comp*.setTag("Inventory", nbtlist)%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Override |
| *] public int getSizeInventory() |
| { |
| return this.inventorySize%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Nullable |
| *]%(#278c3c)[* @Override |
| *] public ItemStack getStackInSlot(int *index*) |
| { |
| return this.inventorySlots[*index*]%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Nullable |
| *]%(#278c3c)[* @Override |
| *] public ItemStack decrStackSize(int *index*, int *count*) |
| { |
| return null%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Nullable |
| *]%(#278c3c)[* @Override |
| *] public ItemStack removeStackFromSlot(int *index*) |
| { |
| return null%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Override |
| *] public void setInventorySlotContents(int *index*, *@Nullable *ItemStack *stack*) |
| { |
| |
| } |
| |
| %(#278c3c)[*@Override |
| *] public int getInventoryStackLimit() |
| { |
| return this.inventoryStackLimit%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Override |
| *] public void markDirty() |
| { |
| |
| } |
| |
| %(#278c3c)[*@Override |
| *] public boolean isUseableByPlayer(EntityPlayer *player*) |
| { |
| return true%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Override |
| *] public void openInventory(EntityPlayer *player*) |
| { |
| |
| } |
| |
| %(#278c3c)[*@Override |
| *] public void closeInventory(EntityPlayer *player*) |
| { |
| |
| } |
| |
| %(#278c3c)[*@Override |
| *] public boolean isItemValidForSlot(int *index*, ItemStack *stack*) |
| { |
| return !(*stack*.getItem() instanceof ItemBag)%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Override |
| *] public int getField(int *id*) |
| { |
| return 0%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Override |
| *] public void setField(int *id*, int *value*) |
| { |
| |
| } |
| |
| %(#278c3c)[*@Override |
| *] public int getFieldCount() |
| { |
| return 0%(#aaa9a7)[; |
| ] } |
| |
| %(#278c3c)[*@Override |
| *] public void %(#afb8c5)____ |