Jump to content

Daeruin

Members
  • Posts

    424
  • Joined

  • Last visited

Everything posted by Daeruin

  1. When breaking the block: itemStackCapability: 1xitem.apple@0 itemStackCapability: 1xtile.air@0 itemStackCapability: 1xtile.air@0 itemStackCapability: 1xtile.air@0 In the GuiHandler: GuiHandler:getClientGuiElement:149]: Slot 0: 1xtile.air@0 GuiHandler:getClientGuiElement:149]: Slot 1: 1xtile.air@0 GuiHandler:getClientGuiElement:149]: Slot 2: 1xtile.air@0 GuiHandler:getClientGuiElement:149]: Slot 3: 1xtile.air@0 GuiHandler:getServerGuiElement:59]: Slot 0: 1xtile.air@0 GuiHandler:getServerGuiElement:59]: Slot 1: 1xtile.air@0 GuiHandler:getServerGuiElement:59]: Slot 2: 1xtile.air@0 GuiHandler:getServerGuiElement:59]: Slot 3: 1xtile.air@0
  2. It prints out the contents of the inventory, just as one would expect. The stacks all seem to be present. When doing it in the GuiHandler for the Container, it shows nothing. The stacks are gone. I’m not at my computer or I would copy it here for you to see. I haven’t tried it on the GUI side yet.
  3. Did you see my new code? I think that's what I'm doing now when placing and picking up the block. If I need to be doing it a different way, let me know. My block. I still think I need to manually save the tile entity's data to the ItemStack's NBT. Otherwise I will not be able to instantiate the tile entity when the block is being placed. I'm storing more than just a list of ItemStacks with my tile entity. Any idea why the inventory is syncing when placing the block, but not when picking it up?
  4. Alright, I tried to do what you said. I think you were both basically saying the same thing. The inventory is now synced when placing the block, but not when picking it up. I'm not sure why. I'm loading the capabilities with the list of ItemStacks in essentially the same way in both cases. I don't see why you are calling BlockEntityTag a hack. That's the key required by ItemBlock#setTileEntityNBT to provide the tile entity with all of its data when the block is placed, including its coordinates. If I don't wrap the NBT data in that tag, how will I provide the tile entity with its data? Are you saying I need to do something custom to set the TE's data?
  5. Making a new post because the old one is out of date. I'm still working on the same functionality. I have a block with a tile entity that keeps its inventory when broken and held in the player's inventory. It can be carried around and re-placed elsewhere in the world and still keep its inventory. I'm trying to make it so the player can open the block's inventory by right clicking while holding the block in their hand. At the moment, I have the GUI appearing when right clicking from the hot bar, but the block's inventory appears to be empty. I can put things into the inventory, and they persist as long as the block stays in the player's inventory. If I drop the block and pick it back up again, the items I had put in the inventory are gone. After placing the block, its original inventory reappears. So basically I've managed to create a temporary inventory that only works when the block is in the player's inventory, and it doesn't affect the actual block's inventory at all. My code repository is here. My block. My tile entity. My Container. My GUI. My GuiHandler. My ItemBlock. My capability provider. My custom ItemStackHandler.
  6. I used Codecademy. I have also used the Head First series to learn programming languages before. They're quite good.
  7. I feel like you're teasing me. Where and when do I initialize the ICapabilityProvider? I thought I was doing that here by passing the NBT data to the ItemStack constructor when spawning the block's EntityItem and relying on the ItemBlock's initCapabilities here. I commented out all that code because it wasn't working. The capability somehow disappeared from the ItemStack by the time it reached the player's inventory.
  8. How/where would I do that? How is what you're telling me different from this?
  9. That's what I was trying to do, but the capability kept disappearing when picking up the item. Nobody replied to that problem, so I tried something else. Any clue why my capability wouldn't stick? See my messages above.
  10. The answer is no. I was able to instantiate a new inventory using the NBT data I was already saving on the dropped block, and send that to my GuiHandler. I now have the block's inventory displaying when the player right-clicks with the ItemBlock while holding it. The new problem is that changes to the ItemBlock inventory aren't saving. I'm guessing I need to send a packet or something, but I'm not sure. Would it be a client-to-server packet to let the server know what has changed in the ItemBlock's inventory?
  11. I added a breakpoint and it appears that the capability remains attached to the EntityItem clear until it gets added to the world's entity list. So that all seems fine. Yet when the player picks the EntityItem up, the capability is gone. It would be nice to get some validation that I'm even headed down the right path here. I have a container that's working great, and I have it saving its inventory when broken, picked up, and then re-placed into the world. All fine and dandy. What I'm trying to do now is make it so when the player is holding the block in their inventory, they can right click with it to view its inventory. My thought was that I need to attach an ItemHandler capability to the ItemBlock, so when the player right clicks with it, I can supply the block's inventory to my GuiHandler. However, I already have the inventory saved in the item's NBT data--that's how it knows what to put back in the block's inventory when the player places it. Do I even need a separate capability? Am I going about it the right way? How would you do it? My code is here: https://bitbucket.org/Daeruin/basketcase/src/master/src/main/java/com/daeruin/basketcase/
  12. Inventory is now saving again. I can see the inventory attached to the ItemStack right before calling Block#spawnAsEntity, but the item handler capability seems to be disappearing when spawning the EntityItem. You can see the Block code here.
  13. That's what Animefan said above, but I misunderstood what he meant. That worked! Thank you! For the record, this is what worked: ItemStack stack = new ItemStack(Item.getItemFromBlock(this), 1, 0, inventoryTag); spawnAsEntity(world, pos, stack); So it's not crashing anymore—but of course nothing else works! The inventory isn't even being saved anymore. I'll see if I can figure it out and let you know if I need more help.
  14. I've been trying to do this with the extension of ItemBlock I created for my Block, since that's what will be in the player's inventory and therefore what they will use to open the basket inventory when they're holding it. In the past I have never created static instances of my ItemBlocks. I just instantiate them in my registration method and register them there. Hence my question above:
  15. Well, I'm trying to do this from Block#onBlockActivated when the player right clicks on the block with an empty hand. I don't have access to the item unless I create one or refer to an existing one.
  16. Yeah, I totally overlooked that. I think I've fixed that, but the error is still occurring. Do I need to create a static ItemBlock that I can use when spawning the EntityItem?
  17. I made a little mod with three kinds of wicker baskets that have different sizes of inventory. The baskets are blocks with tile entities, but when you shift-right-click on the block, the basket will "drop" as an EntityItem and maintain its inventory. You can then pick it up and carry it around, then place it somewhere else and it keeps its inventory intact. I tried to make it so the player can open the basket's inventory when right-clicking with the basket in their hand, but it's not working. Specifically, when picking up the EntityItem, I get a ticking player exception caused by an ArrayIndexOutOfBoundsException. I added a slew of println statements everywhere, and it appears that when I spawn the EntityItem, the NBT data is lost. Everything seems to be in order until I call Block#spawnAsEntity from Block#onBlockActivated. The ItemStack I'm passing into spawnAsEntity is fine. Do I need to do something special here? It was working fine before I started on this particular feature (opening the basket inventory by right clicking with the basket in hand). As part of this, I made a custom ItemBlock so I could trigger the GUI when right-clicking. I'm wondering if I need to override Item#createEntity? But it seems weird to me that vanilla ItemBlock doesn't do anything with this method. To be honest I'm not even sure I'm approaching this right in the first place, so any pointers are greatly appreciated. Code is here: https://bitbucket.org/Daeruin/basketcase/src/master/src/main/java/com/daeruin/basketcase/
  18. I'm not sure I agree 100%. I've been hearing that Forge will take several months to be ready. If your Java knowledge is solid, you could get a lot done in that time and learn a lot of concepts that will remain the same. However, if your mod has anything to do with world gen, I would definitely wait. And if you don't know Java very well, I would recommend spending a few months getting your Java knowledge solid while you wait.
  19. After copying World#rayTraceBlocks into my PlayerInteractEvent and messing around a bit, I can now say that the culprit was indeed BlockLiquid#canCollideCheck. It returns false if the block's level is anything other than 0 (full source water block) and prevents the ray trace from returning the flowing water block as a hit. So I just need to bypass that in my copy of World#rayTraceBlocks, and the ray trace now returns flowing water blocks.
  20. Thanks for the suggestion. I tried the parameters you suggested. It only seems to return the flowing water block (with a hit type of MISS) if there's no other block in range. If I'm close to the flowing water, it still returns the block behind the flowing water. I'm thinking I might need to do a custom ray trace.
  21. The title pretty much says it. I've already managed to detect if the player is right clicking on a water source block. To do that, I use the following code to get a RayTraceResult, then check if the block at that position is equal to Blocks.WATER. RayTraceResult code: However, when the player right clicks on flowing water, the ray trace does not detect it at all and instead detects the block immediately past the flowing water. It seems like maybe the fault is in BlockLiquid#canCollideCheck, which returns false if the water level is anything other than 0 (not flowing). That method is used by World#rayTraceBlocks, which I'm using in my ray trace code. Is there a another way?
  22. To create the custom inventory, extend GuiInventory and supply your own texture that shows your custom slots. Then use the GuiOpenEvent, check if it's a GuiInventory, and if so, open your own custom inventory instead using GuiOpenEvent#setGui.
  23. Thanks for posting that Gist. Do we have any idea yet just what is changing with regard to world gen?
  24. I found capabilities very confusing at first, too. The Forge documentation didn't help me at all until I was already thoroughly familiar with capabilities. Try this tutorial. https://www.planetminecraft.com/blog/forge-tutorial-capability-system/ It will get you started with a single stat called Mana, but you can obviously extend that to anything you want.
  25. So I discovered that players have a stepHeight attribute that does everything I wanted without messing with collision boxes.
×
×
  • Create New...

Important Information

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