Jump to content

Recommended Posts

Posted

I am working on a flower which should save the player that makes a shift-right click on it, but I can't figure out how to save the player entity.

I know how NBT works, and I try to save the player's username in that block and then get the EntityPlayer from the username again, but it doesn't seem to work.

This is the flower code (Note that my mod should be a Botania Addon):

 

  Reveal hidden contents

 

 

EDIT:

I fixed it now.

I no longer use EntityPlayer but the GameProfile and made some other adjustments to the NBT saving / loading, took out the debug stuff with the second saving etc.

For anyone interested, here's what the code now looks like:

 

  Reveal hidden contents

 

 

Thank you for your help anyway :)

Posted
  On 6/20/2015 at 4:20 PM, Failender said:

Define "doenst seem to work"

When are you triing to access the information and how

In "onBlockActivated" it will print out the Bound Player and the seconds the tile existed. When I shift right click it will bind myself to it and then everytime I right click it it will print my username and the time the tile existed. When I log out and log in, and right click the tile, it will print "null", as in no player is bound to it, so it didn't save properly.

 

  Quote

You need to mark dirty when the player is set, or else it will not save

I don't think this is the case because it saves the seconds the tile existed properly, but I will try in a bit

Posted

Have you tried to save player's UUID instead?

 

Because when you have the UUID you can just look up the player whose UUID it is.

If my post helped you, please press that "Thank You"-button to show your appreciation.

 

Also if you don't know Java, I would suggest you read the official tutorials by Oracle to get an idea of how to do this. Thanks, and good modding!

 

Also if you haven't, set up a Git repo for your mod not only for convinience but also to make it easier to help you.

Posted
  On 6/20/2015 at 4:33 PM, tiffit said:

You need to mark dirty when the player is set, or else it will not save

Still same result :/

 

  Quote

Have you tried to save player's UUID instead?

 

Because when you have the UUID you can just look up the player whose UUID it is.

You mean like this?

@Override
public void writeToPacketNBT(NBTTagCompound cmp) {
	super.writeToPacketNBT(cmp);
	if(player == null){
		cmp.setString(TAG_PLAYER, "");
	} else {
		cmp.setString(TAG_PLAYER, player.getPersistentID().toString());
	}
	cmp.setInteger(TAG_SECONDS, seconds);
}

@Override
public void readFromPacketNBT(NBTTagCompound cmp) {
	super.readFromPacketNBT(cmp);
	String str = cmp.getString(TAG_PLAYER);
	if(str != null && !str.equals("")){
		UUID uuid = UUID.fromString(str);
		if(uuid == null){
			player = null;
		} else {
			String playerName = MinecraftServer.getServer().func_152358_ax().func_152652_a(uuid).getName();
			player =  MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName);
		}
	}
	seconds = cmp.getInteger(TAG_SECONDS);
}

When I reload the world the flower transforms into "Botania Flower", which you only get when something went wrong. So that doesn't work either, or am I using it wrong?

Posted

You should check for !isRemote on the worldObj in your onBlockActivated, so it gets only processed on server side and the server sends all needed informations to the client.

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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