Skip to content

Commit

Permalink
Last attempt at persistence was stupid... this should fix that.
Browse files Browse the repository at this point in the history
  • Loading branch information
Funwayguy committed Jan 4, 2016
1 parent 3bfcb6e commit 06426ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/main/java/enviromine/core/api/properties/PropertyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import enviromine.core.EnviroMine;
Expand Down Expand Up @@ -129,6 +130,33 @@ public void onLivingUpdate(LivingUpdateEvent event)
}
}

@SubscribeEvent
public void onClone(PlayerEvent.Clone event)
{
for(PropertyType propType : PropertyRegistry.getAllTypes())
{
PropertyTracker track1 = propType.getTracker(event.entityLiving);
PropertyTracker track2 = propType.getTracker(event.original);

if(track1 == null || track2 == null)
{
continue;
}

if(!event.wasDeath || propType.isPersistent())
{
NBTTagCompound tags = new NBTTagCompound();
track2.saveNBT(tags);
track1.loadNBT(tags);
} else
{
track1.Reset();
}

track2.onClone(event.original, event.entityPlayer);
}
}

public static void SyncTrackers(NBTTagCompound trackerData, EntityLivingBase entityLiving)
{
if(trackerData == null || entityLiving == null || entityLiving.worldObj.isRemote)
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/enviromine/core/api/properties/PropertyTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public final void saveNBTData(NBTTagCompound compound) // Forwards main tracker
{
NBTTagCompound propTags = new NBTTagCompound();
this.saveNBT(propTags);
compound.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG).setTag("ENVIROMINE_" + type.getTrackerID(), propTags);
compound.setTag("ENVIROMINE_" + type.getTrackerID(), propTags);
}

@Override
public final void loadNBTData(NBTTagCompound compound) // Forwards main tracker tag onto a property specific tag
{
this.loadNBT(compound.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG).getCompoundTag("ENVIROMINE_" + type.getTrackerID()));
this.loadNBT(compound.getCompoundTag("ENVIROMINE_" + type.getTrackerID()));
}

public abstract void saveNBT(NBTTagCompound tags);
Expand All @@ -41,11 +41,6 @@ public void init(Entity entity, World world)
{
if(entity instanceof EntityLivingBase)
{
if(entityLiving != entity)
{
this.onClone(entityLiving, entity);
}

this.entityLiving = (EntityLivingBase)entity;
} else
{
Expand All @@ -59,16 +54,12 @@ public void onSpawn()
{
}

public void onClone(Entity oldEntity, Entity newEntity)
public void onClone(EntityPlayer oldPlayer, EntityPlayer newPlayer)
{
}

public void onDeath()
{
if(!type.isPersistent())
{
this.Reset();
}
}

public void onLivingUpdate()
Expand Down

0 comments on commit 06426ff

Please sign in to comment.