21 sept. 2014, 09:42

Salut  🙂 ,
J’ai toujours un problème avec les Extended Entity Properties, j’ai revu plusieurs fois mon code mais les packets n’ont pas l’air de se transmettre peut importe ce que je fais les données restent toujours à 0
Si vous avez une petite idée ^^ :
PacketSonic :

​public class PacketSonic
extends FFMTPacket
{

public int Descendre;
public boolean DoubleJump;
public long Ring;

public PacketSonic(){

}

public PacketSonic(int Descendre, boolean DoubleJump, long Ring){
this.Descendre = Descendre;
this.DoubleJump = DoubleJump;
this.Ring = Ring;
}

@Override
public void writeData(ByteBuf buffer) throws IOException {
buffer.writeInt(Descendre);
buffer.writeBoolean(DoubleJump);
buffer.writeLong(Ring);

}

@Override
public void readData(ByteBuf buffer) {
this.Descendre = buffer.readInt();
this.DoubleJump = buffer.readBoolean();
this.Ring = buffer.readLong();

}

@Override
public void handleClientSide(EntityPlayer player) {
ExtendedEntityPropSonic props = ExtendedEntityPropSonic
.get(player);
props.Descendre = this.Descendre;
props.DoubleJump = this.DoubleJump;
props.Ring = this.Ring;
}

@Override
public void handleServerSide(EntityPlayer player) {
ExtendedEntityPropSonic props = ExtendedEntityPropSonic
.get(player);
props.Descendre = this.Descendre;
props.DoubleJump = this.DoubleJump;
props.Ring = this.Ring;
}

}

ExtendedEntityPropSonic :

​ public final static String EXT_PROP_NAME = "ExtPropSonic";

private final EntityPlayer player;

public int Descendre;
public boolean DoubleJump;
public long Ring;

public ExtendedEntityPropSonic(EntityPlayer player) {
this.player = player;
this.Descendre = 0;
this.DoubleJump = false;
this.Ring = 0;

}

@Override
public void saveNBTData(NBTTagCompound compound) {

NBTTagCompound properties = new NBTTagCompound();

properties.setInteger("Descendre", this.Descendre);
properties.setBoolean("DoubleJump", this.DoubleJump);
properties.setLong("Ring", this.Ring);

compound.setTag(EXT_PROP_NAME, properties);

}

@Override
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
this.Descendre = properties.getInteger("Descendre");
this.DoubleJump = properties.getBoolean("DoubleJump");
this.Ring = properties.getLong("Ring");

}

@Override
public void init(Entity entity, World world) {
// TODO Auto-generated method stub

}

public static final void register(EntityPlayer player) {
player.registerExtendedProperties(ExtendedEntityPropSonic.EXT_PROP_NAME,
new ExtendedEntityPropSonic(player));
}

public static final ExtendedEntityPropSonic get(EntityPlayer player) {
return (ExtendedEntityPropSonic) player.getExtendedProperties(EXT_PROP_NAME);
}

public final void sync() {
PacketSonic packetSonic = new PacketSonic(this.Descendre, this.DoubleJump, this.Ring);
Sonic_mod.rcModPacketHandler.sendToServer(packetSonic);

if (!player.worldObj.isRemote) {
EntityPlayerMP player1 = (EntityPlayerMP) player;
Sonic_mod.rcModPacketHandler.sendTo(packetSonic, player1);
}
}
private static String getSaveKey(EntityPlayer player) {
return player.getDisplayName() + ":" + EXT_PROP_NAME;
}

public static void saveProxyData(EntityPlayer player) {
ExtendedEntityPropSonic playerData = ExtendedEntityPropSonic.get(player);
NBTTagCompound savedData = new NBTTagCompound();

playerData.saveNBTData(savedData);
CommonProxy.storeEntityData(getSaveKey(player), savedData);
}

public static void loadProxyData(EntityPlayer player) {
ExtendedEntityPropSonic playerData = ExtendedEntityPropSonic.get(player);
NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player));

if (savedData != null) {
playerData.loadNBTData(savedData);
}
playerData.sync();
}

public long getRing() {
return this.Ring;
}

public void setRing(long newRing) {
this.Ring = newRing;
this.sync();

}

public int getDescendre() {
return this.Descendre;
}

public void setDescendre(int newDescendre) {
this.Descendre = newDescendre;
this.sync();
}

public boolean getDoubleJump() {
return this.DoubleJump;
}

public void setDoubleJump(boolean newDoubleJump) {
this.DoubleJump = newDoubleJump;
this.sync();
}

Une partie de ma classe event :

​ /** Register data*/
@SubscribeEvent
public void onEntityConstructing(EntityConstructing event) {

if (event.entity instanceof EntityPlayer
&& ExtendedEntityPropSonic.get((EntityPlayer) event.entity) == null)
{
ExtendedEntityPropSonic.register((EntityPlayer) event.entity);
System.out.println("une entité a rejoint le monde");
}
}
@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (!event.entity.worldObj.isRemote
&& event.entity instanceof EntityPlayer) {
NBTTagCompound playerData = CommonProxy
.getEntityData(((EntityPlayer) event.entity)
.getDisplayName());
if (playerData != null) {
((ExtendedEntityPropSonic) (event.entity
.getExtendedProperties(ExtendedEntityPropSonic.EXT_PROP_NAME)))
.loadNBTData(playerData);
}

((ExtendedEntityPropSonic) (event.entity
.getExtendedProperties(ExtendedEntityPropSonic.EXT_PROP_NAME)))
.sync();
}
}
}

Je pense avoir tout mis
Merci d’avance ^^’