Bonsoir,
J’ai quelques problème avec mon mod 1.10.
Je vous explique:
J’ai un item panier à linge qui permet de stocker du linge sauf que quand je clique droit pour ouvrir le panier à linge avec l’item mon jeu crash:
java.lang.NullPointerException
at com.CSC.net.GUI.InventoryLinge.<init>(InventoryLinge.java:22) ~[InventoryLinge.class:?]
at com.CSC.net.GUI.GuiHandler.getClientGuiElement(GuiHandler.java:76) ~[GuiHandler.class:?]
at net.minecraftforge.fml.common.network.NetworkRegistry.getLocalGuiContainer(NetworkRegistry.java:273) ~[NetworkRegistry.class:?]
at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:110) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2723) ~[EntityPlayer.class:?]
at com.CSC.net.item.panierlinger.onItemRightClick(panierlinger.java:25) ~[panierlinger.class:?]
at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:176) ~[ItemStack.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClick(PlayerControllerMP.java:527) ~[PlayerControllerMP.class:?]
at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1629) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2281) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2058) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1846) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1118) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:406) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
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_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
[20:01:39] [Client thread/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:649]: –-- Minecraft Crash Report ----
// I just don't know what went wrong :(
Time: 10/12/16 20:01
Description: Unexpected error
InventoryLinge:
package com.CSC.net.GUI;
import com.CSC.net.item.panierlinger;
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.util.text.ITextComponent;
import net.minecraftforge.common.util.Constants;
public class InventoryLinge implements IInventory
{
public ItemStack[] content;[/font]
public int size;
public InventoryLinge(ItemStack container, int size)
{
this.size = size;
this.content = new ItemStack;
if(!container.hasTagCompound()) // crash ici
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* != null)
{
NBTTagCompound comp1 = new NBTTagCompound();
comp1.setInteger("Slot", i);
this.content*.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 removeStackFromSlot(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 int getInventoryStackLimit()
{
return 64;
}
@Override
public void markDirty()
{}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return !(stack.getItem() instanceof panierlinger);
}
@Override
public String getName()
{
// TODO Auto-generated method stub
return "amm" + ".container.backpack";
}
@Override
public boolean hasCustomName()
{
return false;
}
@Override
public ITextComponent getDisplayName()
{
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
// TODO Auto-generated method stub
return false;
}
@Override
public void openInventory(EntityPlayer player)
{
// TODO Auto-generated method stub
}
@Override
public void closeInventory(EntityPlayer player)
{
// TODO Auto-generated method stub
}
@Override
public int getField(int id)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public void setField(int id, int value)
{
// TODO Auto-generated method stub
}
@Override
public int getFieldCount()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public void clear()
{
// TODO Auto-generated method stub
}
}
Aussi avec quelques Container que j’ai modifier mais bon ça crash.
Je vous passe mon ancienne classe (1.8):
%(#000000)[package com.CSC.net.GUI;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.CSC.net.block.TileEntitySecheLinge;
public class ContainerSecheLinge extends Container
{
private TileEntitySecheLinge tile;
private int currentWorkingTime;
private int totalWorkingTime;
private int remainingFuelTime;
public ContainerSecheLinge(TileEntitySecheLinge tile, InventoryPlayer inventory)
{
this.tile = tile;
// INPUTS
this.addSlotToContainer(new Slotlingemouiller(tile, 0, 21, 0));
this.addSlotToContainer(new Slotlingemouiller(tile, 1, 45, 0));
this.addSlotToContainer(new Slotlingemouiller(tile, 2, 69, 0));
this.addSlotToContainer(new Slotlingemouiller(tile, 3, 93, 0));
// FUEL
this.addSlotToContainer(new Slotlingette(tile, 4, 21, 34));
// OUTPUTS
this.addSlotToContainer(new SlotOutput(tile, 5, 149, 0));
this.addSlotToContainer(new SlotOutput(tile, 6, 149, 25));
this.addSlotToContainer(new SlotOutput(tile, 7, 149, 49));
this.addSlotToContainer(new SlotOutput(tile, 8, 149, 74));
this.bindPlayerInventory(inventory);
}
private void bindPlayerInventory(InventoryPlayer inventory)
{
int i;
int j;
for(i = 0; i < 3; ++i)
{
for(j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + 12));
}
}
for(i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142 + 12));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int quantity)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(quantity);
if(slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if(quantity < this.tile.getSizeInventory())
{
if(!this.mergeItemStack(itemstack1, this.tile.getSizeInventory(), this.inventorySlots.size(), true))
{
return null;
}
}
else if(!this.mergeItemStack(itemstack1, 0, this.tile.getSizeInventory(), false))
{
return null;
}
if(itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
}
return itemstack;
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return this.tile.isUseableByPlayer(player);
}
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed(player);
this.tile.closeInventory(player);
}
@Override
public void onCraftGuiOpened(ICrafting crafting)
{
super.onCraftGuiOpened(crafting);
for(int i = 0; i < this.tile.getFieldCount(); i++)
{
crafting.sendProgressBarUpdate(this, i, this.tile.getField(i));
}
crafting.sendAllWindowProperties(this, this.tile);
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for(int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting)this.crafters.get(i);
for(int j = 0; j < this.tile.getFieldCount(); j++)
{
if(this.getField(j) != this.tile.getField(j))
{
icrafting.sendProgressBarUpdate(this, j, this.tile.getField(j));
}
}
}
for(int i = 0; i < this.tile.getFieldCount(); i++)
{
this.setField(i, this.tile.getField(i));
}
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int value)
{
this.tile.setField(id, value);
}
private int getField(int id)
{
switch(id)
{
case 0:
return this.currentWorkingTime;
case 1:
return this.totalWorkingTime;
case 2:
return this.remainingFuelTime;
default:
return 0;
}
}
private void setField(int id, int value)
{
switch(id)
{
case 0:
this.currentWorkingTime = value;
break;
case 1:
this.totalWorkingTime = value;
break;
case 2:
this.remainingFuelTime = value;
}
}
}]
Et ma nouvelle classe:
package com.CSC.net.GUI;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.CSC.net.block.TileEntitySecheLinge;
public class ContainerSecheLinge extends Container
{
private TileEntitySecheLinge tile;
private int currentWorkingTime;
private int totalWorkingTime;
private int remainingFuelTime;
public ContainerSecheLinge(TileEntitySecheLinge tile, InventoryPlayer inventory)
{
this.tile = tile;
// INPUTS
this.addSlotToContainer(new Slotlingemouiller(tile, 0, 21, 0));
this.addSlotToContainer(new Slotlingemouiller(tile, 1, 45, 0));
this.addSlotToContainer(new Slotlingemouiller(tile, 2, 69, 0));
this.addSlotToContainer(new Slotlingemouiller(tile, 3, 93, 0));
// FUEL
this.addSlotToContainer(new Slotlingette(tile, 4, 21, 34));
// OUTPUTS
this.addSlotToContainer(new SlotOutput(tile, 5, 149, 0));
this.addSlotToContainer(new SlotOutput(tile, 6, 149, 25));
this.addSlotToContainer(new SlotOutput(tile, 7, 149, 49));
this.addSlotToContainer(new SlotOutput(tile, 8, 149, 74));
this.bindPlayerInventory(inventory);
}
private void bindPlayerInventory(InventoryPlayer inventory)
{
int i;
int j;
for(i = 0; i < 3; ++i)
{
for(j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + 12));
}
}
for(i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142 + 12));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int quantity)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(quantity);
if(slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if(quantity < this.tile.getSizeInventory())
{
if(!this.mergeItemStack(itemstack1, this.tile.getSizeInventory(), this.inventorySlots.size(), true))
{
return null;
}
}
else if(!this.mergeItemStack(itemstack1, 0, this.tile.getSizeInventory(), false))
{
return null;
}
if(itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
}
return itemstack;
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return this.tile.isUseableByPlayer(player);
}
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed(player);
this.tile.closeInventory(player);
}
// @Override
// public void onCraftGuiOpened(InventoryCrafting crafting)
// {
// super.onCraftGuiOpened(crafting);
// for(int i = 0; i < this.tile.getFieldCount(); i++)
// {
// crafting.sendProgressBarUpdate(this, i, this.tile.getField(i));
// }
// crafting.sendAllWindowProperties(this, this.tile);
// }
public void onCraftMatrixChanged(IInventory inventoryIn)
{
this.detectAndSendChanges();
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for(int i = 0; i < this.listeners.size(); ++i)
{
ItemStack itemstack1 = (ItemStack)this.inventoryItemStacks.get(i);
InventoryCrafting icrafting = (InventoryCrafting)this.listeners.get(i); // prob ici
for(int j = 0; j < this.tile.getFieldCount(); j++)
{
if(this.getField(j) != this.tile.getField(j))
{
((IContainerListener)this.listeners.get(j)).sendSlotContents(this, j, itemstack1);
}
}
}
for(int i = 0; i < this.tile.getFieldCount(); i++)
{
this.setField(i, this.tile.getField(i));
}
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int value)
{
this.tile.setField(id, value);
}
private int getField(int id)
{
switch(id)
{
case 0:
return this.currentWorkingTime;
case 1:
return this.totalWorkingTime;
case 2:
return this.remainingFuelTime;
default:
return 0;
}
}
private void setField(int id, int value)
{
switch(id)
{
case 0:
this.currentWorkingTime = value;
break;
case 1:
this.totalWorkingTime = value;
break;
case 2:
this.remainingFuelTime = value;
}
}
}
Je crois que c’est tout si j’ai d’autres problème je reviens vers vous.</init>