Jump to content

[1.7.10] Problems with Extended properties


Elix_x

Recommended Posts

Hello, so my problem is this:

Entity properties registered twice, initialized twice, but loaded (readFromNbt) only once, what results in nulliffing of data;

This happens like this (Checked via console);

-register (EntityConstruct)

-init (Propery.init)

-load (Propery.readFromNbt)

-register

-init

All the code that you may want here is EntityConstructEvent, but if you need something else - just ask:

public class OnEntityConstructEvent {

public OnEntityConstructEvent() {

}

@SubscribeEvent
public void construct(EntityConstructing event){
	if(event.entity instanceof EntityPlayer){
		if(event.entity.getExtendedProperties("breathing") == null){
			System.out.println("Registered new propreties on " + FMLCommonHandler.instance().getSide() + " old propreties: " + event.entity.getExtendedProperties("breathing"));
			event.entity.registerExtendedProperties("breathing", new ExtendedBreathingProperties());
		}
	}
}
}

 

Thanks for help, and again: if you need something(code/console/...) - just ask!

Link to comment
Share on other sites

The code looks good. It literally can't be source of any problems.

 

What happens:

Server creates entity, registers IEEP, loads NBT.

Then client creates same entity, registers IEEP, but never loads (NBT is server-sided).

 

Someone here is confused - question is - is it me or you?

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

Link to comment
Share on other sites

Please describle nullified.

Without using packets on client side you will end up with fresh IEEP object.

On server it will be the same, unless you load something from NBT - what are you loading, why do you say it's nullified? Do you mean that WHOLE IEEP object just disappears (because that's what nullified means for me)?

Post readNBT maybe.

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

Link to comment
Share on other sites

Please describle nullified.

Without using packets on client side you will end up with fresh IEEP object.

On server it will be the same, unless you load something from NBT - what are you loading, why do you say it's nullified? Do you mean that WHOLE IEEP object just disappears (because that's what nullified means for me)?

Post readNBT maybe.

I mean all lists become empty, booleans defaults to false and ints to 0. This includes both slient&server!!! (why???)

IEEP:

public class ExtendedBreathingProperties implements IExtendedEntityProperties{

private boolean breathing;
private Set<BreathEffect> effects = new HashSet<BreathEffect>();

public ExtendedBreathingProperties() {
	setBreathing(false);
}

public boolean isBreathing() {
	return breathing;
}

public void setBreathing(boolean breathing) {
	this.breathing = breathing;
}

public void addEffect(BreathEffect effect){
	effects.add(effect);
}

public void removeEffect(BreathEffect effect){
	effects.remove(effects);
}

public Set<BreathEffect> getEffects(){
	return effects;
}

@Override
public void saveNBTData(NBTTagCompound nbt) {
	NBTTagCompound tag = new NBTTagCompound();
	NBTTagCompound es = new NBTTagCompound();
	int a = 0;
	for(BreathEffect effect : effects){
		es.setTag("eN" + a, effect.writeToNBT(new NBTTagCompound()));
		a++;
	}
	es.setInteger("lenght", a);
	tag.setTag("effects", es);
	tag.setBoolean("breathing", breathing);
	nbt.setTag("breathing", tag);

	BreathEffectManager.logger.info("Saving propreties data to nbt: " + tag + " on " + FMLCommonHandler.instance().getSide());
}

@Override
public void loadNBTData(NBTTagCompound nbt) {
	NBTTagCompound tag = nbt.getCompoundTag("breathing");
	NBTTagCompound es = tag.getCompoundTag("effects");

	BreathEffectManager.logger.info("Loading propreties data from nbt: " + tag + " on " + FMLCommonHandler.instance().getSide());

	for(int a = 0; a < nbt.getInteger("lenght"); a++){
		try {
			effects.add(BreathEffect.createFromNBT(es.getCompoundTag("eN" + a)));
		} catch (Exception e) {
			BreathEffectManager.logger.warn("Caught exception while restoring effect: ", e);
		}
	}
	breathing = tag.getBoolean("breathing");
}

@Override
public void init(Entity entity, World world) {
	BreathEffectManager.logger.info("Initializing proprieties on " + FMLCommonHandler.instance().getSide());
}

}

Link to comment
Share on other sites

for(int a = 0; a < nbt.getInteger("lenght"); a++){

 

Doing this will leave you with either 0 or null therefore list will be empty/readNBT will crash (catch error). I don't remember what getInteger returns for not-found keys.

 

You made simple typo mistake :)

 

Edit: If you didn't get me - "nbt" should be "es".

 

Edit 2:

I highly recommend using TagList, which has build-in lenght. You can do effect.writeToNBT directly onlo tag in list.

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

Link to comment
Share on other sites

Facepalm... typo mistake... :)

And i was not using list, beacause i'm a litle bit confused how to use it... Well i'll try how ever...

 

EDIT: well, i'm still confused about them...

 

EDIT 2: it was typo mistake... again...

 

Link to comment
Share on other sites

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.