Posted December 17, 20195 yr Hello guys, Today I encounter another problem. I have trouble doing the good choice when it comes to forge modding. I want to sync a GUI with my tile entity. I know that blocks such as furnace use a Container to sync the whole thing. But in my case I don't need the player inventory at all and I don't care about slots. It is just bunch of variables. So do I really need a container or maybe I can use something else and if that so what can I use ? PS: I could just update my client side tile entity at the same time of my server side tile entity into my GUI but I am not sure it is a good idea... Edited December 17, 20195 yr by dylandmrl
December 17, 20195 yr Author Ok so even if I don't handle any inventory, I still have to implement a container. I have no experience on it at all but I think that I will find enough ressource on internet, thank you very much.
December 19, 20195 yr Author Ok I've implemented the container but I don't understand how to properly handle the "detectAndSendChanges" function. My tile entity contains a rather complex structure and I only see this function: "listener.sendWindowProperty(this, varToUpdate, newValue);" to communicate a change or, I need to change a whole structure which is not only composed of ints... Also, I can't access the listeners list since the variable is private.
December 19, 20195 yr Author Ah yes this was my bad trully sorry, however my main problem is still the same, how can I send a "complex change" I mean, I don't have an array of int inside my tile entity but a list of list that store several values. I can't just update the whole data structure when I observe a changement ?
December 19, 20195 yr Author Ok so basically, when I detect a change, I need to send a packet to each player using listener that I am getting using reflexion to update their client tile entity based on my server side tile entity and my container will retrieve the data from their own tile entity ? Edited December 19, 20195 yr by dylandmrl
December 20, 20195 yr Author For people who don't know how to do, I have something like : Inside your container: public void detectAndSendChanges() { super.detectAndSendChanges(); if(this.tileEntity.isDifferent()){ this.tileEntity.setDifferent(false); Field f = null; try { f = Container.class.getDeclaredField("listeners"); f.setAccessible(true); try { List<IContainerListener> listOfListeners = (List<IContainerListener>) f.get(this); //IllegalAccessException for(IContainerListener listener: listOfListeners){ if(listener instanceof PlayerEntity){ // Send the packet } } } catch (IllegalAccessException e) { e.printStackTrace(); } } catch (NoSuchFieldException e) { e.printStackTrace(); } } } Correct me if I am wrong but normally everything is ok! isDifferent is set as true if the tileentity receive any modification. Basically I have a function that make the tile entity dirty and put this variable to true at the same time.
December 22, 20195 yr Author Okay I have tried to figure out how to do without blowing everything (I have certainly made mistakes again): 12 hours ago, diesieben07 said: That field will not be called "listeners" outside the development environment. You need to use ObfuscationReflectionHelper.findField with a SRG name. This will also call setAccessible for you. Do not look up the Field instance every time. Do it once and store it in a static final field (both modifiers are important to allow the JVM to optimize this reflective access). public static Field field = ObfuscationReflectionHelper.findField(Container.class, "field_177758_a"); I have found "field_177758_a" as an equivalent of listeners in the website that you provided. 12 hours ago, diesieben07 said: That is not how you handle exceptions. Ever. try { List<IContainerListener> listOfListeners = (List<IContainerListener>) DCContainer.field.get(this); for(IContainerListener listener: listOfListeners){ if(listener instanceof ServerPlayerEntity){ this.sendUpdate(listener); } } } catch (IllegalAccessException e) { Debugger.error(e); } For this one, I am not sure at all.
December 22, 20195 yr Author Okay I got it, everything should be fine now. Thank you very much to take your time like this! The Debugger class is mine but I will just create my own exception and throw something instead.
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.