Removed millisecond ticks and tick duration from animations.

This commit is contained in:
luisc committed 2025-02-12 12:15:33 -06:00
1 parent e5673a85e7
commit 3b9c38124e
12 files changed
+54 -192

No files matched your search

+4 -94
View File
@@ -1,9 +1,6 @@
package noppes.npcs;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -19,111 +16,24 @@ import noppes.npcs.blocks.tiles.TileNpcContainer;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.containers.*;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.MillisTimer;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.HashSet;
public class CommonProxy implements IGuiHandler {
public final static HashSet<AnimationData> clientPlayingAnimations = new HashSet<>();
public final static HashSet<AnimationData> serverPlayingAnimations = new HashSet<>();
protected MillisTimer animationTimer = new MillisTimer(1000);
protected static long totalServerTicks;
protected static long totalClientTicks;
public boolean newVersionAvailable = false;
public int revision = 1;
public void load() {
this.createAnimationThread();
}
protected void createAnimationThread() {
Thread thread = (new Thread("Animation Thread") { public void run() {
while (true) {
try {
if (!CustomNpcs.proxy.hasClient() || !Minecraft.getMinecraft().isGamePaused()) {
animationTimer.updateTimer();
}
for (int i = 0; i < animationTimer.elapsedTicks; ++i) {
updateData(totalClientTicks, clientPlayingAnimations);
totalClientTicks++;
updateData(totalServerTicks, serverPlayingAnimations);
totalServerTicks++;
}
totalClientTicks %= Long.MAX_VALUE;
totalServerTicks %= Long.MAX_VALUE;
synchronized (clientPlayingAnimations) {
clientPlayingAnimations.removeIf(CommonProxy.this::removeAnimation);
}
synchronized (serverPlayingAnimations) {
serverPlayingAnimations.removeIf(CommonProxy.this::removeAnimation);
}
} catch (Exception e) {
if (!(e instanceof ConcurrentModificationException)) {
e.printStackTrace();
}
}
}
}});
thread.setDaemon(true);
thread.start();
}
private void updateData(long ticks, Collection<AnimationData> animationData) {
for (AnimationData data : animationData) {
Frame frame = data.animation != null && data.animation.currentFrame() != null
? (Frame) data.animation.currentFrame() : null;
if (frame != null) {
int tickDuration = frame.tickDuration();
if (ticks % tickDuration == 0) {
data.increaseTime();
}
}
}
}
private boolean removeAnimation(AnimationData data) {
Entity entity = null;
if (data.parent instanceof DataDisplay) {
entity = ((DataDisplay)data.parent).npc;
} else {
if (data.parent instanceof PlayerData) {
entity = ((PlayerData) data.parent).player;
} else if (data.parent instanceof EntityPlayer) {
entity = (EntityPlayer) data.parent;
}
}
if (entity == null) return true;
if (entity.worldObj != null && entity.worldObj.isRemote) {
return clientRemoveAnimation(entity);
} else {
return entity.worldObj == null || !entity.worldObj.loadedEntityList.contains(entity)
|| CustomNpcs.getServer().isServerStopped();
}
}
@SideOnly(Side.CLIENT)
private boolean clientRemoveAnimation(Entity entity) {
Minecraft mc = Minecraft.getMinecraft();
return mc.theWorld == null
|| mc.currentScreen == null && entity != mc.thePlayer && !mc.theWorld.loadedEntityList.contains(entity);
}
public PlayerData getPlayerData(EntityPlayer player) {
return null;
}
public AnimationData getClientAnimationData(Entity entity) {
return null;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if(ID > EnumGuiType.values().length)
@@ -8,11 +8,11 @@ import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumSoundOperation;
import kamkeel.npcs.network.enums.EnumSyncAction;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.packets.data.ClonerPacket;
import kamkeel.npcs.network.packets.data.MarkDataPacket;
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
import kamkeel.npcs.network.packets.data.VillagerListPacket;
import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket;
import kamkeel.npcs.network.packets.data.ClonerPacket;
import kamkeel.npcs.network.packets.data.large.SyncPacket;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
@@ -33,6 +33,7 @@ import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
@@ -484,16 +485,13 @@ public class ServerEventsHandler {
return;
AnimationData animationData = AnimationData.getData(event.target);
if (animationData.isClientAnimating()) {
if (animationData != null && animationData.isClientAnimating()) {
AnimationData playerAnimData = AnimationData.getData(event.entityPlayer);
Animation currentAnimation = animationData.currentClientAnimation;
NBTTagCompound compound = currentAnimation.writeToNBT();
if (playerAnimData.viewAnimation(currentAnimation, animationData, compound,
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime)) {
synchronized (CommonProxy.serverPlayingAnimations) {
CommonProxy.serverPlayingAnimations.add(animationData);
}
if (playerAnimData != null) {
Animation currentAnimation = animationData.currentClientAnimation;
NBTTagCompound compound = currentAnimation.writeToNBT();
playerAnimData.viewAnimation(currentAnimation, animationData, compound,
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime);
}
}
@@ -504,4 +502,12 @@ public class ServerEventsHandler {
PacketHandler.Instance.sendToPlayer(new MarkDataPacket(event.target.getEntityId(), data.getNBT()), (EntityPlayerMP)event.entityPlayer);
}
}
@SubscribeEvent
public void entityTick(LivingEvent.LivingUpdateEvent event) {
AnimationData data = AnimationData.getData(event.entityLiving);
if (data != null) {
data.increaseTime();
}
}
}
@@ -16,6 +16,7 @@ import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -28,7 +29,10 @@ import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import noppes.npcs.*;
import noppes.npcs.CommonProxy;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.IWorld;
import noppes.npcs.blocks.tiles.*;
import noppes.npcs.client.controllers.*;
@@ -59,6 +63,7 @@ import noppes.npcs.config.ConfigMain;
import noppes.npcs.config.StringCache;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.containers.*;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.*;
import noppes.npcs.entity.data.ModelData;
@@ -81,8 +86,6 @@ public class ClientProxy extends CommonProxy {
public static FontContainer Font;
public void load() {
this.createAnimationThread();
Font = new FontContainer(ConfigClient.FontType, ConfigClient.FontSize);
createFolders();
new MusicController();
@@ -207,6 +210,15 @@ public class ClientProxy extends CommonProxy {
return null;
}
public AnimationData getClientAnimationData(Entity entity) {
if (entity instanceof EntityPlayer) {
return ClientCacheHandler.playerAnimations.get(entity.getUniqueID());
} else if (entity instanceof EntityNPCInterface) {
return ((EntityNPCInterface) entity).display.animationData;
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@@ -30,12 +30,6 @@ public class SubGuiAnimationFrame extends SubGuiInterface implements ITextfieldL
//smooth - button
this.addLabel(new GuiNpcLabel(12, "animation.smoothing", guiLeft + 5, guiTop + 63));
this.addButton(new GuiNpcButton(12, guiLeft + 75, guiTop + 55, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, editingFrame.smooth));
//
//tick duration - textfield
this.addLabel(new GuiNpcLabel(13, "animation.tickDuration", guiLeft + 5, guiTop + 84));
this.addTextField(new GuiNpcTextField(13, this, guiLeft + 75, guiTop + 79, 40, 15, editingFrame.tickDuration + ""));
this.getTextField(13).integersOnly = true;
this.getTextField(13).setMinMaxDefault(1, Integer.MAX_VALUE, 50);
}
this.addLabel(new GuiNpcLabel(14, "Comment", guiLeft + 5, guiTop + 106));
@@ -67,8 +61,6 @@ public class SubGuiAnimationFrame extends SubGuiInterface implements ITextfieldL
if (textfield.id == 11) {
this.editingFrame.speed = textfield.getFloat();
} else if (textfield.id == 13) {
this.editingFrame.tickDuration = textfield.getInteger();
} else if (textfield.id == 14) {
this.editingFrame.setComment(textfield.getText());
}
@@ -1,10 +1,12 @@
package noppes.npcs.client.gui;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.controllers.data.Animation;
public class SubGuiAnimationOptions extends SubGuiInterface implements ITextfieldListener {
public class SubGuiAnimationOptions extends SubGuiInterface {
private final Animation animation;
public SubGuiAnimationOptions(Animation animation) {
@@ -16,12 +18,6 @@ public class SubGuiAnimationOptions extends SubGuiInterface implements ITextfiel
public void initGui() {
super.initGui();
//
//ticks - button
this.addLabel(new GuiNpcLabel(10, "animation.tickDuration", guiLeft + 5, guiTop + 16));
this.addTextField(new GuiNpcTextField(10, this, guiLeft + 80, guiTop + 12, 40, 15, animation.tickDuration + ""));
this.getTextField(10).integersOnly = true;
this.getTextField(10).setMinMaxDefault(1, Integer.MAX_VALUE, 50);
//
//whileStanding - button
this.addLabel(new GuiNpcLabel(11, "animation.whileStanding", guiLeft + 5, guiTop + 36));
this.addButton(new GuiNpcButton(11, guiLeft + 80, guiTop + 30, 30, 20, new String[]{"gui.yes", "gui.no"}, animation.whileStanding ? 0 : 1));
@@ -50,11 +46,4 @@ public class SubGuiAnimationOptions extends SubGuiInterface implements ITextfiel
initGui();
}
@Override
public void unFocused(GuiNpcTextField textfield) {
if (textfield.id == 10) {
animation.tickDuration = textfield.getInteger();
}
}
}
@@ -4,13 +4,11 @@ import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.animation.AnimationSavePacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import noppes.npcs.client.gui.SubGuiAnimationFrame;
import noppes.npcs.client.gui.SubGuiAnimationOptions;
import noppes.npcs.client.gui.SubGuiColorSelector;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.Frame;
@@ -98,7 +96,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
if (!playingAnimation) {
data.setAnimation(new Animation());
data.animation.smooth = animation.smooth;
data.animation.tickDuration = 50;
data.animation.loop = 0;
if (editingFrame != null) {
data.animation.frames.add(editingFrame);
@@ -111,7 +108,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
if (!frame.isCustomized()) {
frame.speed = animation.speed;
frame.smooth = animation.smooth;
frame.tickDuration = animation.tickDuration();
}
for (Map.Entry<EnumAnimationPart,FramePart> entry : frame.frameParts.entrySet()) {
FramePart part = entry.getValue();
@@ -10,11 +10,12 @@ import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.controllers.data.*;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.FramePart;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
@@ -70,7 +71,6 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
if (!playingAnimation) {
data.setAnimation(new Animation());
data.animation.smooth = animation.smooth;
data.animation.tickDuration = 50;
data.animation.loop = 0;
if (this.animation.frames.size() > 0) {
@@ -26,7 +26,6 @@ public class Animation implements IAnimation {
public float speed = 1.0F;
public byte smooth = 0;
public int loop = -1; //If greater than 0 and less than the amount of frames, the animation will begin looping when it reaches this frame.
public int tickDuration = 50;
public boolean whileStanding = true;
public boolean whileAttacking = true;
@@ -99,15 +98,6 @@ public class Animation implements IAnimation {
return this.name;
}
public int tickDuration() {
return this.tickDuration;
}
public IAnimation setTickDuration(int tickDuration) {
this.tickDuration = tickDuration;
return this;
}
public IAnimation setSpeed(float speed) {
this.speed = speed;
return this;
@@ -179,7 +169,7 @@ public class Animation implements IAnimation {
public long getTotalTime() {
long time = 0;
for (Frame frame : this.frames) {
time += (long) frame.duration * (frame.customized ? frame.tickDuration : this.tickDuration);
time += frame.duration;
}
return time;
}
@@ -197,12 +187,6 @@ public class Animation implements IAnimation {
smooth = compound.getByte("Smooth");
loop = compound.getInteger("Loop");
if (compound.hasKey("TickDuration")) {
this.tickDuration = compound.getInteger("TickDuration");
} else if(compound.hasKey("RenderTicks")){
this.tickDuration = compound.getBoolean("RenderTicks") ? 20 : 50;
}
ArrayList<Frame> frames = new ArrayList<Frame>();
NBTTagList list = compound.getTagList("Frames", 10);
for (int i = 0; i < list.tagCount(); i++) {
@@ -229,7 +213,6 @@ public class Animation implements IAnimation {
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setInteger("Loop",loop);
compound.setInteger("TickDuration", tickDuration);
NBTTagList list = new NBTTagList();
for(Frame frame : frames){
@@ -9,7 +9,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import noppes.npcs.CommonProxy;
import noppes.npcs.CustomNpcs;
import noppes.npcs.DataDisplay;
import noppes.npcs.EventHooks;
import noppes.npcs.api.entity.IAnimatable;
@@ -44,7 +44,12 @@ public class AnimationData implements IAnimationData {
public AnimationData(Object parent){
this.parent = parent;
}
public static AnimationData getData(Entity entity) {
if (entity.worldObj.isRemote) {
return CustomNpcs.proxy.getClientAnimationData(entity);
}
if (entity instanceof EntityPlayerMP) {
return PlayerData.get((EntityPlayer) entity).animationData;
} else if (entity instanceof EntityNPCInterface) {
@@ -102,13 +107,6 @@ public class AnimationData implements IAnimationData {
EventHooks.onAnimationFrameEntered(this.animation, this.animation.currentFrame());
}
synchronized (CommonProxy.serverPlayingAnimations) {
if (this.isClientAnimating && this.getMCEntity() != null &&
!this.getMCEntity().worldObj.isRemote && this.animation != null) {
CommonProxy.serverPlayingAnimations.add(this);
}
}
List<EntityPlayer> entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(
sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range,
sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range));
@@ -159,7 +157,7 @@ public class AnimationData implements IAnimationData {
public void increaseTime() {
Animation updateAnimation = null;
if (this.isActive(animation.parent.currentClientAnimation)) {
if (this.animation != null && this.isActive(this.animation.parent.currentClientAnimation)) {
updateAnimation = this.currentClientAnimation;
} else {
this.isClientAnimating = false;
@@ -171,7 +169,7 @@ public class AnimationData implements IAnimationData {
if (updateAnimation != null && updateAnimation.increaseTime()) {
Frame frame = (Frame) updateAnimation.currentFrame();
if (frame != null) {
this.animatingTime += frame.customized ? frame.tickDuration : updateAnimation.tickDuration;
this.animatingTime++;
}
}
}
@@ -274,9 +272,6 @@ public class AnimationData implements IAnimationData {
if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote && newAnim != null) {
this.animatingTime = 0;
synchronized (CommonProxy.clientPlayingAnimations) {
CommonProxy.clientPlayingAnimations.add(this);
}
}
Animation prevAnim = this.animation;
@@ -14,7 +14,6 @@ public class Frame implements IFrame {
public Animation parent;
public HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
public int duration = 0;
public int tickDuration = 50;
boolean customized = false;
public float speed = 1.0F;
@@ -77,15 +76,6 @@ public class Frame implements IFrame {
return this;
}
public int tickDuration() {
return !this.customized && this.parent != null ? this.parent.tickDuration : this.tickDuration;
}
public IFrame setTickDuration(int tickDuration) {
this.tickDuration = tickDuration;
return this;
}
public boolean isCustomized() {
return customized;
}
@@ -148,18 +138,9 @@ public class Frame implements IFrame {
smooth = compound.getByte("Smooth");
}
if (compound.hasKey("TickDuration")) {
customized = true;
this.tickDuration = compound.getInteger("TickDuration");
} else if(compound.hasKey("RenderTicks")){
customized = true;
this.tickDuration = compound.getBoolean("RenderTicks") ? 20 : 50;
}
if (!customized && parent != null) {
this.speed = parent.speed;
this.smooth = parent.smooth;
this.tickDuration = parent.tickDuration;
}
HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
@@ -186,7 +167,6 @@ public class Frame implements IFrame {
if(customized){
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setInteger("TickDuration", tickDuration);
}
NBTTagList list = new NBTTagList();
@@ -209,7 +189,6 @@ public class Frame implements IFrame {
frame.customized = this.customized;
frame.speed = this.speed;
frame.smooth = this.smooth;
frame.tickDuration = this.tickDuration;
frame.colorMarker = this.colorMarker;
return frame;
}