-
Posts
23 -
Joined
-
Last visited
Converted
-
Gender
Male
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Titmar's Achievements

Tree Puncher (2/8)
0
Reputation
-
I probably should do that, yeah. Works fine now!
-
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 is... https://github.com/titmar/Caravans/blob/main/src/main/java/io/github/titmar/caravans/common/container/MarketContainer.java
-
Nvm, the error does not seem to come from the slot by itself but from somwhere else. Currently investigating.
-
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?
-
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 part of the chest but now im getting an unlocated IndexOutOfBoundsException. I cant trace it back to where the issue is exactly. Maybe Im just overcomplicating things and there is a easier way. Anyway here the code from the container class: LockedSlot is just a extension of Slot where you cant put and take items from. And the error log:
-
[1.16.4] Display Inventory of a different container
Titmar replied to Titmar's topic in Modder Support
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. -
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.
-
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
-
[1.16.4] Display Inventory of a different container
Titmar replied to Titmar's topic in Modder Support
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 override the Container::detectAndSendChanges method since it uses said private field of listeners making it inaccessible for child classes. Also, when I call above function setActiveInventory from my Screen class, does that even solve the whole sync issue? Or is there a standard way of doing this? Since opening the GUI creates a new Container every time and I cant access that from anywhere... -
[1.16.4] Display Inventory of a different container
Titmar replied to Titmar's topic in Modder Support
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. -
[1.16.4] Display Inventory of a different container
Titmar replied to Titmar's topic in Modder Support
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? -
[1.16.4] Display Inventory of a different container
Titmar replied to Titmar's topic in Modder Support
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 -
[1.16.4] Display Inventory of a different container
Titmar replied to Titmar's topic in Modder Support
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 official mappings? And if not, will it in the near future? Or will you support both for now? -
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 = te.getSizeInventory(); this.activeInventory = NonNullList.create(); for(int i = 0; i < size; i++) { this.activeInventory.add(te.getStackInSlot(i)); } } What am I missing. Is there a better way to read an inventory of a different block? Going the normal way via the container does not work either since that field is protected as well.
-
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. Thank you for your help!