Jump to content

Recommended Posts

Posted

Hi all,

I'm trying to add some properties to the player, and it's not correctly working.  Through some system.out.println()'s, I know it is saving, loading, and initializing my properties, it's just not applying them to the player.  I remember reading something old about properties, and packets, but I can't find it anymore and I'm not sure. 

My properties code:

 

package ninjapancakes87.civilwar;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;

public class ExtendedProperties implements IExtendedEntityProperties{

/**The number of soldiers hired by the player*/
private int armySize;

/**Whether the player has hired a Union or Confederate soldier*/
private boolean isUnion;

public int getArmySize(){
	return this.armySize;
}

public void setArmySize(int par1){
	this.armySize = par1;
}

public boolean getIsUnion(){
	return this.isUnion;
}

public void setIsUnion(boolean par1){
	this.isUnion = par1;
}

@Override
public void saveNBTData(NBTTagCompound compound) {
	compound.setBoolean("isUnion", isUnion);
	compound.setInteger("armySize", armySize);
}

@Override
public void loadNBTData(NBTTagCompound compound) {
	this.isUnion = compound.getBoolean("isUnion");
	this.armySize = compound.getInteger("armySize");
}

@Override
public void init(Entity entity, World world) {
	if(entity instanceof EntityPlayer){
		EntityPlayer player = (EntityPlayer)entity;
	}
}
}

 

I previously had it work by calling EntityPlayer.getEntityData(), but that doesn't vary between worlds like I want it to.

Posted

If everything is saving and loading properly, then you're fine. The problem is that the client-side data is not automatically synchronized, so you have to do it yourself.

 

Either:

a) send a packet to the client with the data and set it manually; this is best done from somewhere like the EntityJoinWorldEvent to avoid NPE of the client-side properties

 

b) use DataWatcher to store your data instead of class fields; advantage is that everything else is automatic; disadvantage is you are using an extremely limited resource (data watcher slots)

 

There are tutorials on the Forge wiki about both packets and data watcher, both of which are referenced on this list:

http://mazetar.com/mctuts/displayTutorials.php

 

Alternatively, you can check out my tutorial on IExtendedEntityProperties here:

http://www.minecraftforum.net/topic/1952901-eventhandler-and-iextendedentityproperties/#entry24051513

Posted

If everything is saving and loading properly, then you're fine. The problem is that the client-side data is not automatically synchronized, so you have to do it yourself.

 

Either:

a) send a packet to the client with the data and set it manually; this is best done from somewhere like the EntityJoinWorldEvent to avoid NPE of the client-side properties

 

b) use DataWatcher to store your data instead of class fields; advantage is that everything else is automatic; disadvantage is you are using an extremely limited resource (data watcher slots)

 

There are tutorials on the Forge wiki about both packets and data watcher, both of which are referenced on this list:

http://mazetar.com/mctuts/displayTutorials.php

 

Alternatively, you can check out my tutorial on IExtendedEntityProperties here:

http://www.minecraftforum.net/topic/1952901-eventhandler-and-iextendedentityproperties/#entry24051513

I do know how to use datawatcher (never used packets, so I'm going to avoid that route), but thanks for the tip.  I looked at your tutorial, and the only question I have is should I add the watcher in the init method of my ExtendedProperties class?

Posted

You can add datawatcher in either the init or in the constructor, doesn't really matter since init is called during class construction anyway.

Thanks!

 

But on a side note, in your tutorial it does say you haven't found a use for your Init method. You have figured out what that does, correct?

Posted

But on a side note, in your tutorial it does say you haven't found a use for your Init method. You have figured out what that does, correct?

It's the same as entityInit in Entity classes; it gets called during entity construction, so you could put the exact same code in your constructor and it would have the same effect. The benefit of the init method in IExtendedEntityProperties is that it provides a world object, but I haven't found it (the extra world parameter) particularly useful because the entity itself isn't yet finished constructing.

Posted

But on a side note, in your tutorial it does say you haven't found a use for your Init method. You have figured out what that does, correct?

It's the same as entityInit in Entity classes; it gets called during entity construction, so you could put the exact same code in your constructor and it would have the same effect. The benefit of the init method in IExtendedEntityProperties is that it provides a world object, but I haven't found it (the extra world parameter) particularly useful because the entity itself isn't yet finished constructing.

I know, just wanted to make sure :P

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

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