GooberGunter Posted December 17, 2017 Posted December 17, 2017 (edited) I'm making a tile entity with a single slot and I'm getting this crash report whenever I open the inventory after placing the block down. If I place the block down and close the game then open it again and access the inventory, it is fine. I've looked but I can't find anything that would return null after I went through all my code and replaced all the itemstack = null with itemstack = ItemStack.Empty. Log: Spoiler [11:56:38] [Server thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.lang.NullPointerException: The validated object is null at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_131] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_131] at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:796) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_131] Caused by: java.lang.NullPointerException: The validated object is null at org.apache.commons.lang3.Validate.notNull(Validate.java:225) ~[commons-lang3-3.5.jar:3.5] at org.apache.commons.lang3.Validate.notNull(Validate.java:206) ~[commons-lang3-3.5.jar:3.5] at net.minecraft.util.NonNullList.add(NonNullList.java:62) ~[NonNullList.class:?] at java.util.AbstractList.add(Unknown Source) ~[?:1.8.0_131] at net.minecraft.inventory.Container.getInventory(Container.java:75) ~[Container.class:?] at net.minecraft.inventory.Container.addListener(Container.java:61) ~[Container.class:?] at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:100) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2809) ~[EntityPlayer.class:?] at com.GooberGunter.GrandSorcery.common.block.EnchantingNexus.onBlockActivated(EnchantingNexus.java:75) ~[EnchantingNexus.class:?] at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:472) ~[PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:767) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_131] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_131] at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?] ... 5 more [11:56:38] [Server thread/ERROR]: Encountered an unexpected exception net.minecraft.util.ReportedException: Ticking player at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:846) ~[MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) ~[IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_131] Caused by: java.lang.NullPointerException at net.minecraft.item.ItemStack.areItemStacksEqual(ItemStack.java:495) ~[ItemStack.class:?] at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:100) ~[Container.class:?] at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:365) ~[EntityPlayerMP.class:?] at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2164) ~[World.class:?] at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:870) ~[WorldServer.class:?] at net.minecraft.world.World.updateEntity(World.java:2123) ~[World.class:?] at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:671) ~[WorldServer.class:?] at net.minecraft.world.World.updateEntities(World.java:1903) ~[World.class:?] at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:642) ~[WorldServer.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:840) ~[MinecraftServer.class:?] ... 4 more Tile Entity: Spoiler package com.GooberGunter.GrandSorcery.common.block.tileentities; import java.util.ArrayList; import com.GooberGunter.GrandSorcery.common.utils.Util; import net.minecraft.block.Block; import net.minecraft.block.BlockBreakable; 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.ITickable; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class EnchNexTE extends TileEntity implements ITickable, IInventory{ private int[] arcanaStores = {0, 0, 0, 0, 0}; private ItemStack[] inventory; private String enchName; public EnchNexTE() { this.inventory = new ItemStack[this.getSizeInventory()];//stores an itemstack array with this.getSizeInventory, which returns the int below } @Override public void update() { if(!this.world.isRemote) { } } /** * SAVE AND LOAD */ @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setIntArray("arcanaStores", this.arcanaStores); NBTTagList list = new NBTTagList(); for(int i=0; i < this.getSizeInventory(); ++i) { if(this.getStackInSlot(i) != null && this.getStackInSlot(i) != ItemStack.EMPTY) { NBTTagCompound stackTag = new NBTTagCompound(); stackTag.setByte("Slot", (byte) i); this.getStackInSlot(i).writeToNBT(stackTag); list.appendTag(stackTag); } } compound.setTag("Items", list); if(this.hasCustomName()) { compound.setString("CustomName", this.getCustomName()); } return super.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.arcanaStores = compound.getIntArray("arcanaStores"); NBTTagList list = compound.getTagList("Items", 10); for(int i=0; i<this.getSizeInventory();++i) { NBTTagCompound stackTag = list.getCompoundTagAt(i); int slot = stackTag.getByte("Slot") & 255; this.setInventorySlotContents(slot, new ItemStack(stackTag)); } if(compound.hasKey("CustomName", 8)) { this.setName(compound.getString("CustomName")); } } /** * INVENTORY */ @Override public String getName() { return this.hasCustomName() ? this.enchName : "container.enchanted_nexus_te"; } public void setName(String customName) { this.enchName = customName; } public String getCustomName() { return this.enchName; } @Override public boolean hasCustomName() { return this.enchName != null && !this.enchName.equals(""); } @Override public int getSizeInventory() { return 1; } @Override public boolean isEmpty() { return false; } @Override public ItemStack getStackInSlot(int index) { if(index < 0 || index >= this.getSizeInventory()) { return ItemStack.EMPTY; } return this.inventory[index]; } @Override public ItemStack decrStackSize(int index, int count) { //TODO Game crashes when using a hopper to take an Item slot if(this.getStackInSlot(index) != ItemStack.EMPTY || this.getStackInSlot(index) != null) { ItemStack itemstack; if(this.getStackInSlot(index).getCount() <= count) { itemstack = this.getStackInSlot(index); this.markDirty(); return itemstack; } else { itemstack = this.getStackInSlot(index).splitStack(count); if(this.getStackInSlot(index).getCount() <= 0) { this.setInventorySlotContents(index, ItemStack.EMPTY); } else { //this is the change this.setInventorySlotContents(index, this.getStackInSlot(index)); } this.markDirty(); return itemstack; } }//if the stack in the slot exists, initiate an itemstack and set the inventory contents to the stack else { return ItemStack.EMPTY; } } @Override public ItemStack removeStackFromSlot(int index) { return ItemStack.EMPTY; } @Override public void setInventorySlotContents(int index, ItemStack stack) { if (index < 0 || index >= this.getSizeInventory()) return; if (stack != ItemStack.EMPTY && stack.getCount() == 0) stack = ItemStack.EMPTY; this.inventory[index] = stack; this.markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUsableByPlayer(EntityPlayer player) { return this.world.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64; } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } @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() { for (int i = 0; i < this.getSizeInventory(); i++) this.setInventorySlotContents(i, ItemStack.EMPTY); } /** * TILE ENTITY */ } GUI Container: Spoiler package com.GooberGunter.GrandSorcery.client.gui; import com.GooberGunter.GrandSorcery.common.block.tileentities.EnchNexTE; import com.GooberGunter.GrandSorcery.common.utils.Util; 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; /** * Manages Inventory * @author Justin * */ public class EnchNexTECont extends Container{ private EnchNexTE te; public EnchNexTECont(IInventory playerInv, EnchNexTE te) { this.te = te; //Tile Entity, slot 0, Slot ID: 0 for(int y = 0; y < 1; y++) { for(int x = 0; x < 1; x++) { this.addSlotToContainer(new Slot(te, x + y, 78 + x * 18, 34 + y * 18)); } } //player inventory, slots 9-35, slot ids: 1-27 for(int y = 0; y < 3; y++) { for(int x = 0; x < 9; x++) { this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 101 + y * 18)); } } //player action bar, slots 0-8, slot ids: 28-36 for(int x = 0; x < 9; x++) { this.addSlotToContainer(new Slot(playerInv, x, 8 + x*18, 159)); } }//player, tile entity @Override public boolean canInteractWith(EntityPlayer playerIn) { // TODO Auto-generated method stub return this.te.isUsableByPlayer(playerIn); } @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { ItemStack previous = ItemStack.EMPTY; Slot slot = (Slot) this.inventorySlots.get(index); Util.logger.info("slot validity check"); if (slot != null && slot.getHasStack()) { ItemStack current = slot.getStack(); previous = current.copy(); if (index < 1) { // From TE Inventory to Player Inventory if (!this.mergeItemStack(current, 1, 25, true)) { Util.logger.info("te to pi"); return ItemStack.EMPTY; } } else { // From Player Inventory to TE Inventory if (!this.mergeItemStack(current, 0, 1, false)) { Util.logger.info("pi to te"); return ItemStack.EMPTY; } } if (current.getMaxStackSize() == 0) { Util.logger.info("stack is zero"); slot.putStack(ItemStack.EMPTY); } else { Util.logger.info("stack not zero"); slot.onSlotChanged(); } if (current.getCount() == previous.getCount()) { Util.logger.info("current stack is same as previous"); return ItemStack.EMPTY; } slot.onTake(playerIn, current); } Util.logger.info("slot verified"); return previous; } } /** * Things to Note: *each inventory has its own set of slot ids * * * **/ I've gotten pretty good at reading stack traces but I'm stumped here So from what I understand, the block is placed into the work, in which the constructor is run, which creates the slots and sets them to ItemStack.EMPTY based on the the source code. Then the player rightclicks the block which opens the gui (all of this working) and then the game freezes and the game complains about something being null even though nothing was ever set to null in my code. This means that between 1.8 and 1.12.2 a change was made meaning that a stack must be initialized by the modder. Or maybe not considering that if the player placed down a block then closed and reloaded the save to then access the inventory, everything would work just as it is supposed to. This is an error that freezes the game then fixes itself on next boot. I have never in my life seen something like this Edited December 18, 2017 by GooberGunter Quote
GooberGunter Posted December 17, 2017 Author Posted December 17, 2017 (edited) Update: so i added the tileentity#clear method and that fixes it, but all it does is set the tile entities slots to EMPTY which the addSlotToContainer method already does. //Tile Entity, slot 0, Slot ID: 0 for(int y = 0; y < 1; y++) { for(int x = 0; x < 1; x++) { this.addSlotToContainer(new Slot(te, x + y, 78 + x * 18, 34 + y * 18)); this.te.clear(); } } Edited December 17, 2017 by GooberGunter Quote
GooberGunter Posted December 17, 2017 Author Posted December 17, 2017 *sigh* the one thing I didn't check. Thanks, I'll keep a copy present Quote
GooberGunter Posted December 17, 2017 Author Posted December 17, 2017 (edited) So when I switched to the capability a couple of things changed. The display name, which I've put off to the side since its not a big concern right now. And more importantly, the dropInventoryItems function which requires IInventory as a parameter, which i originally had as the tile entity. Is there a method I can use to drop the items in the tile entity when it's broken? Also how would I then create a new slot in the Container without an IInventory? Edited December 17, 2017 by GooberGunter Quote
GooberGunter Posted December 17, 2017 Author Posted December 17, 2017 (edited) Thanks! Edited December 17, 2017 by GooberGunter Quote
GooberGunter Posted December 17, 2017 Author Posted December 17, 2017 (edited) So on the other hand, when creating a slot in the GUI container on the server side, it needs a slot with an IInventory, which I don't have access to since the tile entity implements the new IItemHandler Edited December 17, 2017 by GooberGunter Quote
larsgerrits Posted December 17, 2017 Posted December 17, 2017 Use SlotItemHandler instead. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
GooberGunter Posted December 17, 2017 Author Posted December 17, 2017 Funny. Now I'm back at square 1, same error as the original post Quote
GooberGunter Posted December 18, 2017 Author Posted December 18, 2017 So I got the slot to work but now I have the following problem, I'm trying to figure it out but it's pretty tough Stacktrace: Spoiler [16:05:44] [main/FATAL]: Reported exception thrown! net.minecraft.util.ReportedException: Updating screen events at net.minecraft.client.Minecraft.runTick(Minecraft.java:1897) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] 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_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] Caused by: java.lang.ClassCastException: com.GooberGunter.GrandSorcery.common.block.tileentities.EnchNexTE cannot be cast to net.minecraftforge.items.IItemHandlerModifiable at net.minecraftforge.items.SlotItemHandler.putStack(SlotItemHandler.java:89) ~[SlotItemHandler.class:?] at net.minecraft.inventory.Container.slotClick(Container.java:306) ~[Container.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:610) ~[PlayerControllerMP.class:?] at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:693) ~[GuiContainer.class:?] at net.minecraft.client.gui.inventory.GuiContainer.mouseReleased(GuiContainer.java:649) ~[GuiContainer.class:?] at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:621) ~[GuiScreen.class:?] at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) ~[GuiScreen.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1884) ~[Minecraft.class:?] ... 15 more [16:05:44] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: ---- Minecraft Crash Report ---- // I bet Cylons wouldn't have this problem. Time: 12/17/17 4:05 PM Description: Updating screen events java.lang.ClassCastException: com.GooberGunter.GrandSorcery.common.block.tileentities.EnchNexTE cannot be cast to net.minecraftforge.items.IItemHandlerModifiable at net.minecraftforge.items.SlotItemHandler.putStack(SlotItemHandler.java:89) at net.minecraft.inventory.Container.slotClick(Container.java:306) at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:610) at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:693) at net.minecraft.client.gui.inventory.GuiContainer.mouseReleased(GuiContainer.java:649) at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:621) at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1884) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186) at net.minecraft.client.Minecraft.run(Minecraft.java:441) at net.minecraft.client.main.Main.main(Main.java:118) 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 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.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace: at net.minecraftforge.items.SlotItemHandler.putStack(SlotItemHandler.java:89) at net.minecraft.inventory.Container.slotClick(Container.java:306) at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:610) at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:693) at net.minecraft.client.gui.inventory.GuiContainer.mouseReleased(GuiContainer.java:649) at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:621) at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) -- Affected screen -- Details: Screen name: com.GooberGunter.GrandSorcery.client.gui.EnchNexGUI -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityPlayerSP['Player259'/268, l='MpServer', x=-189.90, y=71.00, z=-266.96]] Chunk stats: MultiplayerChunkCache: 616, 616 Level seed: 0 Level generator: ID 00 - default, ver 1. Features enabled: false Level generator options: Level spawn location: World: (-168,64,-200), Chunk: (at 8,4,8 in -11,-13; contains blocks -176,0,-208 to -161,255,-193), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1) Level time: 63013 game time, 13704 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: true), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 114 total; [EntitySquid['Squid'/55, l='MpServer', x=-245.60, y=62.00, z=-329.58], EntitySquid['Squid'/56, l='MpServer', x=-248.07, y=60.47, z=-319.97], EntitySquid['Squid'/58, l='MpServer', x=-244.87, y=58.75, z=-213.69], EntitySkeleton['Skeleton'/62, l='MpServer', x=-232.49, y=21.00, z=-251.74], EntitySquid['Squid'/63, l='MpServer', x=-235.98, y=62.00, z=-252.60], EntitySquid['Squid'/64, l='MpServer', x=-237.41, y=60.16, z=-246.69], EntitySquid['Squid'/65, l='MpServer', x=-231.40, y=60.00, z=-246.60], EntitySquid['Squid'/66, l='MpServer', x=-240.39, y=62.55, z=-247.88], EntitySquid['Squid'/67, l='MpServer', x=-225.40, y=60.00, z=-240.40], EntityPlayerSP['Player259'/268, l='MpServer', x=-189.90, y=71.00, z=-266.96], EntitySquid['Squid'/68, l='MpServer', x=-230.57, y=56.62, z=-239.20], EntityCreeper['Creeper'/69, l='MpServer', x=-229.32, y=33.00, z=-226.72], EntitySkeleton['Skeleton'/70, l='MpServer', x=-224.51, y=33.00, z=-226.73], EntitySkeleton['Skeleton'/71, l='MpServer', x=-228.52, y=33.00, z=-239.21], EntitySquid['Squid'/72, l='MpServer', x=-232.08, y=56.23, z=-232.25], EntitySquid['Squid'/73, l='MpServer', x=-232.40, y=58.22, z=-232.92], EntitySkeleton['Skeleton'/77, l='MpServer', x=-214.50, y=13.00, z=-264.31], EntityHorse['Horse'/78, l='MpServer', x=-215.11, y=64.00, z=-232.78], EntitySquid['Squid'/80, l='MpServer', x=-206.00, y=62.00, z=-330.60], EntityZombie['Zombie'/81, l='MpServer', x=-201.69, y=32.35, z=-313.83], EntityCreeper['Creeper'/82, l='MpServer', x=-197.50, y=12.00, z=-280.29], EntityCreeper['Creeper'/83, l='MpServer', x=-205.16, y=18.00, z=-274.52], EntitySpider['Spider'/84, l='MpServer', x=-199.78, y=22.00, z=-279.02], EntityItemFrame['entity.ItemFrame.name'/85, l='MpServer', x=-195.03, y=73.50, z=-267.50], EntityZombie['Zombie'/86, l='MpServer', x=-196.63, y=46.00, z=-249.08], EntityBat['Bat'/87, l='MpServer', x=-184.14, y=49.17, z=-259.43], EntityZombie['Zombie'/88, l='MpServer', x=-200.64, y=53.33, z=-222.36], EntityItemFrame['entity.ItemFrame.name'/89, l='MpServer', x=-202.97, y=65.50, z=-222.50], EntityZombie['Zombie'/94, l='MpServer', x=-180.52, y=21.00, z=-278.81], EntitySkeleton['Skeleton'/95, l='MpServer', x=-173.18, y=50.00, z=-276.47], EntityCreeper['Creeper'/96, l='MpServer', x=-177.92, y=47.00, z=-274.51], EntitySkeleton['Skeleton'/97, l='MpServer', x=-177.55, y=47.00, z=-275.46], EntitySkeleton['Skeleton'/98, l='MpServer', x=-180.51, y=53.00, z=-281.27], EntitySkeleton['Skeleton'/99, l='MpServer', x=-176.53, y=47.00, z=-271.86], EntityBat['Bat'/100, l='MpServer', x=-176.25, y=49.10, z=-271.59], EntityZombie['Zombie'/101, l='MpServer', x=-174.51, y=61.17, z=-262.27], EntitySkeleton['Skeleton'/102, l='MpServer', x=-177.54, y=57.00, z=-264.77], EntityItemFrame['entity.ItemFrame.name'/103, l='MpServer', x=-190.50, y=72.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/104, l='MpServer', x=-189.50, y=72.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/105, l='MpServer', x=-188.50, y=72.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/106, l='MpServer', x=-187.50, y=72.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/107, l='MpServer', x=-187.50, y=71.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/108, l='MpServer', x=-188.50, y=71.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/109, l='MpServer', x=-189.50, y=71.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/110, l='MpServer', x=-189.50, y=73.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/111, l='MpServer', x=-188.50, y=73.50, z=-264.03], EntityItemFrame['entity.ItemFrame.name'/112, l='MpServer', x=-187.50, y=73.50, z=-264.03], EntityZombie['Zombie'/113, l='MpServer', x=-186.50, y=21.00, z=-247.27], EntityBat['Bat'/114, l='MpServer', x=-185.14, y=48.10, z=-245.97], EntityBat['Bat'/115, l='MpServer', x=-186.83, y=48.10, z=-249.51], EntityBat['Bat'/116, l='MpServer', x=-180.46, y=50.17, z=-248.69], EntityHorse['Horse'/117, l='MpServer', x=-180.96, y=72.00, z=-222.36], EntityHorse['Horse'/118, l='MpServer', x=-185.58, y=72.00, z=-232.07], EntityRabbit['Rabbit'/119, l='MpServer', x=-176.72, y=74.00, z=-192.51], EntitySquid['Squid'/124, l='MpServer', x=-160.43, y=60.21, z=-305.40], EntitySquid['Squid'/125, l='MpServer', x=-166.90, y=61.97, z=-318.16], EntityCreeper['Creeper'/126, l='MpServer', x=-172.58, y=49.00, z=-277.08], EntitySkeleton['Skeleton'/127, l='MpServer', x=-161.53, y=55.00, z=-287.27], EntitySkeleton['Skeleton'/128, l='MpServer', x=-176.24, y=50.00, z=-277.51], EntityCreeper['Creeper'/129, l='MpServer', x=-166.84, y=44.00, z=-263.52], EntityBat['Bat'/130, l='MpServer', x=-171.58, y=49.10, z=-271.81], EntitySkeleton['Skeleton'/131, l='MpServer', x=-174.21, y=48.00, z=-270.51], EntityBat['Bat'/132, l='MpServer', x=-171.25, y=64.10, z=-261.25], EntityBat['Bat'/133, l='MpServer', x=-170.25, y=51.10, z=-236.25], EntityCreeper['Creeper'/138, l='MpServer', x=-149.50, y=21.00, z=-316.84], EntitySkeleton['Skeleton'/139, l='MpServer', x=-147.54, y=21.00, z=-320.46], EntitySquid['Squid'/140, l='MpServer', x=-160.40, y=59.68, z=-321.35], EntitySquid['Squid'/141, l='MpServer', x=-151.47, y=62.55, z=-321.14], EntityHorse['Horse'/142, l='MpServer', x=-144.06, y=67.00, z=-277.08], EntityZombie['Zombie'/143, l='MpServer', x=-155.27, y=37.00, z=-267.49], EntityHorse['Horse'/144, l='MpServer', x=-153.71, y=62.29, z=-269.39], EntityCreeper['Creeper'/145, l='MpServer', x=-150.56, y=36.00, z=-224.80], EntitySkeleton['Skeleton'/146, l='MpServer', x=-148.46, y=29.00, z=-227.79], EntitySkeleton['Skeleton'/147, l='MpServer', x=-150.31, y=42.00, z=-212.50], EntitySkeleton['Skeleton'/148, l='MpServer', x=-153.16, y=43.00, z=-216.22], EntitySkeleton['Skeleton'/149, l='MpServer', x=-150.49, y=43.00, z=-211.71], EntitySkeleton['Skeleton'/150, l='MpServer', x=-149.23, y=43.00, z=-215.52], EntityCreeper['Creeper'/151, l='MpServer', x=-146.53, y=43.00, z=-203.93], EntityZombie['Zombie'/152, l='MpServer', x=-153.93, y=44.00, z=-204.55], EntityCreeper['Creeper'/153, l='MpServer', x=-145.17, y=43.00, z=-209.45], EntityCreeper['Creeper'/160, l='MpServer', x=-138.97, y=18.00, z=-308.41], EntitySpider['Spider'/161, l='MpServer', x=-131.07, y=51.00, z=-317.00], EntityEnderman['Enderman'/162, l='MpServer', x=-130.53, y=20.00, z=-302.57], EntityZombie['Zombie'/163, l='MpServer', x=-132.55, y=25.00, z=-303.54], EntityHorse['Horse'/164, l='MpServer', x=-143.78, y=66.00, z=-297.91], EntityHorse['Horse'/165, l='MpServer', x=-134.00, y=72.00, z=-274.70], EntityCreeper['Creeper'/166, l='MpServer', x=-130.27, y=34.00, z=-225.53], EntitySkeleton['Skeleton'/167, l='MpServer', x=-136.97, y=21.00, z=-210.22], EntityCreeper['Creeper'/168, l='MpServer', x=-141.50, y=21.00, z=-214.50], EntityCreeper['Creeper'/169, l='MpServer', x=-142.50, y=21.00, z=-219.50], EntityCreeper['Creeper'/170, l='MpServer', x=-140.17, y=22.00, z=-212.47], EntityZombie['Zombie'/171, l='MpServer', x=-132.93, y=54.00, z=-221.50], EntitySheep['Sheep'/172, l='MpServer', x=-132.45, y=72.00, z=-213.23], EntityCreeper['Creeper'/178, l='MpServer', x=-116.50, y=54.00, z=-322.50], EntitySpider['Spider'/180, l='MpServer', x=-124.35, y=54.00, z=-317.08], EntityZombie['Zombie'/181, l='MpServer', x=-123.82, y=53.00, z=-318.31], EntitySkeleton['Skeleton'/182, l='MpServer', x=-114.50, y=50.00, z=-297.50], EntityCreeper['Creeper'/183, l='MpServer', x=-116.54, y=48.00, z=-289.83], EntityBat['Bat'/184, l='MpServer', x=-115.25, y=60.10, z=-285.48], EntityHorse['Horse'/185, l='MpServer', x=-120.06, y=71.00, z=-274.40], EntitySkeleton['Skeleton'/186, l='MpServer', x=-114.22, y=24.00, z=-270.50], EntityCreeper['Creeper'/187, l='MpServer', x=-119.07, y=25.00, z=-271.65], EntityHorse['Horse'/188, l='MpServer', x=-118.28, y=88.00, z=-256.79], EntityHorse['Horse'/189, l='MpServer', x=-113.01, y=87.00, z=-248.77], EntityCreeper['Creeper'/190, l='MpServer', x=-126.49, y=53.00, z=-226.16], EntityCow['Cow'/191, l='MpServer', x=-126.46, y=90.00, z=-236.22], EntityHorse['Horse'/192, l='MpServer', x=-126.57, y=90.00, z=-229.01], EntityCow['Cow'/193, l='MpServer', x=-112.28, y=87.00, z=-233.42], EntitySkeleton['Skeleton'/194, l='MpServer', x=-113.72, y=35.00, z=-217.35], EntityChicken['Chicken'/195, l='MpServer', x=-126.45, y=79.00, z=-209.04], EntitySheep['Sheep'/196, l='MpServer', x=-112.50, y=73.00, z=-212.27], EntityCow['Cow'/197, l='MpServer', x=-115.53, y=88.00, z=-223.83], EntityChicken['Chicken'/199, l='MpServer', x=-113.50, y=70.00, z=-194.20], EntitySkeleton['Skeleton'/212, l='MpServer', x=-112.26, y=58.00, z=-312.51]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:461) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2897) at net.minecraft.client.Minecraft.run(Minecraft.java:462) at net.minecraft.client.main.Main.main(Main.java:118) 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 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.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26) -- System Details -- Details: Minecraft Version: 1.12.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_131, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 476976816 bytes (454 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94 FML: MCP 9.42 Powered by Forge 14.23.1.2562 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.2562.jar | None | | UCHIJAAAA | forge | 14.23.1.2562 | forgeSrc-1.12.2-14.23.1.2562.jar | None | | UCHIJAAAA | grandsorcery | 0.1a | bin | None | Loaded coremods (and transformers): GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 388.13' Renderer: 'GeForce GTX 1080/PCIe/SSE2' Launched Version: 1.12.2 LWJGL: 2.9.4 OpenGL: GeForce GTX 1080/PCIe/SSE2 GL version 4.6.0 NVIDIA 388.13, NVIDIA Corporation GL Caps: Using GL 1.3 multitexturing. Container: Spoiler package com.GooberGunter.GrandSorcery.client.gui; import com.GooberGunter.GrandSorcery.common.block.tileentities.EnchNexTE; import com.GooberGunter.GrandSorcery.common.utils.Util; 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; import net.minecraftforge.items.SlotItemHandler; /** * Manages Inventory * @author ***** * */ public class EnchNexTECont extends Container{ private EnchNexTE te; public EnchNexTECont(IInventory playerInv, EnchNexTE te) { this.te = te; //Tile Entity, slot 0, Slot ID: 0 for(int y = 0; y < 1; y++) { for(int x = 0; x < 1; x++) { this.addSlotToContainer(new SlotItemHandler(te, x+y, 62 + x * 18, 42 + y * 18)); te.insertItem(x+y, ItemStack.EMPTY, false); } } //player inventory, slots 9-35, slot ids: 1-27 for(int y = 0; y < 3; y++) { for(int x = 0; x < 9; x++) { this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 101 + y * 18)); } } //player action bar, slots 0-8, slot ids: 28-36 for(int x = 0; x < 9; x++) { this.addSlotToContainer(new Slot(playerInv, x, 8 + x*18, 159)); } Util.logger.info("slots added"); }//player, tile entity @Override public boolean canInteractWith(EntityPlayer playerIn) { return true; } @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { /**Util.logger.info("transfer"); ItemStack previous = ItemStack.EMPTY; Slot slot = (Slot) this.inventorySlots.get(index); Util.logger.info("slot validity check"); if (slot != null && slot.getHasStack()) { ItemStack current = slot.getStack(); previous = current.copy(); if (index < 1) { // From TE Inventory to Player Inventory if (!this.mergeItemStack(current, 1, 37, true)) { Util.logger.info("te to pi"); return ItemStack.EMPTY; } } else { // From Player Inventory to TE Inventory if (!this.mergeItemStack(current, 0, 1, false)) { Util.logger.info("pi to te"); return ItemStack.EMPTY; } } if (current.getMaxStackSize() == 0) { Util.logger.info("stack is zero"); slot.putStack(ItemStack.EMPTY); } else { Util.logger.info("stack not zero"); slot.onSlotChanged(); } if (current.getCount() == previous.getCount()) { Util.logger.info("current stack is same as previous"); return ItemStack.EMPTY; } slot.onTake(playerIn, current); } Util.logger.info("slot verified");**/ return this.te.extractItem(index, 64, false); } } /** * Things to Note: *each inventory has its own set of slot ids * * * **/ Tile Entity: Spoiler package com.GooberGunter.GrandSorcery.common.block.tileentities; import java.util.ArrayList; import com.GooberGunter.GrandSorcery.common.utils.Util; import net.minecraft.block.Block; import net.minecraft.block.BlockBreakable; 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.ITickable; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.items.IItemHandler; public class EnchNexTE extends TileEntity implements ITickable, IItemHandler{ private int[] arcanaStores = new int[5]; private ItemStack[] inventory; private String enchName; public EnchNexTE() { for (int i : arcanaStores) { this.arcanaStores[i]=0; } inventory = new ItemStack[this.getSlots()]; for(int slot = 0; slot < this.getSlots(); slot++) this.insertItem(slot, ItemStack.EMPTY, false); } @Override public void update() { if(!this.world.isRemote) { } } //SAVE AND LOAD @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { // TODO Auto-generated method stub return super.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { // TODO Auto-generated method stub super.readFromNBT(compound); } //INVENTORY @Override public int getSlots() { return 1; }//only has one slot @Override public ItemStack getStackInSlot(int slot) { if(slot < 0 || slot >= this.getSlots()) { return null; }//if index is invalid return inventory[slot];//returns itemstack in that slot stored in the array }//gets the stack in the slot @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { Util.logger.info("insert"); inventory[slot] = ItemStack.EMPTY; return inventory[slot]; } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { Util.logger.info("extract"); return ItemStack.EMPTY;//returns the itemstack in the slot asked for } @Override public int getSlotLimit(int slot) { return 1; } } Quote
GooberGunter Posted December 18, 2017 Author Posted December 18, 2017 Update: So I've fiddled around with things. And I have a couple of problems: 1. Hoppers don't send items into the object, I think this is a problem with the TIle Entity class 2. Whenever the player puts an object into the container's slot, the item isn't deleted from the player's inventory causing duplicating glitches 3. Whenever the object is shift clicked from the Tile Entity's inventory, the game crashes with the following error. I'm not sure why I'm having all of these problems, the entity was working fine when it was implementing IInventory. Error: Spoiler [16:56:52] [main/FATAL]: Reported exception thrown! net.minecraft.util.ReportedException: Updating screen events at net.minecraft.client.Minecraft.runTick(Minecraft.java:1897) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] 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_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] Caused by: java.lang.ClassCastException: com.GooberGunter.GrandSorcery.common.block.tileentities.EnchNexTE cannot be cast to net.minecraftforge.items.IItemHandlerModifiable at net.minecraftforge.items.SlotItemHandler.putStack(SlotItemHandler.java:89) ~[SlotItemHandler.class:?] at com.GooberGunter.GrandSorcery.client.gui.EnchNexTECont.transferStackInSlot(EnchNexTECont.java:74) ~[EnchNexTECont.class:?] at net.minecraft.inventory.Container.slotClick(Container.java:271) ~[Container.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:610) ~[PlayerControllerMP.class:?] at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:693) ~[GuiContainer.class:?] at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:430) ~[GuiContainer.class:?] at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:611) ~[GuiScreen.class:?] at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) ~[GuiScreen.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1884) ~[Minecraft.class:?] ... 15 more [16:56:52] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: ---- Minecraft Crash Report ---- // Hi. I'm Minecraft, and I'm a crashaholic. Time: 12/17/17 4:56 PM Description: Updating screen events java.lang.ClassCastException: com.GooberGunter.GrandSorcery.common.block.tileentities.EnchNexTE cannot be cast to net.minecraftforge.items.IItemHandlerModifiable at net.minecraftforge.items.SlotItemHandler.putStack(SlotItemHandler.java:89) at com.GooberGunter.GrandSorcery.client.gui.EnchNexTECont.transferStackInSlot(EnchNexTECont.java:74) at net.minecraft.inventory.Container.slotClick(Container.java:271) at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:610) at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:693) at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:430) at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:611) at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1884) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186) at net.minecraft.client.Minecraft.run(Minecraft.java:441) at net.minecraft.client.main.Main.main(Main.java:118) 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 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.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26) Container: Spoiler package com.GooberGunter.GrandSorcery.client.gui; import com.GooberGunter.GrandSorcery.common.block.tileentities.EnchNexTE; import com.GooberGunter.GrandSorcery.common.utils.Util; 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; import net.minecraftforge.items.SlotItemHandler; /** * Manages Inventory * @author Justin * */ public class EnchNexTECont extends Container{ private EnchNexTE te; public EnchNexTECont(IInventory playerInv, EnchNexTE te) { this.te = te; //Tile Entity, slot 0, Slot ID: 0 for(int y = 0; y < 1; y++) { for(int x = 0; x < 1; x++) { this.addSlotToContainer(new SlotItemHandler(te, x+y, 62 + x * 18, 42 + y * 18)); } } //player inventory, slots 9-35, slot ids: 1-27 for(int y = 0; y < 3; y++) { for(int x = 0; x < 9; x++) { this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 101 + y * 18)); } } //player action bar, slots 0-8, slot ids: 28-36 for(int x = 0; x < 9; x++) { this.addSlotToContainer(new Slot(playerInv, x, 8 + x*18, 159)); } Util.logger.info("slots added"); }//player, tile entity @Override public boolean canInteractWith(EntityPlayer playerIn) { return true; } @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { Util.logger.info("transfer"); ItemStack previous = ItemStack.EMPTY; Slot slot = (Slot) this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack current = slot.getStack(); //previous = current.copy(); if (index < 1) { // From TE Inventory to Player Inventory if (!this.mergeItemStack(current, 1, 37, true)) return ItemStack.EMPTY; } else { // From Player Inventory to TE Inventory if (!this.mergeItemStack(current, 0, 1, false)) return ItemStack.EMPTY; } if (current.getCount() == 0) slot.putStack(ItemStack.EMPTY); else slot.onSlotChanged(); if (current.getCount() == previous.getCount()) return ItemStack.EMPTY; slot.onTake(playerIn, current); } return previous; } } /** * Things to Note: *each inventory has its own set of slot ids * * * **/ Tile entity class: Spoiler package com.GooberGunter.GrandSorcery.common.block.tileentities; import java.util.ArrayList; import com.GooberGunter.GrandSorcery.common.utils.Util; import net.minecraft.block.Block; import net.minecraft.block.BlockBreakable; 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.ITickable; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.items.IItemHandler; public class EnchNexTE extends TileEntity implements ITickable, IItemHandler{ private int[] arcanaStores = new int[5]; private ItemStack[] inventory; private String enchName; public EnchNexTE() { for (int i : arcanaStores) { this.arcanaStores[i]=0; } inventory = new ItemStack[this.getSlots()]; for(int slot = 0; slot < this.getSlots(); slot++) this.insertItem(slot, ItemStack.EMPTY, false); } @Override public void update() { if(!this.world.isRemote) { } } //SAVE AND LOAD @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { // TODO Auto-generated method stub return super.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { // TODO Auto-generated method stub super.readFromNBT(compound); } //INVENTORY @Override public int getSlots() { return 1; }//only has one slot @Override public ItemStack getStackInSlot(int slot) { if(slot < 0 || slot >= this.getSlots()) { return ItemStack.EMPTY; }//if index is invalid return inventory[slot];//returns itemstack in that slot stored in the array }//gets the stack in the slot @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { Util.logger.info("insert"); this.inventory[slot]=stack; stack = ItemStack.EMPTY; return this.inventory[slot]; } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { Util.logger.info("extract"); return inventory[slot];//returns the itemstack in the slot asked for } @Override public int getSlotLimit(int slot) { return this.inventory[slot].getMaxStackSize(); } } Quote
GooberGunter Posted December 18, 2017 Author Posted December 18, 2017 So I found out that I'm supposed to use ItemHandler through the capability system, not through direct implementation. Is that right? Quote
Choonster Posted December 18, 2017 Posted December 18, 2017 5 minutes ago, GooberGunter said: So I found out that I'm supposed to use ItemHandler through the capability system, not through direct implementation. Is that right? That's correct. 1 Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
GooberGunter Posted December 18, 2017 Author Posted December 18, 2017 (edited) So then, the insertItem and extractItem methods are all ready to be used, nothing needs to be overwritten, I can just call the ItemStackHandler to insert and extract things in the GUI Container class? And do I have to attach the Item Handler Capability in an event? Edit: they are, nothing needs to be overwritten afaik, I can call the ItemStackHandle, now I don’t need to attach the capability Edited December 18, 2017 by GooberGunter Quote
Recommended Posts
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.