Files
CustomNPC-Plus/src/main/java/noppes/npcs/AnimationData.java
T

90 lines
3.3 KiB
Java
Raw Normal View History

2023-01-12 03:13:39 -05:00
package noppes.npcs;
import net.minecraft.entity.player.EntityPlayer;
2023-01-12 03:13:39 -05:00
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.api.handler.data.IAnimation;
2023-01-12 03:13:39 -05:00
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.data.Animation;
2023-01-12 03:13:39 -05:00
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityNPCInterface;
public class AnimationData implements IAnimationData {
//Server-side: DataDisplay, PlayerData
//Client-side: DataDisplay, EntityPlayer
public Object parent;
2023-01-12 03:13:39 -05:00
public Animation animation;
public boolean allowAnimation = false;
2023-01-12 03:13:39 -05:00
public AnimationData(Object parent){
this.parent = parent;
2023-01-12 03:13:39 -05:00
}
public void updateClient() {
if (parent instanceof PlayerData) {
NBTTagCompound compound = new NBTTagCompound();
this.writeToNBT(compound);
compound.setTag("Animation",this.animation.writeToNBT());
Server.sendToAll(EnumPacketClient.UPDATE_ANIMATIONS, compound, ((PlayerData) parent).player.getCommandSenderName());
} else if (parent instanceof DataDisplay) {
NBTTagCompound compound = new NBTTagCompound();
this.writeToNBT(compound);
compound.setTag("Animation",this.animation.writeToNBT());
compound.setInteger("EntityId",((DataDisplay) parent).npc.getEntityId());
Server.sendAssociatedData(((DataDisplay) parent).npc, EnumPacketClient.UPDATE_ANIMATIONS, compound);
}
2023-01-12 03:13:39 -05:00
}
public boolean isActive() {
if (!this.allowAnimation || this.animation == null || this.animation.currentFrame == this.animation.frames.size())
2023-01-12 03:13:39 -05:00
return false;
if (this.parent instanceof DataDisplay) {
EntityNPCInterface npc = ((DataDisplay)this.parent).npc;
if (!npc.isEntityAlive())
return false;
return animation.whileAttacking && npc.isAttacking() || animation.whileMoving && npc.isWalking() || animation.whileStanding && !npc.isWalking();
} else {
EntityPlayer player;
if (this.parent instanceof PlayerData) {
player = ((PlayerData) this.parent).player;
} else {
player = (EntityPlayer) this.parent;
}
if (!player.isEntityAlive())
return false;
boolean moving = Math.sqrt(player.motionX*player.motionX + player.motionY*player.motionY + player.motionZ*player.motionZ) != 0.0D;
return animation.whileAttacking && player.getLastAttackerTime() - player.ticksExisted < 20 || animation.whileMoving && moving || animation.whileStanding && !moving;
}
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setBoolean("PuppetEnabled", allowAnimation);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
this.allowAnimation = compound.getBoolean("PuppetEnabled");
}
2023-01-12 03:13:39 -05:00
public void setEnabled(boolean enabled) {
this.allowAnimation = enabled;
}
2023-01-12 03:13:39 -05:00
public boolean enabled() {
return this.allowAnimation;
2023-01-12 03:13:39 -05:00
}
public void setAnimation(IAnimation animation) {
this.animation = (Animation) animation;
}
public IAnimation getAnimation() {
return animation;
}
2023-01-12 03:13:39 -05:00
}