Jump to content

Daeruin

Members
  • Posts

    424
  • Joined

  • Last visited

Everything posted by Daeruin

  1. Has something changed about how container items work? Before updating to 1.10.2, I used to have it working so certain tools could be used in the crafting grid and would remain there but take damage after crafting the item. Now my tools stay in the crafting grid but they get a red zero overlaid over them and disappear as soon as they are clicked on. I'm pretty sure I didn't change anything about that part of the code during the update. @Override public boolean hasContainerItem(ItemStack stack) { return true; } @Override public ItemStack getContainerItem(ItemStack stack) { stack.attemptDamageItem(1, PrimalToolAxe.itemRand); return stack; }
  2. No. To double check, I just created a brand new world, placed a single container and logged out. You can see from my println statements that the tile entity is initialized with 4 slots from my container class. When I hit escape to save and exit, you can see that the NBT tag originally returns 0, but then gets saved as 4. Then when I log back in, as the world is loading, my println statements show the tile entity has a numSlots value of 0 and gets initialized to 4 from readFromNBT, but later on during startup the NBT value shows as 0 and gets reinitialized that way: Of course, as soon as I right click on that container, it crashes.
  3. I don't understand how the tag could not be present. I set it in the writeToNBT method and read it from readFromNBT. There is no sensible default--the containers that use this tile entity can have 4, 8, or 12 slots. That's the whole reason I'm trying to store these values.
  4. Hmmm. There's something still wrong. I no longer get errors on loading the world, but when I right click on the container block I get a runtime exception from ItemStackHandler: Did I do something wrong? public class PrimalTileEntity extends TileEntity { ItemStackHandler inventory; public int numSlots; public int stackLimit; public PrimalTileEntity() { } public void initializeTileEntity(final int numSlotsIn, final int stackLimitIn) { this.numSlots = numSlotsIn; this.stackLimit = stackLimitIn; this.inventory = new ItemStackHandler(numSlotsIn) { @Override protected int getStackLimit(int slot, ItemStack stack) { return Math.min(stackLimitIn, stack.getMaxStackSize()); } }; } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setInteger("numSlots", numSlots); compound.setInteger("stackLimit", stackLimit); compound.setTag("inventory", inventory.serializeNBT()); return super.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { initializeTileEntity(compound.getInteger("numSlots"), compound.getInteger("stackLimit")); inventory.deserializeNBT(compound.getCompoundTag("inventory")); super.readFromNBT(compound); }
  5. In my tile entity's writeToNBT method?
  6. Oooh, great idea. Let's see... I'm still trying to wrap my head around all this, so how would I go about that? Would I need to create a new capability to attach to my tile entities? Could I somehow wrap it into the ItemStackHandler stuff?
  7. Terrafirmacraft revamped Minecraft's health system, and it's not compatible with much of anything—but that's due to much more than simply the health system.
  8. The way I have set things up now, I can't do that because I need to pass in the number of slots to the ItemStackHandler constructor, and that number varies for the three different containers I'm trying to handle with this tile entity. When the tile entity is created, I need to know for which container, so I know how many slots to give the ItemStackHandler. Unless someone has another clever idea, it's looking like I really will have to create separate tile entity classes to handle each container. Thanks for the idea. It didn't seem to help.
  9. I took larsgerrits advice and created a method to initialize those values in my tile entity. I'm using an anonymous class to override ItemStackHandler#getStackLimit. However, the container contents are still not being saved, and I get a null pointer exception in my tile entity's readFromNBT method when loading the world. Error message: My tile entity class: I call the my tile entity's initialization method in my block's createTileEntity method:
  10. D'oh! I ran into this when first creating my containers. Now while updating I completely forgot and thought I was being clever by streamlining my four classes into one by simply passing in values to the constructor. Kind of annoying to have to create multiple subclasses just for the sake of two int values.
  11. I hope this is the last problem I have converting my tile entities over to capabilities. When I leave something in the container and log out then back in, I get an error and the stuff in the container is gone. From searching online it seems I may have to do something with packets, but I'm not sure. Here's the error: And here's my tile entity class:
  12. I had never heard of anonymous classes before, so I read up on them and realized I had seen them before without knowing what to call them. So I experimented a little and came up with something that seems to work. public class PrimalTileEntity2 extends TileEntity { private ItemStackHandler inventory; private int numSlots; public PrimalTileEntity2(int numSlots, final int stackLimit) { this.numSlots = numSlots; inventory = new ItemStackHandler(this.numSlots) { @Override protected int getStackLimit(int slot, ItemStack stack) { return Math.min(stackLimit, stack.getMaxStackSize()); } }; }
  13. That's good to know. I'm still trying to update to 1.10.2 from 1.8.9, and it's taken me several months. So I'm reluctant to try to update further at the moment.
  14. OK... so to do that, do I need to replace ItemStackHandler with my own class that implements IItemHandler?
  15. I am trying to update my custom containers to the capability system. My old tile entity class implemented IInventory and made use of the very handy built-in getInventoryStackLimit method to limit the number of items allowed in each slot. Now I'm using ItemStackHandler, and I'm left wondering how to set a stack limit on my container. I didn't see a similar method in ItemStackHandler except getStackLimit, but that refers to a property of the ItemStack rather than the container. Thanks in advance for any tips you have on how to achieve this.
  16. Right, but I had my own variables in my subclass. Why couldn't the superclass method set their values? Changing my subclass's variables to public didn't make a difference.
  17. I guess I still don't have a full understanding of how subclassing works, but let me see if I understand now. I'm extending GuiInventory, which has two private variables (oldMouseX and oldMouseY) and a method (drawScreen) for setting those variables. I have extended that class, but I had to declare my own versions of the variables, because they were private in the superclass. So now I need my own method to set the variables, too. I'm still unclear if the real reason is because the variables are private, or because the superclass method uses the [b]this[/b] notation when setting the variables. But yeah, once I copied drawScreen into my subclass and override it, everything works. Thanks for being patient with all my questions. I really appreciate all your help! I'm really pleased with how this feature of my mod has turned out.
  18. You're talking about mouseX and mouseY, right? I don't see a problem. I'm not doing anything different from vanilla. drawEntityOnScreen is called from drawGuiContainerBackgroundLayer, which passes in a float parameter based on oldMouseX and oldMouseY and some other values. oldMouseX and oldMouseY get their values from the superclass drawScreen method from the mouseX and mouseY parameters.... all that is pure vanilla.
  19. I lied, I didn't copy that code. I'm already extending GuiInventory, so I'm just letting that class do the work by calling GuiInventory#drawEntityOnScreen. Here's my container GUI: And here's GuiInventory#drawEntityOnScreen, which is supposed to animate the player model on the inventory screen: For some reason, it isn't doing its job, or I've done something wrong, so the player model is always stuck staring at the top left of the screen and does't follow the mouse's movement. Also, I realized I don't need to use Capabilities just yet. I originally thought I needed to make changes to the player's inventory itself, but in the end I only needed to modify the player container, since the slots I'm adding are all in the crafting grid, and they aren't part of the player's permanent inventory. I can let the vanilla player inventory do all the work of saving and loading the items in the inventory. I have other ideas for adding more slots to the inventory, however, and may be asking for help later. I got a ways into adding the Capability and kept getting confused.
  20. I haven't finished converting to Capabilities yet, but in the meantime I have noticed that the player model that displays in the inventory screen doesn't move around as I move the mouse. It's always looking at the top left corner of the screen. Any idea why? I copied that code directly from vanilla's GuiInventory class.
  21. Alright, I did that and it seems to be working. It wasn't as annoying as I thought it would be, in large part because I had defined my indices with a set of constants with human-readable names. Here's what the finished player container looks like, for anyone who's interested. I have one final problem, which is that the items in the player's inventory disappear every time I log out. I need to convert the player container over to Capabilities still, and I'm hoping that will solve the problem.
  22. The creative inventory problem has been there since my very first post, so nothing I've done recently has caused it. Does this screen shot work? https://screencast.com/t/ItbjCtAFi See how the icons for the armor slots have all been pushed down into the regular inventory? I think because the creative inventory lacks a crafting grid, GuiContainerCreative#setCurrentCreativeTab manually adjusts for the missing slots by iterating through the player's inventoryContainer and moving the slots around based on their ID. For example, it sets slot ID 45 (the shield slot) to xPos=35 and yPos=20. Well, since I've added five slots to the player container, slot ID 45 is no longer the shield slot. setCurrentCreativeTab is private, so I can't override it by extending GuiContainerCreative. I suppose I could rearrange what indexes I assign my new player inventory slots to, in order to leave all the vanilla slots in their original index positions. That would be a pain in the butt and make my transferStackInSlot method even more complicated than it already is. Maybe I could use OpenGuiEvent to intercept the creative inventory and replace it with a custom one, but that intimidates me because the creative inventory GUI is such a huge class.
  23. Oh, I feel like such a dummy. I went with option 2. I realized I needed to override two of the methods anyway. Man, transferStackInSlot is nasty. I'm still having the problem with the creative survival inventory tab. I think by adding five new slots to the player container, I have pushed all the slot indexes for that screen down by five. Vanilla does some weird crap in the GuiContainerInventory class to compensate for the missing crafting grid slots, and by adding five slots to the player container, I seem to have thrown that off. Any advice on how to deal with that?
  24. Which question are you attempting to answer? Could you be more explicit? Overriding what Container? I am extending the ContainerPlayer class and overriding some of the methods, if that's what you mean. And I'm replacing the regular player.inventoryContainer with my player container during the EntityJoinWorldEvent. But you could have seen that from the code I posted earlier, so maybe you meant something else?
  25. Let me know if you find any. I'd like to do this, as well. I tried once and couldn't get it to work. The mod Terrafirmacraft does this with containers. Perhaps you can make more sense of their code than I could.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.