Jump to content

[UNSOLVED]Problem with IExtendedEntityProperties


ItsAMysteriousYT

Recommended Posts

Im trying to properly register IEE, but they are not saved probably. I can't make out the problem.

Here are the classes and where i register the IEE:

IEE-Class:

 

 

package itsamysterious.mods.reallifemod.core.lifesystem;

 

import net.minecraft.client.entity.EntityPlayerSP;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.util.BlockPos;

import net.minecraft.util.EnumParticleTypes;

import net.minecraft.world.World;

import net.minecraftforge.common.IExtendedEntityProperties;

 

public class RLMPlayerProps implements IExtendedEntityProperties {

 

protected EntityPlayer player;

protected World theWorld;

 

public String name;

public String surname;

 

public double toilet;

public double water;

private int timeWaterless = 0;

private int waterlowmessagetime = 0;

public float money;

public double energy;

public double stamina;

private int gender;

 

public boolean shownGui;

 

public static final String EXT_PROP_NAME = "RealLifeProperties";

 

public RLMPlayerProps(EntityPlayer player) {

this.player=player;

}

 

public static final void register(EntityPlayer player){

player.registerExtendedProperties(EXT_PROP_NAME, new RLMPlayerProps(player));

}

 

public static final RLMPlayerProps get(EntityPlayer player) {

return (RLMPlayerProps) player.getExtendedProperties(EXT_PROP_NAME);

}

 

public void circleOfLife() {

if (player != null && !player.capabilities.isCreativeMode) {

this.theWorld=this.player.worldObj;

if (water > 0.1) {

water -= 0.00138888889D;

}

 

if (toilet < 100) {

toilet += 0.00415151515151515D;

}

 

updateEffects();

}

 

}

 

private void updateEffects() {

if (!player.worldObj.isRemote) {

if (water < 40 &&water>10&& waterlowmessagetime % 200 == 0) {

player.addChatComponentMessage(LinesHelper.ThirstWarning);

 

}

if (water < 10&&water>0.1) {

player.addChatComponentMessage(LinesHelper.ThirstWarning2);

player.addPotionEffect(new PotionEffect(Potion.confusion

.getId(), 100));

} else if (player.getActivePotionEffect(Potion.confusion) != null) {

player.removePotionEffect(Potion.confusion.id);

}

 

if (water < 0.1) {

player.addPotionEffect(new PotionEffect(

Potion.weakness.getId(), 100));

timeWaterless++;

if (timeWaterless == 200) {

player.addChatComponentMessage(LinesHelper.DyingOfThirst);

player.setHealth(player.getHealth() - 1);

}

 

 

}

// Toilet stuff

if (toilet > 50) {

player.addPotionEffect(new PotionEffect(Potion.digSlowdown

.getId(), 1));

} else {

player.removePotionEffect(Potion.digSlowdown.getId());

}

 

}

 

 

 

}

 

@Override

public void saveNBTData(NBTTagCompound compound) {

NBTTagCompound theTag = new NBTTagCompound();

compound.setTag(EXT_PROP_NAME, theTag);

if (player != null) {

theTag.setDouble("WATER", water);

theTag.setDouble("TOILET", toilet);

theTag.setFloat("MONEY", money);

theTag.setString("NAME", name);

theTag.setString("SURNAME", surname);

theTag.setDouble("ENERGIE", energy);

theTag.setBoolean("GUISHOWN", shownGui);

theTag.setInteger("GENDER", gender);

player.writeEntityToNBT(compound);

}

}

 

@Override

public void loadNBTData(NBTTagCompound compound) {

NBTTagCompound theTag = compound.getCompoundTag(EXT_PROP_NAME);

if (player != null) {

water = theTag.getDouble("WATER");

toilet = theTag.getDouble("TOILET");

money = theTag.getFloat("MONEY");

name = theTag.getString("NAME");

surname = theTag.getString("SURNAME");

energy = theTag.getDouble("ENERGIE");

shownGui=theTag.getBoolean("GUISHOWN");

gender=theTag.getInteger("GENDER");

}

}

 

@Override

public void init(Entity entity, World world) {

if (entity instanceof EntityPlayer) {

player = (EntityPlayer) entity;

water=100;

toilet=0;

}

}

 

public void pee() {

while(toilet>0){

toilet-=1;

}

}

 

public static String getGender(EntityPlayer player){

if(get(player).gender==0){

return"male";

}else

return "female";

}

 

public void setGender(String s){

if(s.equals("male")){

gender=0;

}else

gender=1;

}

 

public boolean requestMariage(EntityPlayer requester){

return true;

}

 

public static final String getFullname(EntityPlayerSP thePlayer) {

return get(thePlayer).name+" "+get(thePlayer).surname;

}

 

}

 

 

 

Registration in the ClientHandler registered to MinecraftForge.EVENT_BUS:

 

 

@SubscribeEvent

public void onEntityConstructing(EntityConstructing event) {

if (event.entity instanceof EntityPlayer) {

event.entity.registerExtendedProperties(RLMPlayerProps.EXT_PROP_NAME,

new RLMPlayerProps((EntityPlayer) event.entity));

}

}

 

 

Link to comment
Share on other sites

In your event

 

try "RLMPlayerProps.register((EntityPlayer) event.entity))

 

instead of "event.entity.registerExtendedProperties(RLMPlayerProps.EXT_PROP_NAME, new RLMPlayerProps((EntityPlayer) event.entity);"

 

you don't really need to have that in two places.

 

 

Now,

for your problem on not saved, I believe it is because you are overwriting the data each time.  you need to check for the property to exist before writing it.

 

Add this to your property:

 

 

 

public static final ExtendedPlayer get(EntityPlayer player) {

return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);

}

 

 

 

In your construction

 

 

 

  @SubscribeEvent

  public void onEntityConstructing(EntityConstructing event) {

      if (event.entity instanceof EntityPlayer) {

        if (RLMPlayerProps.get((EntityPlayer) event.entity) == null) {RLMPlayerProps.register((EntityPlayer) event.entity);}

      }

  }

 

 

 

I suspect you used Jabelar's tutorial (which is great) but from looking at it, its a one time horse, not a long term recuring entity like the player.

 

I originally used this one to learn it.

 

https://github.com/coolAlias/Forge_Tutorials/blob/master/IExtendedEntityPropertiesTutorial.java

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Ok, first things first, your handling of names and gender is horribly incomplete and irritating (if you want to learn more,

Edit:
, but the other one is good, too. /edit).

Also that "pee" method is a joke. It is equivalent to just doing "toilet = 0" (which the JVM will probably optimize it to, but still).

 

Now: What makes you think that the data is not properly saved? What are the symptoms?

When i spawn in the world the guiscreen pops back up in which ive set the name and gender before. probably this is cuz i don't have the -username argument in JVM-Arguments properly?

Link to comment
Share on other sites

Okay - i tried doing the packethandling stuff but it gives me a svere error and just sais that the packet couldn't be handled also it does not set the properties right. Please help. PS - No errorcode available - just a crash

 

Here is the packagehandler method:

 

 

@Override

public SetPropertiesPackage onMessage(SetPropertiesPackage message, MessageContext ctx) {

EntityPlayer player = ctx.getServerHandler().playerEntity;

World world = player.worldObj;

if(RLMPlayerProps.get(player)!=null){

RLMPlayerProps.get(player).setGender(message.gender);

RLMPlayerProps.get(player).name=message.name;

RLMPlayerProps.get(player).surname=message.surname;

}

return null;

}

 

 

 

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.