Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Titmar

Members
  • Content Count

    23
  • Joined

  • Last visited

Everything posted by Titmar

  1. I probably should do that, yeah. Works fine now!
  2. Okay, I am at a loss - once again. Somehow resetting the container.inventorySlots field does not work as intended. When the MarketContainer is created it is starting out with the first inventory in the list and displays that. If that is a single chest and i switch to a double chest and back i get thrown the ioob exception. If the first inventory is a double chest and I switch to a single chest, it keeps showing the second part of the double chest but when i click one of those slots i still get the ioob exception. I uploaded it to my github, because I cant even get close to where the issue
  3. Nvm, the error does not seem to come from the slot by itself but from somwhere else. Currently investigating.
  4. Yeah but I need to give the slot an object of IInventory (in this case the chestTE) which for some reason only sees the single inventory. I could override the slot class to use IItemHandler instead of IInventory but that seems a bit overkill. Or is there a way to get the slot to use the IItemHandler that I dont see?
  5. I am currently trying to display the contents of a double chest in the container of a different block. For single chests and barrels it works perfectly fine. The problem is, when adding Slots to the container it uses the IInventory vanilla implementation. So when looping over the chest contents with the ItemHandler capability i get thrown indexoutofbound exceptions since vanilla handles double chests quite weirdly. The capability shows me the full 54 size but vanilla thinks its only 27. Anyways, I tried getting around that by switching the IInventory of the newly generated Slot to the second p
  6. Alright, I got it all working now. In the end it was easy after finding out abut the player.openContainer field... On Button press, send a custom packet. This custom packet tells the server to update the players openContainer like so: Nothing else to do afterwards. Vanilla takes care of the rest apparently. At least for now I havent found any bugs, though I only tested it with a single player and only on a single player world.
  7. Titmar

    setGui

    Do you know basic java and how to capture Events? Pseudo code: public static void catchEvent(GuiOpenEvent even) { WorkBenchContainer con = new WorkBenchContainer(id, playerInventory); CraftingScreen screen = new CraftingScreen(con, playerInventory, title); event.setGUI(screen); } id and playerInventory should be readable from the old screen. Check out the classes how to access those.
  8. Titmar

    setGui

    You would need to give it an Object of CraftingScreen which in itself needs a WorkbenchContainer, the playerInventory and a title. You just pass the CraftingScreen object to the setGUI method
  9. Okay so I had a bit of a deeper look into the syncing of containers. Vanilla is using the Container::detectAndSendChanges method which in turn uses a list of private listeners it sends those changes to. My current code You see I am resetting the slots and recreate them for the new Inventory which makes the vanilla method unable to detect any changes. Reason being that I would like to be able to support custom sized inventories. Of course I could set a maximum size for the inventory and just clear all slots before refilling them. But that is just limiting functionality. Now I cant o
  10. I do have said block which you can register inventory blocks to, i call it market. When opening its GUI I have a bunch of buttons which are connected to those registered inventories. When pressing a button i want to show the inventory of its connected block until i chose another (similar to the selection of an active trade with a villager). Now I could of course set some global variable such that it shows the same inventory for every player. But I would like it independent such that every player can browse independently from others.
  11. I know how to send from client to server via the SimpleChannel Network but I have no idea how to send packets the other way. As in, I could send a request to the server from the client but how would I answer it? How do i send backwards?
  12. okay, so even with the capability i wouldnt be able to get the inventory clientside i suppose. How would i sync from server to client in this case? Because apparently private void changeInventory(LockableLootTileEntity te) { IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null); if(handler == null) return; this.activeInventory = NonNullList.create(); for(int i = 0; i < handler.getSlots(); i++) { this.activeInventory.add(handler.getStackInSlot(i)); } } does not resolve the issue
  13. I thought there would be a forge way to get access to the inventory. I havent yet fully wrapped my head around the capability system which is probably why I didnt think of it. I will get back to you if I cant figure it out by myself. The above code is located in the screen class of my "controler" block. Im using the inventory there in order to just render the ItemStacks. For now I dont plan to add other functionality in the screen. Later on I would want to add a villager interaction but thats some time away. As a side question: This forum is not yet switched over to the
  14. I am currently wokring on a block which lets you register and see the inventory of registered blocks. I.e. i want to display what is inside a chest which could be 10 blocks away. I am not looking to change its inventory, just look at it. Since i can't just use the LockableLootTileEntity::getItems method I have to set with recreating the inventory by looping through with LockableLootTileEntity::getStackInSlot. Problem is I only get an empty ItemStack (1 air block) from that method. No matter which index. For reference: private void changeInventory(LockableLootTileEntity te) { int size = t
  15. Ahh, it has been the markDirty part. I knew i missed some crucial part that calls the read/write. As for the HashSet, this is subject to change anyway. In the future i will need to store way more data alongside the position. For now I just wanted to get a proof of concept which I can expand on. I guess I was using the wrong nethod there, it should be getTileData(). The idea was to check if anything has been writen onto the NBTTag. Because if anything has been writen in there and it still didnt work the problem would have been in the read method. As we know now neither was the case.
  16. When im accessing the NBT data from a different point (right clicking the block and outputting into the logger) it shows me an empty NBTList while the private list of the TE has content. After reloading the world all data is lost. Since i dont know how to trigger a read/write i cant tell where the mistake is. Adding a debug message right into the read/write methods does not work either. I dont get any Logger output at all. Seems weird that both functions arent triggered at all... Will upload to git so you have a full overview. https://github.com/titmar/Caravans/blob/main/src/main
  17. This is actually what i was looking for - a sucessor of the NBTTagList. Thank you sieben. Makes it look way cleaner. It still does not work though. @Override public CompoundNBT write(CompoundNBT compound) { super.write(compound); ListNBT nbt = new ListNBT(); for(BlockPos pos : containers) { nbt.add(NBTUtil.writeBlockPos(pos)); } compound.put("containerArray", nbt); return compound; } @Override public void read(BlockState state, CompoundNBT compound) { super.read(state, compound); ArrayList<BlockPos> list = new ArrayList<BlockPos>(); ListNBT
  18. So basically the idea i had. I just tested it and I have no idea why it wont work. @Override public CompoundNBT write(CompoundNBT compound) { super.write(compound); compound.putInt("containerArray", containers.size()); int i = 0; for (BlockPos bp : containers) { compound.put("pos" + i, NBTUtil.writeBlockPos(bp)); i++; } return compound; } @Override public void read(BlockState state, CompoundNBT nbt) { super.read(state, nbt); int size = nbt.getInt("containerArray"); for (int i = 0; i <= size; i++) { BlockPos bp = NBTUtil.readBlockPos((CompoundNBT)
  19. I am currently stuck at storing (and reading) an ArrayList of BlockPos to NBT. I found a thread where they tell you to use a NBTTagList. This does not seem to exist in 1.16 anymore. I know there is the NBTUtil methods for BlockPos which is returning me a new CompoundNBT. The idea I have is to use the NBTCompound#put(String key, INBT value) method and just add a incremental number to my key for every object in my ArrayList. But that sounds dirty to me. Is there a better way?
  20. Big oopsie, guess its been a long day it actually works perfectly fine and as intended
  21. I cant for the life of me find out why my ItemStack wont get updated properly in the Item::onItemUse method. The nbt data is working properly but it wont shrink the stack. Or rather it does shrink it in the local functions but somehow it does get reset afterwards. @Override public ActionResultType onItemUse(ItemUseContext context) { World world = context.getWorld(); if (!world.isRemote) { TileEntity te = world.getTileEntity(context.getPos()); ItemStack stack = context.getPlayer().getHeldItem(context.getHand()); if (te instanceof MarketTileEntity) { this.useOnMarket
  22. Okay, guess for now im not going to touch a full rework then and make it simple. Thanks!
  23. Im currently creating a mod with a similar food system like TerrafirmaCraft where food decays depending on where it is stored. For the calcualtion of said decay i need to know the place where an item is stored. The playerinventory is easy, i can just check for inventoryTicks. Terrafirmacraft seems to have a whole rework going for the tick system where all storage options send ticks to items inside. That negates vanilla storage and other mods storage systems to detect where it is stored. Is there any way i can find out where an item is being stored? Same goes for when the item is dropped on the
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.