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, 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!

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.

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.

  • Author

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());
}

}

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.

("lenght")

 

Never seen that word before. xD

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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.