Posted April 8, 20187 yr The container works as intended in other gamemodes. But in spectator mode game crashes as soon as it is opened. Tile entity class: package com.fcelon.enhancedcraft.tileentities; import com.fcelon.enhancedcraft.Main; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntityLockable; import net.minecraft.util.NonNullList; public class TileEntityBookshelf extends TileEntityLockable { public boolean hasBook1; public boolean hasBook2; public boolean hasBook3; public boolean hasBook4; public boolean hasBook5; public boolean hasBook6; private String customName; private NonNullList<ItemStack> BookshelfItemStacks = NonNullList.<ItemStack>withSize(6, ItemStack.EMPTY); @Override public int getSizeInventory() { return BookshelfItemStacks.size(); } @Override public boolean isEmpty() { for (ItemStack itemstack : this.BookshelfItemStacks) { if (!itemstack.isEmpty()) { return false; } } return true; } public int getBookCount() { int i = 0; for (ItemStack itemstack : this.BookshelfItemStacks) { if (!itemstack.isEmpty()) { i++; } } return i; } @Override public ItemStack getStackInSlot(int index) { return index >= 0 && index < this.BookshelfItemStacks.size() ? (ItemStack)this.BookshelfItemStacks.get(index) : ItemStack.EMPTY; } public ItemStack decrStackSize(int index, int count) { return ItemStackHelper.getAndSplit(this.BookshelfItemStacks, index, count); } /** * Removes a stack from the given slot and returns it. */ public ItemStack removeStackFromSlot(int index) { ItemStack stack = ItemStackHelper.getAndRemove(this.BookshelfItemStacks, index); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); return stack; } /** * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). */ public void setInventorySlotContents(int index, ItemStack stack) { if (index >= 0 && index < this.BookshelfItemStacks.size()) { this.BookshelfItemStacks.set(index, stack); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } } @Override public int getInventoryStackLimit() { return 1; } @Override public boolean isUsableByPlayer(EntityPlayer player) { if (this.world.getTileEntity(this.pos) != this) { return false; } else { return player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; } } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { if (stack.getItem() == Items.BOOK || stack.getItem() == Items.ENCHANTED_BOOK || stack.getItem() == Items.WRITABLE_BOOK || stack.getItem() == Items.WRITTEN_BOOK) { return true; } return false; } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { } @Override public int getFieldCount() { return 0; } @Override public void clear() { BookshelfItemStacks.clear(); } @Override public String getName() { return this.hasCustomName() ? this.customName : "modcontainer.bookshelf"; } @Override public boolean hasCustomName() { return this.customName != null && !this.customName.isEmpty(); } @Override public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { // TODO Auto-generated method stub return null; } @Override public String getGuiID() { return Main.MOD_ID + ":bookshelf"; } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); ItemStackHelper.saveAllItems(compound, this.BookshelfItemStacks); if (this.hasCustomName()) { compound.setString("CustomName", this.customName); } return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); ItemStackHelper.loadAllItems(compound, this.BookshelfItemStacks); if (compound.hasKey("CustomName", 8)) { this.customName = compound.getString("CustomName"); } } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { NBTTagCompound compound = pkt.getNbtCompound(); System.out.println("recieving"); readUpdateTag(compound); } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound compound = new NBTTagCompound(); this.writeUpdateTag(compound); System.out.println("sending"); return new SPacketUpdateTileEntity(pos, getBlockMetadata(), compound); } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound compound = super.getUpdateTag(); writeUpdateTag(compound); return compound; } public void readUpdateTag (NBTTagCompound compound) { int j = compound.getInteger("hasBooks"); System.out.println(j); this.hasBook1 = ((j & 1) == 1); this.hasBook2 = (((j >> 1) & 1) == 1); this.hasBook3 = (((j >> 2) & 1) == 1); this.hasBook4 = (((j >> 3) & 1) == 1); this.hasBook5 = (((j >> 4) & 1) == 1); this.hasBook6 = (((j >> 5) & 1) == 1); } public void writeUpdateTag (NBTTagCompound compound) { int j = 0; for (int i = 0; i < this.getSizeInventory(); i++) { if (!this.getStackInSlot(i).isEmpty()) { j += 1 << i; } } System.out.println(j); compound.setInteger("hasBooks", j); } } Container class: ackage com.fcelon.enhancedcraft; import com.fcelon.enhancedcraft.tileentities.TileEntityBookshelf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerBookshelf extends Container{ public TileEntityBookshelf bookshelfInventory; public ContainerBookshelf(IInventory playerInventory, TileEntityBookshelf bookshelfInventory) { this.bookshelfInventory = bookshelfInventory; for (int i = 0; i < bookshelfInventory.getSizeInventory(); i++) { this.addSlotToContainer(new Slot(bookshelfInventory, i, 34 + i * 18, 20) { public boolean isItemValid(net.minecraft.item.ItemStack stack) { return bookshelfInventory.isItemValidForSlot(0, stack); } } ); } for (int l = 0; l < 3; ++l) { for (int k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(playerInventory, k + l * 9 + 9, 8 + k * 18, l * 18 + 51)); } } for (int i1 = 0; i1 < 9; ++i1) { this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 109)); } } 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(); if (index < this.bookshelfInventory.getSizeInventory()) { if (!this.mergeItemStack(itemstack1, this.bookshelfInventory.getSizeInventory(), this.inventorySlots.size(), true)) { return ItemStack.EMPTY; } } else if (!this.mergeItemStack(itemstack1, 0, this.bookshelfInventory.getSizeInventory(), false)) { return ItemStack.EMPTY; } if (itemstack1.isEmpty()) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } } return itemstack; } @Override public boolean canInteractWith(EntityPlayer playerIn) { // TODO Auto-generated method stub return bookshelfInventory.isUsableByPlayer(playerIn); } } Thanks for any help
April 8, 20187 yr Author Sorry, I completely forgot to paste the ctash report Spoiler [12:17:32] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: ---- Minecraft Crash Report ---- // Would you like a cupcake? Time: 4/8/18 12:17 PM Description: Ticking player java.lang.NullPointerException: Ticking player at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:365) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2164) at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:870) at net.minecraft.world.World.updateEntity(World.java:2123) at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:671) at net.minecraft.world.World.updateEntities(World.java:1903) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:642) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:840) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) at java.lang.Thread.run(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace: at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:365) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2164) at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:870) at net.minecraft.world.World.updateEntity(World.java:2123) -- Player being ticked -- Details: Entity Type: null (net.minecraft.entity.player.EntityPlayerMP) Entity ID: 0 Entity Name: Player137 Entity's Exact location: -15.35, 55.06, 19.22 Entity's Block location: World: (-16,55,19), Chunk: (at 0,3,3 in -1,1; contains blocks -16,0,16 to -1,255,31), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511) Entity's Momentum: 0.00, 0.00, 0.00 Entity's Passengers: [] Entity's Vehicle: ~~ERROR~~ NullPointerException: null Stacktrace: at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:671) at net.minecraft.world.World.updateEntities(World.java:1903) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:642) -- Affected level -- Details: Level name: Texture test All players: 1 total; [EntityPlayerMP['Player137'/0, l='Texture test', x=-15.35, y=55.06, z=19.22]] Chunk stats: ServerChunkCache: 625 Drop: 0 Level seed: 383275871841080968 Level generator: ID 01 - flat, ver 0. Features enabled: true Level generator options: 3;minecraft:bedrock,3*minecraft:stone,52*minecraft:sandstone;2; Level spawn location: World: (0,56,0), Chunk: (at 0,3,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 124871 game time, 4836 day time Level dimension: 0 Level storage version: 0x04ABD - Anvil Level weather: Rain time: 44866 (now: false), thunder time: 95389 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true Stacktrace: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:840) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) at java.lang.Thread.run(Unknown Source) -- System Details -- Details: Minecraft Version: 1.12.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_101, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 366889064 bytes (349 MB) / 877658112 bytes (837 MB) up to 1879048192 bytes (1792 MB) JVM Flags: 0 total; IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP 9.42 Powered by Forge 14.23.1.2555 5 mods loaded, 5 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored | State | ID | Version | Source | Signature | |:--------- |:------------- |:------------ |:-------------------------------- |:--------- | | UCHIJAAAA | minecraft | 1.12.2 | minecraft.jar | None | | UCHIJAAAA | mcp | 9.42 | minecraft.jar | None | | UCHIJAAAA | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.1.2555.jar | None | | UCHIJAAAA | forge | 14.23.1.2555 | forgeSrc-1.12.2-14.23.1.2555.jar | None | | UCHIJAAAA | enhancedcraft | Alfa_0.1 | bin | None | Loaded coremods (and transformers): GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Player Count: 1 / 8; [EntityPlayerMP['Player137'/0, l='Texture test', x=-15.35, y=55.06, z=19.22]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.