Jump to content

Recommended Posts

Posted

I used this tutorial from CoolAlias, taht one with the Extended Player Properties, but it seems like the event is fired, but it doesn't save the NBT, and I can't figure out why

 

public class PlayerProperties implements IExtendedEntityProperties
{

public final static String EXT_PROP_NAME = "IntektorsProperties";

private final EntityPlayer player;

public int researchState;

public PlayerProperties(EntityPlayer player)
{
	this.player = player;
}

public static final void register(EntityPlayer player)
{
	player.registerExtendedProperties(PlayerProperties.EXT_PROP_NAME, new PlayerProperties(player));
}

public static final PlayerProperties get(EntityPlayer player)
{
	return (PlayerProperties) player.getExtendedProperties(EXT_PROP_NAME);
}

@Override
public void saveNBTData(NBTTagCompound compound)
{
	NBTTagCompound properties = new NBTTagCompound();
	properties.getInteger("Research");
	compound.setTag(EXT_PROP_NAME, properties);
}

@Override
public void loadNBTData(NBTTagCompound compound)
{
	NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
	this.researchState = properties.getInteger("Research");
}

@Override
public void init(Entity entity, World world)
{

}

}

 

The event is fireds, I checked this, but it creates the Properties every time again

 

@SubscribeEvent
public void onEntityContructionEvent(EntityConstructing event){
	if(event.entity instanceof EntityPlayer && PlayerProperties.get((EntityPlayer) event.entity) == null){
		PlayerProperties.register((EntityPlayer) event.entity);
	}
}

 

 

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

@Override
public void saveNBTData(NBTTagCompound compound)
{
	NBTTagCompound properties = new NBTTagCompound();
	properties.getInteger("Research");
	compound.setTag(EXT_PROP_NAME, properties);
}

@Override
public void loadNBTData(NBTTagCompound compound)
{
	NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
	this.researchState = properties.getInteger("Research");
}
}

 

properties.getInteger("Research");

VVV

properties.setInteger("Research", this.researchState);

1.7.10 is no longer supported by forge, you are on your own.

Posted

What exactly makes you think it is not saved? How do you check it? Also how is "researchState modified?

 

First of all, this line of code

 

PlayerProperties.get((EntityPlayer) event.entity) == null

 

should make sure to only create a new instance of the properties, if there isn't already one, shouldn't it?

 

Also, when I use my update method

 

@Override
public void updateEntity() {
	if(theUser != null){
		finishedNBT.setBoolean(theUser.getDisplayName(), true);
		System.out.println(PlayerProperties.get(theUser).researchState + "" + FMLCommonHandler.instance().getEffectiveSide());
	}
}

 

it prints 0 on both Client and Server, although

 

PlayerProperties.get(theUser).researchState++;
			ModArmMod.network.sendToServer(new ClientToServerMessage(7, new int[]{tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord}));

in my gui

 

if(message.ID == 7){
			TileEntityArmorModifier tileEntity = (TileEntityArmorModifier) ctx.getServerHandler().playerEntity.getEntityWorld().getTileEntity(message.extra[0], message.extra[1], message.extra[2]);
			PlayerProperties.get(tileEntity.theUser).researchState++;
		}

 

and thats it

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

@Override
public void saveNBTData(NBTTagCompound compound)
{
	NBTTagCompound properties = new NBTTagCompound();
	properties.getInteger("Research");
	compound.setTag(EXT_PROP_NAME, properties);
}

@Override
public void loadNBTData(NBTTagCompound compound)
{
	NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
	this.researchState = properties.getInteger("Research");
}
}

 

properties.getInteger("Research");

 

#setInteger

 

 

thanks, but it won't cfhange anything if there is every time a new instance created

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

There is a new instance created when the player is created, there is nothing wrong with that.

 

hm ok, but why the hell is it 0 then

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

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.