Salut, j’ai un probleme avec mes entity props, elles ne savent pas a ma mort ni quand je deco/reco.
package fr.sosoh.hogsmod.common.entity.props;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import fr.sosoh.hogsmod.common.Hogsmod;
import fr.sosoh.hogsmod.common.packet.PacketMana;
import fr.sosoh.hogsmod.common.packet.PacketSpellLeft;
import fr.sosoh.hogsmod.common.packet.PacketSpellRight;
import fr.sosoh.hogsmod.common.packet.PacketSpellsList;
import fr.sosoh.hogsmod.proxy.CommonProxy;
public class ExtendedEntityProps implements IExtendedEntityProperties
{
public final static String EXT_PROP_NAME = "ExtHogs";
private final EntityPlayer player;
public double mana;
public double maxMana;
public List <string>spellsList = new ArrayList<string>();
public String spellRight, spellLeft;
public ExtendedEntityProps(EntityPlayer player)
{
this.player = player;
this.mana = 1000;
this.maxMana = 1000;
this.spellRight = "";
this.spellLeft = "";
}
@Override
public void init(Entity entity, World world)
{
}
public static final void register(EntityPlayer player)
{
player.registerExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME,
new ExtendedEntityProps(player));
}
public static final ExtendedEntityProps get(EntityPlayer player)
{
return (ExtendedEntityProps) player.getExtendedProperties(EXT_PROP_NAME);
}
@Override
public void saveNBTData(NBTTagCompound compound)
{
NBTTagCompound properties = new NBTTagCompound();
compound.setTag(EXT_PROP_NAME, properties);
properties.setDouble("Mana", this.mana);
properties.setDouble("MaxMana", this.maxMana);
properties.setString("spellRight", this.spellRight);
properties.setString("spellLeft", this.spellLeft);
properties.setInteger("spellsListSize", this.spellsList.size());
if(this.spellsList != null){
for(String spell : this.spellsList)
{
properties.setString("spellsList", spell);
}
}
}
@Override
public void loadNBTData(NBTTagCompound compound)
{
NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
this.mana = properties.getDouble("Mana");
this.maxMana = properties.getDouble("MaxMana");
this.spellRight = properties.getString("spellRight");
this.spellLeft = properties.getString("spellLeft");
int size = properties.getInteger("spellsListSize");
if(size < 0){
for(int i = 0; i < size; i++){
String stringI = this.spellsList.get(i);
this.spellsList.add(i, stringI);
}
}
}
public final void sync()
{
PacketMana packetMana = new PacketMana(this.mana, this.maxMana);
PacketSpellRight packetSpellRight = new PacketSpellRight(this.spellRight);
PacketSpellLeft packetSpellLeft = new PacketSpellLeft(this.spellLeft);
PacketSpellsList packetSpellsList = new PacketSpellsList(this.spellsList);
if (!player.worldObj.isRemote)
{
EntityPlayerMP player1 = (EntityPlayerMP) player;
Hogsmod.network.sendTo(packetMana, player1);
Hogsmod.network.sendTo(packetSpellRight, player1);
Hogsmod.network.sendTo(packetSpellLeft, player1);
Hogsmod.network.sendTo(packetSpellsList, player1);
}
}
private static String getSaveKey(EntityPlayer player)
{
return player.getDisplayName() + ":" + EXT_PROP_NAME;
}
public static void saveProxyData(EntityPlayer player) {
ExtendedEntityProps playerData = ExtendedEntityProps.get(player);
NBTTagCompound savedData = new NBTTagCompound();
playerData.saveNBTData(savedData);
CommonProxy.storeEntityData(getSaveKey(player), savedData);
}
public static void loadProxyData(EntityPlayer player)
{
ExtendedEntityProps playerData = ExtendedEntityProps.get(player);
NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player));
if (savedData != null)
{
playerData.loadNBTData(savedData);
}
playerData.sync();
}
public boolean removeMana(double amount)
{
boolean sufficient = amount <= this.mana;
if (sufficient)
{
this.mana -= amount;
this.sync();
} else
{
return false;
}
return sufficient;
}
public void addMana(double amount)
{
this.mana += amount;
this.sync();
}
public double getMana()
{
return this.mana;
}
public void setMana(double newMana)
{
this.mana = newMana;
this.sync();
}
public double getMaxMana() {
return this.maxMana;
}
public boolean setSpellRight(String spell){
if(this.spellsList.contains(spell)){
this.spellRight = spell;
this.sync();
return true;
}
return false;
}
public boolean setSpellLeft(String spell){
if(this.spellsList.contains(spell)){
this.spellLeft = spell;
this.sync();
return true;
}
return false;
}
public String getSpellRight(){
return this.spellRight;
}
public String getSpellLeft(){
return this.spellLeft;
}
public boolean addSpellsList(String spell){
if(this.getSpellsList().contains(spell) == false){
this.spellsList.add(spell);
this.sync();
return true;
}
return false;
}
public boolean removeSpellsList(String spell){
if(this.getSpellsList().contains(spell) == true){
this.spellsList.remove(spell);
this.sync();
return true;
}
return false;
}
public List <string>getSpellsList(){
return this.spellsList;
}
}
package fr.sosoh.hogsmod.common.event;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import fr.sosoh.hogsmod.common.entity.props.ExtendedEntityProps;
import fr.sosoh.hogsmod.proxy.CommonProxy;
public class EventHandlerExtendedProps {
private CommonProxy proxy;
public int ticks;
@SubscribeEvent
public void onEntityConstructing(EntityConstructing event)
{
if (event.entity instanceof EntityPlayer && ExtendedEntityProps.get((EntityPlayer) event.entity) == null)
ExtendedEntityProps.register((EntityPlayer) event.entity);
}
@SubscribeEvent
public void onLivingDeathEvent(LivingDeathEvent event) {
if (!event.entity.worldObj.isRemote
&& event.entity instanceof EntityPlayer) {
NBTTagCompound playerData = new NBTTagCompound();
((ExtendedEntityProps) (event.entity
.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME)))
.saveNBTData(playerData);
proxy.storeEntityData(
((EntityPlayer) event.entity).getDisplayName(), playerData);
ExtendedEntityProps.saveProxyData((EntityPlayer) event.entity);
} else {
}
}
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (!(event.entity.worldObj.isRemote) && event.entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer)event.entity;
NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).getDisplayName());
if (playerData != null) {
((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).loadNBTData(playerData);
}
((ExtendedEntityProps) (event.entity.getExtendedProperties(ExtendedEntityProps.EXT_PROP_NAME))).sync();
}
}
@SubscribeEvent
public void LivingUpdateEvent(LivingEvent.LivingUpdateEvent event){
if(event.entity instanceof EntityPlayer){
ExtendedEntityProps props = ExtendedEntityProps.get(((EntityPlayer) event.entity));
if(props.getMana() != props.getMaxMana()){
ticks = ticks+1;
if(ticks == 9){
props.setMana(props.getMana()+1);
ticks = 0;
}
}
}
}
}
```</string></string></string>