Re,
Alors du coup j’ai fais l’extended
voilà ma classe:
| |
| public class ExtendedEntityPropTimer implements IExtendedEntityProperties { |
| |
| public final static String EXT_PROP_NAME = "ExtPropTimer"; |
| |
| private final EntityPlayer player; |
| |
| public int timer; |
| |
| public ExtendedEntityPropTimer(EntityPlayer player) { |
| this.player = player; |
| this.timer = 0; |
| } |
| |
| public static final void register(EntityPlayer player) { |
| player.registerExtendedProperties(ExtendedEntityPropTimer.EXT_PROP_NAME, |
| new ExtendedEntityPropTimer(player)); |
| } |
| |
| public static final ExtendedEntityPropTimer get(EntityPlayer player) { |
| return (ExtendedEntityPropTimer) player.getExtendedProperties(EXT_PROP_NAME); |
| } |
| |
| @Override |
| public void saveNBTData(NBTTagCompound compound) { |
| |
| NBTTagCompound properties = new NBTTagCompound(); |
| |
| properties.setInteger("Timer", this.timer); |
| |
| compound.setTag(EXT_PROP_NAME, properties); |
| } |
| |
| @Override |
| public void loadNBTData(NBTTagCompound compound) { |
| NBTTagCompound properties = (NBTTagCompound) compound |
| .getTag(EXT_PROP_NAME); |
| properties.setInteger("Timer", this.timer); |
| } |
| |
| public final void sync() { |
| PacketTimer packetTimer = new PacketTimer(this.timer); |
| LegacyMod.network.sendToServer(packetTimer); |
| |
| if (!player.worldObj.isRemote) { |
| EntityPlayerMP player1 = (EntityPlayerMP) player; |
| |
| LegacyMod.network.sendTo(packetTimer, player1); |
| } |
| } |
| |
| private static String getSaveKey(EntityPlayer player) { |
| return player.getDisplayName() + ":" + EXT_PROP_NAME; |
| } |
| |
| public static void saveProxyData(EntityPlayer player) { |
| ExtendedEntityPropTimer playerData = ExtendedEntityPropTimer.get(player); |
| NBTTagCompound savedData = new NBTTagCompound(); |
| |
| playerData.saveNBTData(savedData); |
| CommonProxy.storeEntityData(getSaveKey(player), savedData); |
| } |
| |
| public static void loadProxyData(EntityPlayer player) { |
| ExtendedEntityPropTimer playerData = ExtendedEntityPropTimer.get(player); |
| NBTTagCompound savedData = CommonProxy |
| .getEntityData(getSaveKey(player)); |
| |
| if (savedData != null) { |
| playerData.loadNBTData(savedData); |
| } |
| playerData.sync(); |
| } |
| |
| @Override |
| public void init(Entity entity, World world) { |
| |
| |
| } |
| |
| } |
| |
Mon packet:
| |
| public class PacketTimer implements IMessage{ |
| |
| private int Timer; |
| |
| public PacketTimer() |
| { |
| |
| } |
| |
| public PacketTimer(int timer) |
| { |
| this.Timer = timer; |
| } |
| |
| @Override |
| public void fromBytes(ByteBuf buf) |
| { |
| this.Timer = buf.readInt(); |
| } |
| |
| @Override |
| public void toBytes(ByteBuf buf) |
| { |
| buf.writeInt(this.Timer); |
| } |
| |
| public static class Handler implements IMessageHandler <packettimer, imessage="">{ |
| public IMessage onMessage(PacketTimer message, MessageContext ctx) { |
| ExtendedEntityPropTimer props = ExtendedEntityPropTimer |
| .get(ctx.getServerHandler().playerEntity); |
| props.timer = message.Timer; |
| return null; |
| } |
| } |
| |
| } |
| |
register packet:
network.registerMessage(PacketTimer.Handler.class, PacketTimer.class, 4, Side.SERVER);
Mais je suis bloqué car je vois pas trop comment faire pour le timer.
Je dois rajouter des fonctions dans l’extended pour le timer ou pas ? je dois surement faire this.timer++ / – mais je vois pas du tout ou ^^ et esque je dois faire aussi des fonction settimer / gettimer etc…
Merci :)</packettimer,>