mirror of
https://github.com/KAMKEEL/CustomNPC-Gecko-Addon.git
synced 2026-11-19 03:49:11 +00:00
Created a packet network for animation synchronisation
This commit is contained in:
1 parent
56e12c4730
commit
a3e0484ed1
3 files changed
+82
No files matched your search
@@ -0,0 +1,7 @@
|
||||
package com.goodbird.npcgecko.constants;
|
||||
|
||||
public enum EnumSyncAutoAnim {
|
||||
MELEE_ATTACK,
|
||||
RANGED_ATTACK,
|
||||
HURT
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.goodbird.npcgecko.network;
|
||||
|
||||
import com.goodbird.npcgecko.constants.EnumSyncAutoAnim;
|
||||
import com.goodbird.npcgecko.entity.EntityCustomModel;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
public final class CPacketSyncAutoAnim implements IMessage, IMessageHandler<CPacketSyncAutoAnim, IMessage> {
|
||||
public EnumSyncAutoAnim animType;
|
||||
public int entityId;
|
||||
public CPacketSyncAutoAnim(){
|
||||
|
||||
}
|
||||
public CPacketSyncAutoAnim(EntityNPCInterface npc, EnumSyncAutoAnim animType) {
|
||||
this.animType = animType;
|
||||
this.entityId = npc.getEntityId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(animType.ordinal());
|
||||
buf.writeInt(entityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
animType = EnumSyncAutoAnim.values()[buf.readInt()];
|
||||
entityId = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketSyncAutoAnim message, MessageContext ctx) {
|
||||
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(message.entityId);
|
||||
if(!(entity instanceof EntityCustomNpc)) return null;
|
||||
EntityCustomNpc npc = (EntityCustomNpc) entity;
|
||||
if(npc.modelData==null || !(npc.modelData.getEntity(npc) instanceof EntityCustomModel)) return null;
|
||||
EntityCustomModel entityCustomModel = (EntityCustomModel) npc.modelData.getEntity(npc);
|
||||
entityCustomModel.activateReceivedAnim(message.animType);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.goodbird.npcgecko.network;
|
||||
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public final class NetworkHandler {
|
||||
private static final SimpleNetworkWrapper wrapper = new SimpleNetworkWrapper("npcgecko");
|
||||
|
||||
public static void init() {
|
||||
wrapper.registerMessage(CPacketSyncAutoAnim.class, CPacketSyncAutoAnim.class, 0, Side.CLIENT);
|
||||
}
|
||||
|
||||
public static void sendToPlayer(IMessage message, EntityPlayer player) {
|
||||
wrapper.sendTo(message, (EntityPlayerMP) player);
|
||||
}
|
||||
|
||||
public static void sendToAll(IMessage message) {
|
||||
wrapper.sendToAll(message);
|
||||
}
|
||||
|
||||
public static void sendToServer(IMessage message) {
|
||||
wrapper.sendToServer(message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user