mirror of
https://github.com/KAMKEEL/CustomNPC-Gecko-Addon.git
synced 2026-11-19 08:29:06 +00:00
Added a packet for manual animation synchronisation
This commit is contained in:
1 parent
63fde2c954
commit
2e9b43c6d0
2 files changed
+88
No files matched your search
@@ -0,0 +1,87 @@
|
||||
package com.goodbird.npcgecko.network;
|
||||
|
||||
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 net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
||||
import software.bernie.geckolib3.core.builder.ILoopType;
|
||||
import software.bernie.geckolib3.core.builder.RawAnimation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class CPacketSyncManualAnim implements IMessage, IMessageHandler<CPacketSyncManualAnim, IMessage> {
|
||||
public AnimationBuilder builder;
|
||||
public int entityId;
|
||||
public CPacketSyncManualAnim(){
|
||||
|
||||
}
|
||||
public CPacketSyncManualAnim(EntityNPCInterface npc, AnimationBuilder builder) {
|
||||
this.builder = builder;
|
||||
this.entityId = npc.getEntityId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
try {
|
||||
writeAnimBuilder(buf, builder);
|
||||
}catch (Exception ignored){ }
|
||||
buf.writeInt(entityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
try {
|
||||
builder = readAnimBuilder(buf);
|
||||
}catch (Exception ignored){ }
|
||||
entityId = buf.readInt();
|
||||
}
|
||||
|
||||
public static void writeAnimBuilder(ByteBuf buffer, AnimationBuilder builder) throws IOException {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList animList = new NBTTagList();
|
||||
for(RawAnimation anim: builder.getRawAnimationList()){
|
||||
NBTTagCompound animTag = new NBTTagCompound();
|
||||
animTag.setString("name", anim.animationName);
|
||||
if(anim.loopType!=null) {
|
||||
animTag.setInteger("loop", ((ILoopType.EDefaultLoopTypes) anim.loopType).ordinal());
|
||||
}else{
|
||||
animTag.setInteger("loop",1);
|
||||
}
|
||||
animList.appendTag(animTag);
|
||||
}
|
||||
compound.setTag("anims",animList);
|
||||
Server.writeNBT(buffer,compound);
|
||||
}
|
||||
|
||||
public static AnimationBuilder readAnimBuilder(ByteBuf buffer) throws IOException {
|
||||
AnimationBuilder builder = new AnimationBuilder();
|
||||
NBTTagCompound compound = Server.readNBT(buffer);
|
||||
NBTTagList animList = compound.getTagList("anims",10);
|
||||
for(int i=0;i<animList.tagCount();i++){
|
||||
NBTTagCompound animTag = animList.getCompoundTagAt(i);
|
||||
builder.addAnimation(animTag.getString("name"),
|
||||
ILoopType.EDefaultLoopTypes.values()[animTag.getInteger("loop")]);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketSyncManualAnim 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.manualAnim = message.builder;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ public final class NetworkHandler {
|
||||
|
||||
public static void init() {
|
||||
wrapper.registerMessage(CPacketSyncAutoAnim.class, CPacketSyncAutoAnim.class, 0, Side.CLIENT);
|
||||
wrapper.registerMessage(CPacketSyncManualAnim.class, CPacketSyncManualAnim.class, 1, Side.CLIENT);
|
||||
}
|
||||
|
||||
public static void sendToPlayer(IMessage message, EntityPlayer player) {
|
||||
|
||||
Reference in new issue
Block a user