Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello,

im trying to create a Tile Entitie with Inventory and GUI that changes the content of the inventory when a button on the gui is clicked. my problem is that the change to the inventoy does not really get saved. when i click the button i see the content change, but when i close the gui and reopen it its back to pre button click.

Container: https://github.com/robertusengel/aoemod/blob/master/blocks/towncentergui/ContainerTowncenter.java

GuiContainer: https://github.com/robertusengel/aoemod/blob/master/blocks/towncentergui/GuiTowncenter.java

TileEntity: https://github.com/robertusengel/aoemod/blob/master/blocks/towncentergui/TileEntityTowncenter.java

Message: https://github.com/robertusengel/aoemod/blob/master/network/TowncenterMessage.java

 

i hope i didnt forget anything relevant

 

thanks in advance

The only button in your GUI that tells the server to do anything is the last one, TowncenterButtons.PLUS. None of the other buttons send a packet to the server and the server is the one in charge and the only one that can save data.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

@Draco18s

sry should have specified that, TowncenterButtons.PLUS is the button im talking about

 

https://github.com/robertusengel/aoemod/blob/80ca12cd420ca9b2879f54841edbfaeca5936678/network/TowncenterMessage.java#L47

thats the line that basicially changes it, but doesnt really save it

the test method is in the tile entity

public void test() {
		inventory.extractItem(0, 10, false);
		this.markDirty();
	}

 

Edited by Robertusxd

Put a breakpoint there. Does it ever get run?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Are you me?

I have been struggling with this for a week now

 

everything gets registered fine, the game loads fine, the console prints out fine, the functions get called fine, the new item even stacks on itself fine, the new item just evaporates when i try to move it, or when i reload the gui.

  • Author

Yes it does get run because the inventory in the gui actually changes, but it seems like the changes dont get saved.

i uploaded a short video that hopefully explains the problem better

https://youtu.be/DvVKD6hG7lY

@glassManMCID20 hope we both find a solution here :P if u find a solution somewhere else please let me know

2 hours ago, glassManMCID20 said:

Are you me?

I have been struggling with this for a week now

 

everything gets registered fine, the game loads fine, the console prints out fine, the functions get called fine, the new item even stacks on itself fine, the new item just evaporates when i try to move it, or when i reload the gui.

Have you checked that the function runs on the server side. That's why you should use break points. Look at what the game is doing, make sure it is correct. 

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

5 hours ago, Draco18s said:

Have you checked that the function runs on the server side. That's why you should use break points. Look at what the game is doing, make sure it is correct. 

Actually, that was the point i got to that is beyond me. I can debug, i can get console messages, i can check locals and function returns...

 

and while the message context says its on the server, but forge documentation says you can't use the in-code like Side or world.isRemote methods to double check that, and when i do use them they say its on the client

 

And i  have made sure the message is being registered to execute on the server, and its only called in one place on the client


//registration

INSTANCE.registerMessage(MessageCustomButtonPressed.MessageCustonButtonPressedHandler.class, MessageCustomButtonPressed.class, 0, Side.SERVER);


//only on button press

ModNetworkHandler.sendToServer(new MessageCustomButtonPressed(GUIHandler.GuiIDs.DUPLICATIONTABLE.ordinal(), myTable.getPos()));

 

//message handling
 

@Override
        public IMessage onMessage(MessageCustomButtonPressed message, MessageContext ctx) {

            EntityPlayerMP serverPlayer = ctx.getServerHandler().playerEntity;

            if(ctx.side == Side.SERVER) {
                handleServerSide(message, serverPlayer);
            }

            return null;
        }


        public void handleServerSide(MessageCustomButtonPressed message, EntityPlayer player) {

            switch(GUIHandler.GuiIDs.values()[message.guiID]){
            case DUPLICATIONTABLE:
                System.out.println("You pressed the dupe button");
                final TileEntityDuplicationTable entity =((TileEntityDuplicationTable) Minecraft.getMinecraft().world.getTileEntity(message.blockPosition));
                player.getServer().addScheduledTask(new Runnable() {
                    
                    @Override
                    public void run() {
                        entity.duplicate();
                        
                    }
                });
                break;
            default:
                break;
            }
        }

           

 

The entity duplicate function IS being called once, but like i said the methods i know of think its on the client side, while the message context ctx say its server side

36 minutes ago, glassManMCID20 said:

Minecraft.getMinecraft()

This is SideOnly(CLIENT)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

2 hours ago, Draco18s said:

This is SideOnly(CLIENT)

You beautiful bastard you

That has probably been my problem the whole time

Changed it to use the message provided players reference to the world,

final TileEntityDuplicationTable entity =((TileEntityDuplicationTable) player.world.getTileEntity(message.blockPosition));

passed from the message context

 

It seems to be duplicating without issue now, i can relog, pick it up everything!
 

Spoiler

 

Id suk yur cauck :^)

 

 

Robetusxd, I hope this helped, or that Draco18s helps you too.

Edited by glassManMCID20

  • Author

oh wow, i did the exact same thing you did, i knew Minecraft.getMinecraft() was client side but apparently i still used it anyways. 

thanks alot

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.