Résolu Problème avec le Gui & Container [1.7.10]
-
Bonjour à vous,
Je poste ce message afin d’avoir de l’aide sur un problème de Gui et de Container dans mon mod.
Le block que j’ai fait est une forge, j’ai tout fait correctement. J’ai réglé quelque problème sauf que j’ai eu un autre problème qui est apparu est que je n’arrive pas à comprendre. Cela vient de la classe du Gui de la forge et du Container voici les codes pour mieux comprendre :BlockForgeMod
public class BlockForgeMod extends Block { @SideOnly(Side.CLIENT) private IIcon top; @SideOnly(Side.CLIENT) private IIcon front; private static boolean isBurning; private final boolean isBurning2; private final Random random = new Random(); public BlockForgeMod(boolean isActive) { super(Material.rock); isBurning2 = isActive; } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconregister) { this.blockIcon = iconregister.registerIcon(References.MOD_ID + ":forge_side"); this.front = iconregister.registerIcon(this.isBurning2 ? References.MOD_ID + ":forge_active" : References.MOD_ID + ":forge_inactive"); this.top = iconregister.registerIcon(References.MOD_ID + ":forge_top"); } public IIcon getIcon(int side, int meta) { if(side == 1) { return top; }else if(side == 3) { return front; }else { return this.blockIcon; } } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { player.openGui(IrisiumMod.instance, 0, world, x, y, z); return true; } public Item getItemDropped(int par1, Random random, int par3) { return Item.getItemFromBlock(ModBlocks.forge); } public Item getItem(World world , int par2, int par3, int par4) { return Item.getItemFromBlock(ModBlocks.forge); } @SideOnly(Side.CLIENT) public void onBlockAdded(World world, int x, int y, int z) { super.onBlockAdded(world, x, y, z); this.direction(world, x, y, z); } private void direction(World world, int x, int y, int z) { if(!world.isRemote) { Block direction = world.getBlock(x, y, z -1); Block direction1 = world.getBlock(x, y, z +1); Block direction2 = world.getBlock(x -1, y, z); Block direction3 = world.getBlock(x +1, y, z); byte byte0 = 3; if(direction.func_149730_j() && direction.func_149730_j()) { byte0 = 3; } if(direction1.func_149730_j() && direction1.func_149730_j()) { byte0 = 2; } if(direction2.func_149730_j() && direction2.func_149730_j()) { byte0 = 5; } if(direction3.func_149730_j() && direction3.func_149730_j()) { byte0 = 4; } world.setBlockMetadataWithNotify(x, y, z, byte0, 2); } } public void onBlockPlaceBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemstack) { int direction = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if(direction == 0) { world.setBlockMetadataWithNotify(x, y, z, 2, 2); } if(direction == 1) { world.setBlockMetadataWithNotify(x, y, z, 5, 2); } if(direction == 2) { world.setBlockMetadataWithNotify(x, y, z, 3, 2); } if(direction == 3) { world.setBlockMetadataWithNotify(x, y, z, 4, 2); } if(itemstack.hasDisplayName()) { ((TileEntityForge) world.getTileEntity(x, y, z)).func_145951_a(itemstack.getDisplayName()); } } public static void updateBlockState(boolean burning, World world, int x, int y, int z) { int direction = world.getBlockMetadata(x, y, z); TileEntity tileentity = world.getTileEntity(x, y, z); isBurning = true; if(burning) { world.setBlock(x, y, z, ModBlocks.forge_active); }else { world.setBlock(x, y, z, ModBlocks.forge); } isBurning = false; world.setBlockMetadataWithNotify(x, y, z, direction, 2); if(tileentity != null) { tileentity.validate(); world.setTileEntity(x, y, z, tileentity); } } public void breakBlock(World world, int x, int y, int z, Block block, int meta) { if(!isBurning) { TileEntityForge tileentityforge = (TileEntityForge) world.getTileEntity(x, y, z); if(tileentityforge != null) { for(int i = 0; i < tileentityforge.getInventorySize; ++i) { ItemStack itemstack = tileentityforge.getStackInSlot(i); if(itemstack != null) { float f = this.random.nextFloat() * 0.6F + 0.1F; float f1 = this.random.nextFloat() * 0.6F + 0.1F; float f2 = this.random.nextFloat() * 0.6F + 0.1F; while(itemstack.stackSize > 0) { int j = this.random.nextInt(21) + 10; if(j > itemstack.stackSize) { j = itemstack.stackSize; } itemstack.stackSize -= j; EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage())); if(itemstack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); } float f3 = 0.025F; entityitem.motionX = (double) ((float) this.random.nextGaussian() * f3); entityitem.motionY = (double) ((float) this.random.nextGaussian() * f3 + 0.1F); entityitem.motionZ = (double) ((float) this.random.nextGaussian() * f3); world.spawnEntityInWorld(entityitem); } } } world.func_147453_f(x, y, z, block); } } super.breakBlock(world, x, y, z, block, meta); } @SideOnly(Side.CLIENT) public void randomDisplayTick(World world, int x, int y, int z, Random random) { if(this.isBurning2) { int direction = world.getBlockMetadata(x, y, z); float xx = (float) x + 0.5F, yy = (float) y + random.nextFloat() * 6.0F / 16.0F, zz = (float) z + 0.5F, xx2 = random.nextFloat() * 0.3F - 0.2F, zz2 = 0.5F; if (direction == 4) { world.spawnParticle("smoke", (double) (xx - xx2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F); world.spawnParticle("flame", (double) (xx - xx2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F); } else if (direction == 5) { world.spawnParticle("smoke", (double) (xx - xx2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F); world.spawnParticle("flame", (double) (xx - xx2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F); } else if (direction == 3) { world.spawnParticle("smoke", (double) (xx - xx2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F); world.spawnParticle("flame", (double) (xx - xx2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F); } else if (direction == 2) { world.spawnParticle("smoke", (double) (xx - xx2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F); world.spawnParticle("flame", (double) (xx - xx2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F); } } } }
TileEntityForge
public class TileEntityForge extends TileEntity implements ISidedInventory { private static final int[] slotsTop = new int[] { 0 }; private static final int[] slotsBottom = new int[] { 2, 1 }; private static final int[] slotsSides = new int[] { 1 }; private ItemStack[] furnaceItemStacks = new ItemStack[3]; public int furnaceBurnTime; public int currentBurnTime; public int furnaceCookTime; private String furnaceName; public int getInventorySize; public void furnaceName(String string){ this.furnaceName = string; } @Override public int getSizeInventory() { return this.furnaceItemStacks.length; } @Override public ItemStack getStackInSlot(int slot) { return this.furnaceItemStacks[slot]; } @Override public ItemStack decrStackSize(int par1, int par2) { if (this.furnaceItemStacks[par1] != null) { ItemStack itemstack; if (this.furnaceItemStacks[par1].stackSize <= par2) { itemstack = this.furnaceItemStacks[par1]; this.furnaceItemStacks[par1] = null; return itemstack; } else { itemstack = this.furnaceItemStacks[par1].splitStack(par2); if (this.furnaceItemStacks[par1].stackSize == 0) { this.furnaceItemStacks[par1] = null; } return itemstack; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int slot) { if (this.furnaceItemStacks[slot] != null) { ItemStack itemstack = this.furnaceItemStacks[slot]; this.furnaceItemStacks[slot] = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int slot, ItemStack itemstack) { this.furnaceItemStacks[slot] = itemstack; if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) { itemstack.stackSize = this.getInventoryStackLimit(); } } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.furnaceName : "Tut Furnace"; } @Override public boolean hasCustomInventoryName() { return this.furnaceName != null && this.furnaceName.length() > 0; } @Override public int getInventoryStackLimit() { return 64; } public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Items", 10); this.furnaceItemStacks = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < tagList.tagCount(); ++i) { NBTTagCompound tabCompound1 = tagList.getCompoundTagAt(i); byte byte0 = tabCompound1.getByte("Slot"); if (byte0 >= 0 && byte0 < this.furnaceItemStacks.length) { this.furnaceItemStacks[byte0] = ItemStack.loadItemStackFromNBT(tabCompound1); } } this.furnaceBurnTime = tagCompound.getShort("BurnTime"); this.furnaceCookTime = tagCompound.getShort("CookTime"); this.currentBurnTime = getItemBurnTime(this.furnaceItemStacks[1]); if (tagCompound.hasKey("CustomName", 8)) { this.furnaceName = tagCompound.getString("CustomName"); } } public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); tagCompound.setShort("BurnTime", (short) this.furnaceBurnTime); tagCompound.setShort("CookTime", (short) this.furnaceBurnTime); NBTTagList tagList = new NBTTagList(); for (int i = 0; i < this.furnaceItemStacks.length; ++i) { if (this.furnaceItemStacks[i] != null) { NBTTagCompound tagCompound1 = new NBTTagCompound(); tagCompound1.setByte("Slot", (byte) i); this.furnaceItemStacks[i].writeToNBT(tagCompound1); tagList.appendTag(tagCompound1); } } tagCompound.setTag("Items", tagList); if (this.hasCustomInventoryName()) { tagCompound.setString("CustomName", this.furnaceName); } } @SideOnly(Side.CLIENT) public int getCookProgressScaled(int par1) { return this.furnaceCookTime * par1 / 200; } @SideOnly(Side.CLIENT) public int getBurnTimeRemainingScaled(int par1) { if (this.currentBurnTime == 0) { this.currentBurnTime = 200; } return this.furnaceBurnTime * par1 / this.currentBurnTime; } public boolean isBurning() { return this.furnaceBurnTime > 0; } public void updateEntity() { boolean flag = this.furnaceBurnTime > 0; boolean flag1 = false; if (this.furnaceBurnTime > 0) { --this.furnaceBurnTime; } if (!this.worldObj.isRemote) { if (this.furnaceBurnTime == 0 && this.canSmelt()) { this.currentBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]); if (this.furnaceBurnTime > 0) { flag1 = true; if (this.furnaceItemStacks[1] != null) { --this.furnaceItemStacks[1].stackSize; if (this.furnaceItemStacks[1].stackSize == 0) { this.furnaceItemStacks[1] = furnaceItemStacks[1].getItem().getContainerItem(this.furnaceItemStacks[1]); } } } } if (this.isBurning() && this.canSmelt()) { ++this.furnaceCookTime; if (this.furnaceCookTime == 200) { this.furnaceCookTime = 0; this.smeltItem(); flag1 = true; } } else { this.furnaceCookTime = 0; } } if (flag != this.furnaceBurnTime > 0) { flag1 = true; BlockForgeMod.updateBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord); } if (flag1) { this.markDirty(); } } private boolean canSmelt() { if (this.furnaceItemStacks[0] == null) { return false; } else { ItemStack itemstack = ForgeRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]); if (itemstack == null) return false; if (this.furnaceItemStacks[2] == null) return true; if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false; int result = furnaceItemStacks[2].stackSize + itemstack.stackSize; return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize(); } } public void smeltItem() { if (this.canSmelt()) { ItemStack itemstack = ForgeRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]); if (this.furnaceItemStacks[2] == null) { this.furnaceItemStacks[2] = itemstack.copy(); } else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem()) { this.furnaceItemStacks[2].stackSize += itemstack.stackSize; } --this.furnaceItemStacks[0].stackSize; if(this.furnaceItemStacks[0].stackSize >= 0){ this.furnaceItemStacks[0] = null; } } } public static int getItemBurnTime(ItemStack itemstack){ if(itemstack == null){ return 0; }else{ Item item = itemstack.getItem(); if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air){ Block block = Block.getBlockFromItem(item); if(block == ModBlocks.steel_block){ return 200; } if(block.getMaterial() == Material.rock){ return 300; } } if(item == ModItems.steel_helmet) return 1600; if(item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("EMERALD")) return 300; return GameRegistry.getFuelValue(itemstack); } } public static boolean isItemFuel(ItemStack itemstack){ return getItemBurnTime(itemstack) > 0; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int par1, ItemStack itemstack) { return par1 == 2 ? false : (par1 == 1 ? isItemFuel(itemstack) : true); } @Override public int[] getAccessibleSlotsFromSide(int par1) { return par1 == 0 ? slotsBottom : (par1 == 1 ? slotsTop : slotsSides); } @Override public boolean canInsertItem(int par1, ItemStack itemstack, int par3) { return this.isItemValidForSlot(par1, itemstack); } @Override public boolean canExtractItem(int par1, ItemStack itemstack, int par3) { return par3 != 0 || par1 != 1 || itemstack.getItem() == Items.bucket; } public void func_145951_a(String displayName) { } }
ContainerForge
public class ContainerForge extends Container { private TileEntityForge tileFurnace; private int lastCookTime; private int lastBurnTime; private int lastItemBurnTime; public ContainerForge(InventoryPlayer player, TileEntityForge tileEntityFurnace){ this.tileFurnace = tileEntityFurnace; this.addSlotToContainer(new Slot(tileEntityFurnace, 0, 56, 17)); this.addSlotToContainer(new Slot(tileEntityFurnace, 1, 56, 53)); this.addSlotToContainer(new SlotFurnace(player.player, tileEntityFurnace, 2, 116, 35)); int i; for(i = 0; i < 3; ++i){ for(int j = 0; j < 9; ++j){ this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for(i = 0; i < 9; ++i){ this.addSlotToContainer(new Slot(player, i , 8 + i * 18 , 142)); } } public void addCraftingToCrafters(ICrafting craft){ super.addCraftingToCrafters(craft); craft.sendProgressBarUpdate(this, 0, this.tileFurnace.furnaceCookTime); craft.sendProgressBarUpdate(this, 1, this.tileFurnace.furnaceBurnTime); craft.sendProgressBarUpdate(this, 2, this.tileFurnace.currentBurnTime); } public void detectAndSendChanges(){ super.detectAndSendChanges(); for(int i = 0; i < this.crafters.size(); ++i){ ICrafting craft = (ICrafting) this.crafters.get(i); if(this.lastCookTime != this.tileFurnace.furnaceCookTime){ craft.sendProgressBarUpdate(this, 0, this.tileFurnace.furnaceCookTime); } if(this.lastBurnTime != this.tileFurnace.furnaceBurnTime){ craft.sendProgressBarUpdate(this, 1, this.tileFurnace.furnaceBurnTime); } if(this.lastItemBurnTime != this.tileFurnace.currentBurnTime){ craft.sendProgressBarUpdate(this, 2, this.tileFurnace.currentBurnTime); } } this.lastBurnTime = this.tileFurnace.furnaceBurnTime; this.lastCookTime = this.tileFurnace.furnaceCookTime; this.lastItemBurnTime = this.tileFurnace.currentBurnTime; } @SideOnly(Side.CLIENT) public void updateProgressBar(int par1, int par2){ if(par1 == 0){ this.tileFurnace.furnaceCookTime = par2; } if(par1 == 1){ this.tileFurnace.furnaceBurnTime = par2; } if(par1 == 2){ this.tileFurnace.currentBurnTime = par2; } } @Override public boolean canInteractWith(EntityPlayer player) { return this.tileFurnace.isUseableByPlayer(player); } public ItemStack transferStackInSlot(EntityPlayer player, int par2){ ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(par2); if(slot != null && slot.getHasStack()){ ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if(par2 == 2){ if(!this.mergeItemStack(itemstack1, 3, 39, true)){ return null; } slot.onSlotChange(itemstack1, itemstack); }else if(par2 != 1 && par2 != 0){ if(ForgeRecipes.smelting().getSmeltingResult(itemstack1) != null){ if(!this.mergeItemStack(itemstack1, 0, 1, false)){ return null; } }else if(TileEntityForge.isItemFuel(itemstack1)){ if(!this.mergeItemStack(itemstack1, 1, 2, false)){ return null; } }else if(par2 >=3 && par2 < 30){ if(!this.mergeItemStack(itemstack1, 30, 39, false)){ return null; } }else if(par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)){ return null; } }else if(!this.mergeItemStack(itemstack1, 3, 39, false)){ return null; } if(itemstack1.stackSize == 0){ slot.putStack((ItemStack)null); }else{ slot.onSlotChanged(); } if(itemstack1.stackSize == itemstack.stackSize){ return null; } slot.onPickupFromSlot(player, itemstack1); } return itemstack; } }
GuiForge
@SideOnly(Side.CLIENT) public class GuiForge extends GuiContainer { private static final ResourceLocation forgeGuiTextures = new ResourceLocation("textures/gui/forge.png"); private TileEntityForge tileForge; public GuiForge(InventoryPlayer invPlayer, TileEntityForge tile) { super(new ContainerForge(invPlayer, tile)); this.tileForge = tile; } protected void drawGuiContainerForegroundLayer(int par1, int par2){ String string = this.tileForge.hasCustomInventoryName() ? this.tileForge.getInventoryName() : I18n.format(this.tileForge.getInventoryName(), new Object[0]); this.fontRendererObj.drawString(string, this.xSize / 2 - this.fontRendererObj.getStringWidth(string), 6, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 94, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(forgeGuiTextures); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); int i1; if (this.tileForge.isBurning()) { i1 = this.tileForge.getBurnTimeRemainingScaled(12); this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2); } i1 = this.tileForge.getCookProgressScaled(24); this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16); } }
Voici aussi le crash-raport pour vous aidez aussi :
---- Minecraft Crash Report ---- // Daisy, daisy... Time: 02/01/19 12:37 Description: Rendering screen java.lang.NullPointerException: Rendering screen at fr.irisium.irisiummod.gui.GuiForge.drawGuiContainerBackgroundLayer(GuiForge.java:43) at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:93) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1067) at net.minecraft.client.Minecraft.run(Minecraft.java:962) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at fr.irisium.irisiummod.gui.GuiForge.drawGuiContainerBackgroundLayer(GuiForge.java:43) at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:93) -- Screen render details -- Details: Screen name: fr.irisium.irisiummod.gui.GuiForge Mouse location: Scaled: (341, 176). Absolute: (683, 352) Screen size: Scaled: (683, 353). Absolute: (1366, 705). Scale factor of 2 -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['Player101'/15, l='MpServer', x=-487,48, y=5,62, z=744,14]] Chunk stats: MultiplayerChunkCache: 289, 289 Level seed: 0 Level generator: ID 01 - flat, ver 0. Features enabled: false Level generator options: Level spawn location: World: (-488,4,747), Chunk: (at 8,0,11 in -31,46; contains blocks -496,0,736 to -481,255,751), Region: (-1,1; contains chunks -32,32 to -1,63, blocks -512,0,512 to -1,255,1023) Level time: 3139 game time, 3139 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 63 total; [EntitySheep['Sheep'/61184, l='MpServer', x=-530,44, y=4,00, z=801,78], EntitySheep['Sheep'/61185, l='MpServer', x=-528,22, y=4,00, z=796,50], EntitySheep['Sheep'/61186, l='MpServer', x=-529,81, y=4,00, z=796,50], EntitySheep['Sheep'/61187, l='MpServer', x=-537,50, y=4,00, z=795,50], EntitySheep['Sheep'/61188, l='MpServer', x=-537,50, y=4,00, z=793,50], EntitySheep['Sheep'/61189, l='MpServer', x=-534,50, y=4,00, z=791,50], EntitySheep['Sheep'/61190, l='MpServer', x=-534,50, y=4,00, z=788,50], EntitySheep['Sheep'/61194, l='MpServer', x=-409,50, y=4,00, z=732,50], EntitySheep['Sheep'/61199, l='MpServer', x=-408,72, y=4,00, z=719,88], EntitySheep['Sheep'/61200, l='MpServer', x=-409,91, y=4,00, z=719,50], EntitySheep['Sheep'/61082, l='MpServer', x=-428,81, y=4,00, z=824,22], EntitySheep['Sheep'/61084, l='MpServer', x=-431,50, y=4,00, z=823,50], EntitySheep['Sheep'/61085, l='MpServer', x=-430,50, y=4,00, z=821,78], EntityCow['Cow'/61087, l='MpServer', x=-430,69, y=4,00, z=820,50], EntitySheep['Sheep'/61215, l='MpServer', x=-496,13, y=4,00, z=809,25], EntitySheep['Sheep'/61216, l='MpServer', x=-493,75, y=4,00, z=806,44], EntityCow['Cow'/61089, l='MpServer', x=-432,19, y=4,00, z=808,25], EntitySheep['Sheep'/61217, l='MpServer', x=-499,59, y=4,00, z=807,59], EntitySheep['Sheep'/61218, l='MpServer', x=-497,34, y=4,00, z=809,63], EntityCow['Cow'/61219, l='MpServer', x=-496,41, y=4,00, z=805,09], EntityCow['Cow'/61220, l='MpServer', x=-497,28, y=4,00, z=808,41], EntityCow['Cow'/61221, l='MpServer', x=-502,50, y=4,00, z=802,50], EntityCow['Cow'/61222, l='MpServer', x=-499,19, y=4,00, z=801,50], EntityHorse['Horse'/61223, l='MpServer', x=-488,25, y=4,00, z=805,66], EntityHorse['Horse'/61225, l='MpServer', x=-500,81, y=4,00, z=805,38], EntityHorse['Horse'/61226, l='MpServer', x=-490,87, y=4,00, z=809,13], EntityClientPlayerMP['Player101'/15, l='MpServer', x=-487,48, y=5,62, z=744,14], EntitySheep['Sheep'/61275, l='MpServer', x=-553,38, y=4,00, z=701,25], EntitySheep['Sheep'/61276, l='MpServer', x=-554,50, y=4,00, z=698,50], EntitySheep['Sheep'/61277, l='MpServer', x=-556,22, y=4,00, z=689,16], EntitySheep['Sheep'/61278, l='MpServer', x=-543,91, y=4,00, z=704,94], EntityCow['Cow'/61279, l='MpServer', x=-556,22, y=4,00, z=706,50], EntityCow['Cow'/61280, l='MpServer', x=-553,50, y=4,00, z=706,50], EntityCow['Cow'/61281, l='MpServer', x=-547,06, y=4,00, z=702,34], EntityCow['Cow'/61154, l='MpServer', x=-439,66, y=4,00, z=677,94], EntityCow['Cow'/61282, l='MpServer', x=-559,50, y=4,00, z=705,50], EntityCow['Cow'/61155, l='MpServer', x=-443,72, y=4,00, z=674,69], EntityCow['Cow'/61156, l='MpServer', x=-439,97, y=4,00, z=679,69], EntityCow['Cow'/61284, l='MpServer', x=-547,25, y=4,00, z=703,56], EntityCow['Cow'/61157, l='MpServer', x=-443,50, y=4,00, z=681,50], EntitySheep['Sheep'/61158, l='MpServer', x=-444,50, y=4,00, z=678,50], EntityCow['Cow'/61286, l='MpServer', x=-557,81, y=4,00, z=706,50], EntitySheep['Sheep'/61159, l='MpServer', x=-442,50, y=4,00, z=679,50], EntitySheep['Sheep'/61160, l='MpServer', x=-446,50, y=4,00, z=676,50], EntityCow['Cow'/61288, l='MpServer', x=-560,50, y=4,00, z=710,50], EntitySheep['Sheep'/61161, l='MpServer', x=-442,69, y=4,00, z=676,66], EntityCow['Cow'/61162, l='MpServer', x=-438,34, y=4,00, z=680,66], EntityCow['Cow'/61163, l='MpServer', x=-440,94, y=4,00, z=677,19], EntityChicken['Chicken'/61166, l='MpServer', x=-511,09, y=4,00, z=754,69], EntitySheep['Sheep'/61167, l='MpServer', x=-451,22, y=4,00, z=755,78], EntitySheep['Sheep'/61168, l='MpServer', x=-456,22, y=4,00, z=758,22], EntitySheep['Sheep'/61169, l='MpServer', x=-457,50, y=4,00, z=760,78], EntitySheep['Sheep'/61170, l='MpServer', x=-457,81, y=4,00, z=759,50], EntityChicken['Chicken'/61171, l='MpServer', x=-453,50, y=4,00, z=751,50], EntityChicken['Chicken'/61172, l='MpServer', x=-452,50, y=4,00, z=751,50], EntityChicken['Chicken'/61174, l='MpServer', x=-451,59, y=4,00, z=743,38], EntitySheep['Sheep'/61176, l='MpServer', x=-456,84, y=4,00, z=751,81], EntitySheep['Sheep'/61177, l='MpServer', x=-453,50, y=4,00, z=757,50], EntitySheep['Sheep'/61178, l='MpServer', x=-448,50, y=4,00, z=758,50], EntityChicken['Chicken'/61179, l='MpServer', x=-530,50, y=4,00, z=798,50], EntityChicken['Chicken'/61180, l='MpServer', x=-534,41, y=4,00, z=803,44], EntityChicken['Chicken'/61182, l='MpServer', x=-523,50, y=4,00, z=802,50], EntitySheep['Sheep'/61183, l='MpServer', x=-532,50, y=4,00, z=798,50]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566) at net.minecraft.client.Minecraft.run(Minecraft.java:984) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source)
---- Minecraft Crash Report ---- // Everything's going to plan. No, really, that was supposed to happen. Time: 02/01/19 12:37 Description: Ticking memory connection java.lang.NullPointerException: Ticking memory connection at net.minecraft.inventory.Slot.getStack(Slot.java:88) at net.minecraft.inventory.Container.getInventory(Container.java:67) at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53) at fr.irisium.irisiummod.container.ContainerForge.addCraftingToCrafters(ContainerForge.java:43) at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) at fr.irisium.irisiummod.block.BlockForgeMod.onBlockActivated(BlockForgeMod.java:66) at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409) at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.inventory.Slot.getStack(Slot.java:88) at net.minecraft.inventory.Container.getInventory(Container.java:67) at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53) at fr.irisium.irisiummod.container.ContainerForge.addCraftingToCrafters(ContainerForge.java:43) at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) at fr.irisium.irisiummod.block.BlockForgeMod.onBlockActivated(BlockForgeMod.java:66) at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409) at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@6e7d5cd6 Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
Je vous remercie d’avance,
Cordialement, Xemnys -
Bonjou,
Dommage d’avoir coupé les importations, ça rend faux les numéros de ligne du code.
À quoi correspond la ligne 43 de la classe GuiForge.java ? Le NullPointerException est déclenché par cette dernière. -
Bonjour,
Je n’ai pas coupé le code, je n’ai juste pas tout pris le code (les imports et autres) mais la ligne 43 est au faite la ligne 28 pour le Gui
Cordialement, Xemnys
-
@Xemnys a dit dans Problème avec le Gui & Container [1.7.10] :
Je n’ai pas coupé le code, je n’ai juste pas tout pris le code (les imports et autres)
Imprimes ta classe sur une feuille de papier et coupe-là juste après les importations. Tu aura exactement le résultat qu’ici, c’est pour ça que j’ai dit “Dommage d’avoir coupé les importations”.
Cela correspond à ça :
if (this.tileForge.isBurning())
tileForge est donc null, tu peux envoyer le code de ton guihandler ? -
D’accord, voici le code du GuiHandler :
import cpw.mods.fml.common.network.IGuiHandler; import fr.irisium.irisiummod.container.ContainerForge; import fr.irisium.irisiummod.gui.GuiForge; import fr.irisium.irisiummod.tileentity.TileEntityForge; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class GuiHandler implements IGuiHandler { public GuiHandler (){ } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0){ TileEntityForge tileEntityForge = (TileEntityForge) world.getTileEntity(x, y, z); return new ContainerForge(player.inventory, tileEntityForge); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0){ TileEntityForge tileEntityForgeContainer = (TileEntityForge) world.getTileEntity(x, y, z); return new GuiForge(player.inventory, tileEntityForgeContainer); } return null; } }
Merci d’avoir pris du temps pour répondre à mon problème,
Cordialement, Xemnys -
Aucun problème ici, le seul moyen d’avoir un NPE est que
world.getTileEntity(x, y, z)
renvoie null.Et en remontant à la classe de ton bloc, en effet à aucun moment tu n’indiques que ton bloc a un tile entity (il faut implémenter les méthodes
hasTileEntity
etcreateTileEntity
-
Bonsoir,
J’ai fait comme vous me l’avez dit, d’ajouter les méthodes hasTileEntity et createTileEntity dans la classe du block mais c’est toujours les mêmes crash-report.
Mais en regardant le crash-report, j’ai remarquer qu’il y a un soucis dans la ligne du “onBlockActivated” dans la classe BlockForgeMod.Merci d’avoir pris le temps de m’aider,
Cordialement, Xemnys -
Tu as mis quoi dans ces deux fonctions ?
Ton tile entity est bien enregistré ? https://www.minecraftforgefrance.fr/topic/995/ajouter-une-entité-à-votre-bloc-tile-entity -
Voici ce que j’ai mis dans les deux fonctions :
@Override public boolean hasTileEntity(int metadata) { return true; } @Override public TileEntity createTileEntity(World world, int metadata) { if(metadata == 0) { return new TileEntityForge(); } else if(metadata == 1) { return new TileEntityForge(); } else if(metadata == 2) { return new TileEntityForge(); } return null; }
Et oui j’ai bien enregistrer le TileEntity.
-
J’ai fait des modifications dans la ligne “onBlockActivated” voici le code :
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { if (world.isRemote) { return true; } else { TileEntityForge tileentityforge = (TileEntityForge)world.getTileEntity(x, y, z); if (tileentityforge != null) { player.openGui(IrisiumMod.instance, 0, world, x, y, z); } return true; } }
Mais cette fois, quand on fait un clique droit sur le block, rien ne se passe. Pas de crash juste le gui qui ne veut pas s’ouvrir.
Cordialement, Xemnys.
-
Bonsoir,
Petite mise à jour au niveau du block, sur un court temps j’ai réussi à accéder au block mais après avoir cassé le block et l’avoir reposé. Je n’arrive plus à y accéder.
Cordialement, Xemnys.
-
Tu peux mettre directement comme ceci, sans check de metadata :
@Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntityForge(); }
Il y a une erreur dans les logs où quelque chose ?
-
C’est bon tout marche bien, merci beaucoup de ton aide
Cordialement, Xemnys