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.

TrickShotMLG

Members
  • Joined

  • Last visited

  1. I am fairly new to mod programming and I am currently trying to create a GUI with a TextField where I can enter a text and store this input in the EntityBlock class of my specific block within a variable. I can open the GUI and the input field is working, but the input data is not transferred to the EntityBlock persistently. This is the init code with the logic for storing the entered text on the button click, which is in my screen class. @Override protected void init() { super.init(); // Create widgets portalNameTextField = new EditBox( this.font, this.leftPos + 7, this.topPos + 11, 150, 20, Component.literal("") ); setPortalNameButton = new Button.Builder( Component.literal("OK"), (button) -> { // copy text field value to portal name variable this.menu.blockEntity.portalName = portalNameTextField.getValue(); // set data stored as dirty this.menu.blockEntity.setChanged(); } ) .pos(20, 20) .size(50, 20) .build(); // Focus the screen this.setFocused(true); // Add Widgets this.addRenderableWidget(portalNameTextField); this.addRenderableWidget(setPortalNameButton); setPortalNameButton.active = true; // Trying to set the focus on the widget portalNameTextField.setCanLoseFocus(false); portalNameTextField.active = true; portalNameTextField.setFocused(true); } This is the code from my BlockEntity @Override public void load(CompoundTag nbt) { super.load(nbt); // Load stored portal name from nbt data CompoundTag portablePortalsModData = nbt.getCompound(PortablePortalsMod.MODID); this.portalName = portablePortalsModData.getString("PORTAL_NAME"); System.out.println("LOADING DATA: " + nbt); } @Override public void saveAdditional(CompoundTag nbt) { super.saveAdditional(nbt); // Save stored portal name to nbt data var portablePortalsModData = new CompoundTag(); portablePortalsModData.putString("PORTAL_NAME", this.portalName); nbt.put(PortablePortalsMod.MODID, portablePortalsModData); System.out.println("SAVING DATA: " + nbt); } However the console shows the following output, which is the default value that is stored as nbt and not the changed value Screenshot of console and screen Anybody got an idea how I could fix this problem to store the text input persistent in the block entity?

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.