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, i'm trying to read strings from NBT. i have attached the code for read and write.

My problem is that he reads the both Strings groupName and ownerName and set the fields in the entity. but when i acces them in the onBlockActivated method, they are empty.

For the Inventory stuff, everything work fine O.o but i'm using the same method for the groupName and the ownerName. Can someone explain me the odd behavior or say me how to fix this ?

 

public void writeToNBT(NBTTagCompound par1)
   {
      super.writeToNBT(par1);
      
          NBTTagList itemList = new NBTTagList();
          for (int i = 0; i < inv.length; i++) {
                  ItemStack stack = inv[i];
                  if (stack != null) {
                          NBTTagCompound tag = new NBTTagCompound();
                          tag.setByte("Slot", (byte) i);
                          stack.writeToNBT(tag);
                          itemList.appendTag(tag);
                  }
          }
          par1.setTag("Inventory", itemList);
      
          NBTTagList theMatterSettings = new NBTTagList();
          NBTTagCompound baseMatter = new NBTTagCompound();
          baseMatter.setString("groupName", groupName);
          baseMatter.setString("ownerName", ownerName);
          
          theMatterSettings.appendTag(baseMatter);
          
          par1.setTag("thematter", theMatterSettings);
          
      NBTTagList groupMembers2 = new NBTTagList();

  
      for(String name:groupMembers)
      {
    	  NBTTagCompound tagName = new NBTTagCompound();
    	  tagName.setString("name", name);
    	  groupMembers2.appendTag(tagName);
      }

      
      par1.setTag("themattergroupmembers", groupMembers2);
      
      System.out.println("Write to NTB");
      System.out.println(groupName);
      
   }

   @Override
   public void readFromNBT(NBTTagCompound par1)
   {
      super.readFromNBT(par1);
          
          NBTTagList tagList = par1.getTagList("Inventory",par1.getId());
          for (int i = 0; i < tagList.tagCount(); i++) {
                  NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
                  byte slot = tag.getByte("Slot");
                  if (slot >= 0 && slot < inv.length) {
                          inv[slot] = ItemStack.loadItemStackFromNBT(tag);
                  }
          }
          
          NBTTagList theMatterSettings = par1.getTagList("thematter",par1.getId());

          if(theMatterSettings.tagCount() > 0)
          {
        	  NBTTagCompound baseMatter =theMatterSettings.getCompoundTagAt(0);
        	  
        	  groupName = baseMatter.getString("groupName");
    	      ownerName = baseMatter.getString("ownerName");
    	      
    	      NBTTagList groupTagList = par1.getTagList("themattergroupmembers",par1.getId());
    	      
    	      groupMembers.clear();
    	      
    	      for (int i = 0; i < groupTagList.tagCount(); i++) {
    	    	  groupMembers.add(groupTagList.getCompoundTagAt(i).getString("name"));
    		}
          }
        	  
      System.out.println("Read from NTB");

      System.out.println(this.groupName);
   }

 

//EDIT:

Found the bug. The values are only set on the server (world.isRemote=false). is there a way to automatically sync the entity with the client?

  • Author

Ich gehe mal davon aus das du Deutsch bist (wegen dem Namen)

 

Nee ich setze in dem Entity den Namen des Spielers dem der Block gehört. Derjenige kann mit nem bestimmten Gegenstand den Block aktivieren und andere nicht. Darum muss ich den Owner zum Client syncen.

  • Author

Yes i know this. i do the checks on the server not on the client. The informations are only for the GUI. i used the SimleNetworkWrapper now to send Changes to the client who stores the informations in the entity, is that a good way?

  • Author

Okay THX then i have to use a handler ^^. i will notice u in my credits when i release the mod

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.