diff --git a/src/main/java/noppes/npcs/CommonProxy.java b/src/main/java/noppes/npcs/CommonProxy.java index d814ccf86..067e2f1b3 100644 --- a/src/main/java/noppes/npcs/CommonProxy.java +++ b/src/main/java/noppes/npcs/CommonProxy.java @@ -1,11 +1,7 @@ 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; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; @@ -18,108 +14,19 @@ import noppes.npcs.api.IWorld; 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 clientPlayingAnimations = new HashSet<>(); - public final static HashSet 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(); - CustomNpcs.Channel.register(new PacketHandlerServer()); CustomNpcs.ChannelPlayer.register(new PacketHandlerPlayer()); } - 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) { - 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; } @@ -259,4 +166,4 @@ public class CommonProxy implements IGuiHandler { public boolean isGUIOpen(){ return false; } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index aa95c8af7..43e6d570f 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -15,12 +15,11 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.api.IWorld; -import noppes.npcs.api.entity.*; -import noppes.npcs.api.event.IAnimationEvent; +import noppes.npcs.api.entity.IEntity; +import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.entity.IProjectile; import noppes.npcs.api.gui.ICustomGui; import noppes.npcs.api.gui.IItemSlot; -import noppes.npcs.api.handler.data.IAnimation; -import noppes.npcs.api.handler.data.IFrame; import noppes.npcs.api.item.IItemCustom; import noppes.npcs.api.item.IItemStack; import noppes.npcs.constants.EnumScriptType; @@ -120,6 +119,7 @@ public class EventHooks { return; noppes.npcs.scripted.event.NpcEvent.InitEvent event = new noppes.npcs.scripted.event.NpcEvent.InitEvent(npc.wrappedNPC); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.INIT, event); npc.script.callScript(EnumScriptType.INIT, event); NpcAPI.EVENT_BUS.post(event); npc.advanced.soulStoneInit = false; @@ -130,6 +130,7 @@ public class EventHooks { return; noppes.npcs.scripted.event.NpcEvent.UpdateEvent event = new noppes.npcs.scripted.event.NpcEvent.UpdateEvent(npc.wrappedNPC); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TICK, event); npc.script.callScript(EnumScriptType.TICK, event); NpcAPI.EVENT_BUS.post(event); } @@ -139,6 +140,7 @@ public class EventHooks { return false; NpcEvent.DialogEvent event = new NpcEvent.DialogEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DIALOG, event); npc.script.callScript(EnumScriptType.DIALOG, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); return NpcAPI.EVENT_BUS.post(event); @@ -149,6 +151,7 @@ public class EventHooks { return; NpcEvent.DialogClosedEvent event = new NpcEvent.DialogClosedEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DIALOG_CLOSE, event); npc.script.callScript(EnumScriptType.DIALOG_CLOSE, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); NpcAPI.EVENT_BUS.post(event); @@ -159,6 +162,7 @@ public class EventHooks { return false; NpcEvent.InteractEvent event = new NpcEvent.InteractEvent(npc.wrappedNPC,player); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.INTERACT, event); boolean result = npc.script.callScript(EnumScriptType.INTERACT, event, "player", player); NpcAPI.EVENT_BUS.post(event); return result; @@ -168,6 +172,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ATTACK_MELEE, event); npc.script.callScript(EnumScriptType.ATTACK_MELEE, event, "target", event.target); npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); return NpcAPI.EVENT_BUS.post(event); @@ -177,6 +182,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ATTACK_SWING, event); npc.script.callScript(EnumScriptType.ATTACK_SWING, event); return NpcAPI.EVENT_BUS.post(event); } @@ -185,6 +191,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.RANGED_LAUNCHED, event); npc.script.callScript(EnumScriptType.RANGED_LAUNCHED, event, "target", event.target); npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); return NpcAPI.EVENT_BUS.post(event); @@ -195,6 +202,7 @@ public class EventHooks { return; NpcEvent.KilledEntityEvent event = new NpcEvent.KilledEntityEvent(npc.wrappedNPC,entity); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.KILLS, event); npc.script.callScript(EnumScriptType.KILLS, event, "target", entity); NpcAPI.EVENT_BUS.post(event); } @@ -203,6 +211,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TARGET, event); npc.script.callScript(EnumScriptType.TARGET, event); return NpcAPI.EVENT_BUS.post(event); } @@ -212,6 +221,7 @@ public class EventHooks { return false; NpcEvent.TargetLostEvent event = new NpcEvent.TargetLostEvent(npc.wrappedNPC, prevtarget, newTarget); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TARGET_LOST, event); npc.script.callScript(EnumScriptType.TARGET_LOST, event); return NpcAPI.EVENT_BUS.post(event); } @@ -221,6 +231,7 @@ public class EventHooks { return; NpcEvent.CollideEvent event = new NpcEvent.CollideEvent(npc.wrappedNPC,entity); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.COLLIDE, event); npc.script.callScript(EnumScriptType.COLLIDE, event, "entity", entity); NpcAPI.EVENT_BUS.post(event); } @@ -229,6 +240,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DAMAGED, event); npc.script.callScript(EnumScriptType.DAMAGED, event); return NpcAPI.EVENT_BUS.post(event); } @@ -237,6 +249,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.KILLED, event); npc.script.callScript(EnumScriptType.KILLED, event); return NpcAPI.EVENT_BUS.post(event); } @@ -246,12 +259,14 @@ public class EventHooks { return; NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TIMER, event); npc.script.callScript(EnumScriptType.TIMER, event); NpcAPI.EVENT_BUS.post(event); } public static void onProjectileTick(EntityProjectile projectile) { ProjectileEvent.UpdateEvent event = new ProjectileEvent.UpdateEvent((IProjectile) NpcAPI.Instance().getIEntity(projectile)); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.PROJECTILE_TICK, event); for(ScriptContainer script : projectile.scripts) { if(script.isValid()) { script.run(EnumScriptType.PROJECTILE_TICK, event); @@ -269,6 +284,7 @@ public class EventHooks { } public static void onProjectileImpact(EntityProjectile projectile, ProjectileEvent.ImpactEvent event) { + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.PROJECTILE_IMPACT, event); for(ScriptContainer script : projectile.scripts) { if(script.isValid()) { script.run(EnumScriptType.PROJECTILE_IMPACT, event); @@ -787,49 +803,4 @@ public class EventHooks { handler.callScript(EnumScriptType.PARTY_DISBAND, event); NpcAPI.EVENT_BUS.post(event); } - - private static boolean postAnimationEvent(IAnimationEvent event) { - IScriptHandler handler; - IAnimatable animatable = event.getAnimation().getParent().getEntity(); - if (animatable instanceof ICustomNpc) { - EntityNPCInterface npc = (EntityNPCInterface) ((ICustomNpc) animatable).getMCEntity(); - handler = npc.script; - } else { - handler = ScriptController.Instance.playerScripts; - } - - if (handler.isClient()) - return false; - - handler.callScript(event.getHookName(), (Event) event); - return NpcAPI.EVENT_BUS.post((Event) event); - } - - public static boolean onAnimationStarted(IAnimation animation) { - if (animation.getParent() == null || animation.getParent().getEntity() == null) { - return false; - } - return postAnimationEvent(new AnimationEvent.Started(animation)); - } - - public static void onAnimationEnded(IAnimation animation) { - if (animation.getParent() == null || animation.getParent().getEntity() == null) { - return; - } - postAnimationEvent(new AnimationEvent.Ended(animation)); - } - - public static void onAnimationFrameEntered(IAnimation animation, IFrame frame) { - if (frame == null || animation.getParent() == null || animation.getParent().getEntity() == null) { - return; - } - postAnimationEvent(new AnimationEvent.FrameEvent.Entered(animation, frame)); - } - - public static void onAnimationFrameExited(IAnimation animation, IFrame frame) { - if (frame == null || animation.getParent() == null || animation.getParent().getEntity() == null) { - return; - } - postAnimationEvent(new AnimationEvent.FrameEvent.Exited(animation, frame)); - } } diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index f482fa0cc..45af0cf13 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -479,24 +479,12 @@ public class ServerEventsHandler { @SubscribeEvent public void playerTracking(PlayerEvent.StartTracking event){ - if (event.target.worldObj.isRemote) return; + if(!(event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote) + return; - if(event.target instanceof EntityPlayerMP || event.target instanceof EntityNPCInterface) { - AnimationData animationData = AnimationData.getData(event.target); - if (animationData.isClientAnimating()) { - AnimationData playerAnimData = AnimationData.getData(event.entityPlayer); - Animation currentAnimation = animationData.currentClientAnimation; - NBTTagCompound compound = currentAnimation.writeToNBT(); - playerAnimData.viewAnimation(currentAnimation, animationData, compound, - animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime); - } - - if (event.target instanceof EntityNPCInterface) { - MarkData data = MarkData.get((EntityNPCInterface) event.target); - if (data.marks.isEmpty()) - return; - Server.sendData((EntityPlayerMP) event.entityPlayer, EnumPacketClient.MARK_DATA, event.target.getEntityId(), data.getNBT()); - } - } + MarkData data = MarkData.get((EntityNPCInterface) event.target); + if(data.marks.isEmpty()) + return; + Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.MARK_DATA, event.target.getEntityId(), data.getNBT()); } } diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index 810cc4bf0..4314a83b8 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -1,7 +1,6 @@ package noppes.npcs.client; import net.minecraft.util.ResourceLocation; -import noppes.npcs.CommonProxy; import noppes.npcs.client.gui.OverlayQuestTracking; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.renderer.ImageData; @@ -10,7 +9,6 @@ import noppes.npcs.controllers.data.*; import noppes.npcs.util.CacheHashMap; import java.util.HashMap; -import java.util.HashSet; import java.util.UUID; public class ClientCacheHandler { @@ -20,7 +18,6 @@ public class ClientCacheHandler { public static OverlayQuestTracking questTrackingOverlay = null; public static HashMap customOverlays = new HashMap<>(); public static HashMap> skinOverlays = new HashMap<>(); - public static HashMap playerAnimations = new HashMap<>(); public static Party party; diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 69e248300..c42179714 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -129,9 +129,35 @@ public class ClientEventHandler { ClientEventHandler.playerModel = null; } + if (data != null && data.isActive() && !Minecraft.getMinecraft().isGamePaused()) { + Animation animation = data.animation; + if (data.isActive() && animation.currentFrame().useRenderTicks()) { + animation.increaseTime(); + } + } + ClientEventHandler.renderingNpc = null; } + @SubscribeEvent + public void onUpdateEntity(LivingEvent.LivingUpdateEvent event) { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { + AnimationData data = null; + if (event.entity instanceof EntityNPCInterface) { + data = ((EntityNPCInterface) event.entity).display.animationData; + } else if (event.entity instanceof EntityPlayer && ClientCacheHandler.playerAnimations.containsKey(event.entity.getUniqueID())) { + data = ClientCacheHandler.playerAnimations.get(event.entity.getUniqueID()); + } + + if (data != null && data.isActive()) { + Animation animation = data.animation; + if (data.isActive() && !animation.currentFrame().useRenderTicks()) { + animation.increaseTime(); + } + } + } + } + @SubscribeEvent public void onRenderPlayer(RenderPlayerEvent.Pre event) { ClientEventHandler.renderingPlayer = event.entityPlayer; diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 29d3470c3..e9de292a3 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -80,8 +80,6 @@ public class ClientProxy extends CommonProxy { public static FontContainer Font; public void load() { - this.createAnimationThread(); - Font = new FontContainer(ConfigClient.FontType, ConfigClient.FontSize); createFolders(); CustomNpcs.Channel.register(new PacketHandlerClient()); diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 8938ed01e..e9f3f3b57 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -37,7 +37,7 @@ public class ClientTickHandler{ @SubscribeEvent(priority = EventPriority.LOWEST) public void onClientTick(TickEvent.ClientTickEvent event){ Minecraft mc = Minecraft.getMinecraft(); - if (mc.theWorld != null && this.prevWorld != mc.theWorld) { + if ((this.prevWorld == null || mc.theWorld == null) && this.prevWorld != mc.theWorld) { ClientCacheHandler.clearCache(); this.prevWorld = mc.theWorld; } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index f6efe6c34..07f025119 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -379,14 +379,8 @@ public class PacketHandlerClient extends PacketHandlerServer{ } animationData.setAnimation(ClientCacheHandler.animationCache.get(animationId)); - animationData.viewReadFromNBT(compound); - - if (compound.hasKey("Frame")) { - animationData.animation.readFromNBT(compound.getCompoundTag("Animation")); - animationData.animation.jumpToFrameAtTime(compound.getInteger("Frame"), compound.getInteger("Time")); - } else if (compound.hasKey("Animation")) { - Client.sendData(EnumPacketServer.CacheAnimation, animationId); - } + animationData.readFromNBT(compound); + Client.sendData(EnumPacketServer.CacheAnimation, animationId); } } else if(type == EnumPacketClient.DISABLE_MOUSE_INPUT) { diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiAnimationFrame.java b/src/main/java/noppes/npcs/client/gui/SubGuiAnimationFrame.java index 62837a495..f719b649b 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiAnimationFrame.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiAnimationFrame.java @@ -6,54 +6,48 @@ import noppes.npcs.controllers.data.Frame; public class SubGuiAnimationFrame extends SubGuiInterface implements ITextfieldListener { private final Frame editingFrame; - + public SubGuiAnimationFrame(Frame editingFrame) { this.editingFrame = editingFrame; setBackground("smallbg.png"); } - + @Override public void initGui() { super.initGui(); // //customized - button, enables all the following options. this.addLabel(new GuiNpcLabel(10, "animation.customized", guiLeft + 5, guiTop + 16)); - this.addButton(new GuiNpcButton(10, guiLeft + 75, guiTop + 10, 30, 20, new String[]{"gui.yes", "gui.no"}, editingFrame.isCustomized() ? 0 : 1)); + this.addButton(new GuiNpcButton(10, guiLeft + 65, guiTop + 10, 30, 20, new String[]{"gui.yes", "gui.no"}, editingFrame.isCustomized() ? 0 : 1)); if (editingFrame.isCustomized()) { // //speed - textfield - this.addLabel(new GuiNpcLabel(11, "stats.speed", guiLeft + 5, guiTop + 42)); - this.addTextField(new GuiNpcTextField(11, this, guiLeft + 75, guiTop + 37, 30, 15, editingFrame.speed + "")); + this.addLabel(new GuiNpcLabel(11, "stats.speed", guiLeft + 5, guiTop + 36)); + this.addTextField(new GuiNpcTextField(11, this, guiLeft + 65, guiTop + 32, 30, 15, editingFrame.speed + "")); this.getTextField(11).floatsOnly = true; this.getTextField(11).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 1.0F); // //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)); + this.addLabel(new GuiNpcLabel(12, "animation.smoothing", guiLeft + 5, guiTop + 58)); + this.addButton(new GuiNpcButton(12, guiLeft + 65, guiTop + 52, 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); + //ticks - button + this.addLabel(new GuiNpcLabel(13, "animation.tickType", guiLeft + 5, guiTop + 78)); + this.addButton(new GuiNpcButton(13, guiLeft + 65, guiTop + 72, 75, 20, new String[]{"animation.renderTicks", "animation.mcTicks"}, editingFrame.renderTicks ? 0 : 1)); } - - this.addLabel(new GuiNpcLabel(14, "Comment", guiLeft + 5, guiTop + 106)); - this.addTextField(new GuiNpcTextField(14, this, guiLeft + 50, guiTop + 101, 120, 15, editingFrame.getComment())); } @Override protected void actionPerformed(GuiButton guibutton) { super.actionPerformed(guibutton); - if (this.editingFrame == null) { - return; - } - int value = ((GuiNpcButton)guibutton).getValue(); - if (guibutton.id == 10) { + + if (guibutton.id == 10 && editingFrame != null) { editingFrame.setCustomized(!editingFrame.isCustomized()); - } else if (guibutton.id == 12) { + } else if (guibutton.id == 12 && editingFrame != null) { editingFrame.smooth = (byte) value; + } else if (guibutton.id == 13 && editingFrame != null) { + editingFrame.renderTicks = value == 0; } initGui(); @@ -61,16 +55,8 @@ public class SubGuiAnimationFrame extends SubGuiInterface implements ITextfieldL @Override public void unFocused(GuiNpcTextField textfield) { - if (this.editingFrame == null) { - return; - } - - if (textfield.id == 11) { + if (textfield.id == 11 && this.editingFrame != null) { 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()); } } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiAnimationOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiAnimationOptions.java index 1f3b7f0d1..4a0724644 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiAnimationOptions.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiAnimationOptions.java @@ -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) { @@ -17,10 +19,8 @@ public class SubGuiAnimationOptions extends SubGuiInterface implements ITextfiel 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); + this.addLabel(new GuiNpcLabel(10, "animation.tickType", guiLeft + 5, guiTop + 16)); + this.addButton(new GuiNpcButton(10, guiLeft + 60, guiTop + 10, 75, 20, new String[]{"animation.renderTicks", "animation.mcTicks"}, animation.renderTicks ? 0 : 1)); // //whileStanding - button this.addLabel(new GuiNpcLabel(11, "animation.whileStanding", guiLeft + 5, guiTop + 36)); @@ -40,7 +40,9 @@ public class SubGuiAnimationOptions extends SubGuiInterface implements ITextfiel super.actionPerformed(guibutton); int value = ((GuiNpcButton)guibutton).getValue(); - if (guibutton.id == 11) { + if (guibutton.id == 10) { + animation.renderTicks = value == 0; + } else if (guibutton.id == 11) { animation.whileStanding = value == 0; } else if (guibutton.id == 12) { animation.whileAttacking = value == 0; @@ -50,11 +52,4 @@ public class SubGuiAnimationOptions extends SubGuiInterface implements ITextfiel initGui(); } - - @Override - public void unFocused(GuiNpcTextField textfield) { - if (textfield.id == 10) { - animation.tickDuration = textfield.getInteger(); - } - } } diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCEditAnimation.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCEditAnimation.java index 6991e54be..70c3a9470 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCEditAnimation.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCEditAnimation.java @@ -23,16 +23,14 @@ import java.util.Map; public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfieldListener, ISliderListener, ISubGuiListener { private final Animation animation; - private static int partEditMode; - private static int sliderSelection = 0; - private static Frame copiedFrame; - private EnumAnimationPart editingPart = EnumAnimationPart.HEAD; private int frameIndex = 0; public boolean playingAnimation = false; private Frame prevFrame; private final GuiScreen parent; private long prevTick; + private static int partEditMode; + private static int sliderSelection = 0; private final GuiNpcSlider[] rotationSliders = new GuiNpcSlider[3]; private final GuiNpcSlider[] pivotSliders = new GuiNpcSlider[3]; @@ -51,7 +49,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield this.animation = animation; AnimationData data = npc.display.animationData; - data.setAnimation(animation); + data.animation = animation; data.setEnabled(true); int bodyPartX = 280; @@ -94,9 +92,9 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield AnimationData data = npc.display.animationData; if (!playingAnimation) { - data.setAnimation(new Animation()); + data.animation = new Animation(); data.animation.smooth = animation.smooth; - data.animation.tickDuration = 50; + data.animation.renderTicks = animation.renderTicks; data.animation.loop = 0; if (editingFrame != null) { data.animation.frames.add(editingFrame); @@ -109,7 +107,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield if (!frame.isCustomized()) { frame.speed = animation.speed; frame.smooth = animation.smooth; - frame.tickDuration = animation.tickDuration(); + frame.renderTicks = animation.renderTicks; } for (Map.Entry entry : frame.frameParts.entrySet()) { FramePart part = entry.getValue(); @@ -403,7 +401,13 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield AnimationData data = npc.display.animationData; if (guibutton.id == 11) { - this.addFrame(); + if (frameIndex < animation.frames.size() - 1) { + animation.frames.add(frameIndex + 1, new Frame(10)); + } else { + animation.frames.add(new Frame(10)); + } + this.frameIndex = frameIndex + 1; + updateFrameSlider(); } else if (guibutton.id == 12) { animation.frames.remove(frameIndex); updateFrameSlider(); @@ -471,7 +475,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield } } this.playingAnimation = true; - data.setAnimation(this.animation); + data.animation = animation; data.animation.paused = false; } else if (guibutton.id == 201) { data.animation.paused = true; @@ -497,20 +501,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield initGui(); } - private void addFrame() { - this.addFrame(new Frame(10)); - } - - private void addFrame(Frame frame) { - if (frameIndex < animation.frames.size() - 1) { - animation.frames.add(frameIndex + 1, frame); - } else { - animation.frames.add(frame); - } - this.frameIndex = frameIndex + 1; - updateFrameSlider(); - } - @Override public void drawScreen(int par1, int par2, float par3) { @@ -520,8 +510,12 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield this.playingAnimation = false; initGui(); } else if (data.isActive()) { + Frame currentFrame = (Frame) data.animation.currentFrame(); long time = mc.theWorld.getTotalWorldTime(); if (time != prevTick) { + if (currentFrame != null && !currentFrame.renderTicks) { + data.animation.increaseTime(); + } GuiNpcLabel label = this.getLabel(213); if (label != null) { label.label += "."; @@ -649,28 +643,4 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield editingFrame.setColorMarker(((SubGuiColorSelector) subgui).color); } } - - @Override - public void keyTyped(char par1, int par2) { - super.keyTyped(par1, par2); - - if (GuiScreen.isCtrlKeyDown() && par2 != 29 && !GuiNpcTextField.isFieldActive()) { - switch (par2) { - case 46: - if (this.editingFrame() != null) { - copiedFrame = this.editingFrame(); - } - break; - case 47: - if (copiedFrame != null) { - Frame frame = new Frame(10); - frame.parent = this.animation; - frame.readFromNBT(copiedFrame.writeToNBT()); - this.addFrame(frame); - this.initGui(); - } - break; - } - } - } } diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java index e5b5d07a5..cbcdd0ed1 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java @@ -63,9 +63,9 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol AnimationData data = npc.display.animationData; if (!playingAnimation) { - data.setAnimation(new Animation()); + data.animation = new Animation(); data.animation.smooth = animation.smooth; - data.animation.tickDuration = 50; + data.animation.renderTicks = animation.renderTicks; data.animation.loop = 0; if (this.animation.frames.size() > 0) { @@ -109,8 +109,12 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol this.playingAnimation = false; initGui(); } else if (data.isActive()) { + Frame currentFrame = (Frame) data.animation.currentFrame(); long time = mc.theWorld.getTotalWorldTime(); if (time != prevTick) { + if (currentFrame != null && !currentFrame.renderTicks) { + data.animation.increaseTime(); + } GuiNpcLabel label = this.getLabel(94); if (label != null) { label.label += "."; @@ -182,7 +186,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol } } this.playingAnimation = true; - data.setAnimation(this.animation); + data.animation = animation; data.animation.paused = false; } else if (guibutton.id == 92) { data.animation.paused = true; @@ -203,7 +207,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol this.animation = new Animation(); animation.readFromNBT(compound); setSelected(animation.name); - npc.display.animationData.setAnimation(this.animation); + npc.display.animationData.animation = animation; this.playingAnimation = false; npc.display.animationData.animation.paused = false; initGui(); diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index fd968a716..a8f233f47 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -99,27 +99,13 @@ public enum EnumScriptType { PARTY_INVITE("partyInvite"), PARTY_KICK("partyKick"), PARTY_LEAVE("partyLeave"), - PARTY_DISBAND("partyDisband"), - - ANIMATION_START("animationStart"), - ANIMATION_END("animationEnd"), - ANIMATION_FRAME_ENTER("frameEnter"), - ANIMATION_FRAME_EXIT("frameExit"); + PARTY_DISBAND("partyDisband"); public String function; public static EnumScriptType valueOfIgnoreCase(String channelName) { channelName = channelName.toUpperCase(); - try { - return valueOf(channelName); - } catch (IllegalArgumentException exception) { - for (EnumScriptType value : EnumScriptType.values()) { - if (value.function.toUpperCase().equals(channelName)) { - return value; - } - } - throw exception; - } + return valueOf(channelName); } private EnumScriptType(String function) { diff --git a/src/main/java/noppes/npcs/controllers/data/Animation.java b/src/main/java/noppes/npcs/controllers/data/Animation.java index be05ef4e1..569ff7614 100644 --- a/src/main/java/noppes/npcs/controllers/data/Animation.java +++ b/src/main/java/noppes/npcs/controllers/data/Animation.java @@ -1,15 +1,10 @@ package noppes.npcs.controllers.data; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import noppes.npcs.CustomNpcs; -import noppes.npcs.DataDisplay; -import noppes.npcs.EventHooks; import noppes.npcs.api.handler.data.IAnimation; -import noppes.npcs.api.handler.data.IAnimationData; import noppes.npcs.api.handler.data.IFrame; import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.controllers.AnimationController; @@ -29,7 +24,7 @@ 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 renderTicks = false; // If true, MC ticks are used. If false, render ticks are used. public boolean whileStanding = true; public boolean whileAttacking = true; @@ -53,10 +48,6 @@ public class Animation implements IAnimation { this.id = id; } - public IAnimationData getParent() { - return this.parent; - } - public IFrame currentFrame() { return currentFrame < frames.size() ? frames.get(currentFrame) : null; } @@ -102,15 +93,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; @@ -129,6 +111,15 @@ public class Animation implements IAnimation { return this.smooth; } + public IAnimation useRenderTicks(boolean renderTicks) { + this.renderTicks = renderTicks; + return this; + } + + public boolean useRenderTicks() { + return this.renderTicks; + } + public IAnimation doWhileStanding(boolean whileStanding) { this.whileStanding = whileStanding; return this; @@ -179,14 +170,6 @@ public class Animation implements IAnimation { id = newID; } - public long getTotalTime() { - long time = 0; - for (Frame frame : this.frames) { - time += (long) frame.duration * (frame.customized ? frame.tickDuration : this.tickDuration); - } - return time; - } - public void readFromNBT(NBTTagCompound compound){ if(compound.hasKey("ID")){ id = compound.getInteger("ID"); @@ -200,11 +183,7 @@ 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; - } + renderTicks = compound.getBoolean("RenderTicks"); ArrayList frames = new ArrayList(); NBTTagList list = compound.getTagList("Frames", 10); @@ -220,9 +199,6 @@ public class Animation implements IAnimation { this.whileStanding = compound.getBoolean("WhileStanding"); this.whileMoving = compound.getBoolean("WhileWalking"); this.whileAttacking = compound.getBoolean("WhileAttacking"); - - this.currentFrame = compound.getInteger("CurrentFrame"); - this.currentFrameTime = compound.getInteger("CurrentFrameTime"); } public NBTTagCompound writeToNBT(){ @@ -232,7 +208,8 @@ public class Animation implements IAnimation { compound.setFloat("Speed", speed); compound.setByte("Smooth", smooth); compound.setInteger("Loop",loop); - compound.setInteger("TickDuration", tickDuration); + + compound.setBoolean("RenderTicks", renderTicks); NBTTagList list = new NBTTagList(); for(Frame frame : frames){ @@ -244,24 +221,20 @@ public class Animation implements IAnimation { compound.setBoolean("WhileStanding", whileStanding); compound.setBoolean("WhileWalking", whileMoving); compound.setBoolean("WhileAttacking", whileAttacking); - - compound.setInteger("CurrentFrame", currentFrame); - compound.setInteger("CurrentFrameTime", currentFrameTime); return compound; } - public boolean increaseTime() { + @SideOnly(Side.CLIENT) + public void increaseTime() { if (paused) - return false; + return; if (this.parent != null && this.currentFrame < this.frames.size()) { this.parent.finishedFrame = this.currentFrame; } this.currentFrameTime++; - if (this.currentFrame() != null && this.currentFrameTime == this.currentFrame().getDuration()) { - EventHooks.onAnimationFrameExited(this, this.currentFrame()); - + if (this.currentFrameTime == this.currentFrame().getDuration()) { Frame prevFrame = (Frame) this.currentFrame(); Frame nextFrame = null; this.currentFrameTime = 0; @@ -271,13 +244,6 @@ public class Animation implements IAnimation { } else if (this.loop >= 0 && this.loop < this.frames.size()) { this.currentFrame = this.loop; } - - if (this.currentFrame() != null) { - EventHooks.onAnimationFrameEntered(this, this.currentFrame()); - } else { - EventHooks.onAnimationEnded(this); - } - if (nextFrame != null) { for (EnumAnimationPart part : EnumAnimationPart.values()) { if (prevFrame.frameParts.containsKey(part) && nextFrame.frameParts.containsKey(part)) { @@ -286,32 +252,23 @@ public class Animation implements IAnimation { } } } else if (this.parent != null && this.currentFrame > this.loop) { - this.parent.finishedTime = this.parent.getMCEntity().getAge(); + this.parent.finishedTime = this.parent.animationEntity.getAge(); } } - - return true; } @SideOnly(Side.CLIENT) public void jumpToCurrentFrame() { - this.jumpToFrameAtTime(this.currentFrame, 0); + this.currentFrameTime = 0; + Frame frame = (Frame) this.currentFrame(); + if(frame != null){ + for (EnumAnimationPart part : EnumAnimationPart.values()) { + if(part != null){ + if (frame.frameParts.containsKey(part)) { + frame.frameParts.get(part).jumpToCurrentFrame(); + } + } + } + } } - - @SideOnly(Side.CLIENT) - public void jumpToFrameAtTime(int frameIndex, int time) { - this.currentFrame = frameIndex; - this.currentFrameTime = time; - - Frame frame = (Frame) this.currentFrame(); - if(frame != null){ - for (EnumAnimationPart part : EnumAnimationPart.values()) { - if(part != null){ - if (frame.frameParts.containsKey(part)) { - frame.frameParts.get(part).jumpToCurrentFrame(); - } - } - } - } - } } diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index a7d120672..37528ce95 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -1,24 +1,21 @@ package noppes.npcs.controllers.data; -import net.minecraft.entity.Entity; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; import net.minecraft.entity.EntityLivingBase; 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.*; -import noppes.npcs.api.entity.IAnimatable; -import noppes.npcs.api.entity.ICustomNpc; -import noppes.npcs.api.entity.IEntity; -import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.DataDisplay; +import noppes.npcs.Server; import noppes.npcs.api.handler.data.IAnimation; import noppes.npcs.api.handler.data.IAnimationData; import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.NpcAPI; import java.util.Arrays; import java.util.HashSet; @@ -32,48 +29,20 @@ public class AnimationData implements IAnimationData { public Animation animation; public boolean allowAnimation = false; - public long animatingTime = 0; - - public Animation currentClientAnimation; - private boolean isClientAnimating; private final HashSet cachedAnimationIDs = new HashSet<>(); //Client-side values + public EntityLivingBase animationEntity; public int finishedTime = -1; public int finishedFrame = -1; public AnimationData(Object parent){ this.parent = parent; - } - - public static AnimationData getData(Entity entity) { - if (entity instanceof EntityPlayerMP) { - return PlayerData.get((EntityPlayer) entity).animationData; - } else if (entity instanceof EntityNPCInterface) { - return ((EntityNPCInterface)entity).display.animationData; - } else { - return null; - } - } - - public IAnimatable getEntity() { - IEntity entity = NpcAPI.Instance().getIEntity(this.getMCEntity()); - if (entity instanceof IAnimatable) { - return (IAnimatable) entity; - } - return null; - } - - public EntityLivingBase getMCEntity() { - if (this.parent instanceof DataDisplay) { - return ((DataDisplay) this.parent).npc; - } else { - if (this.parent instanceof PlayerData) { - return ((PlayerData) this.parent).player; - } else { - return (EntityPlayer) this.parent; - } + if (parent instanceof DataDisplay) { + this.animationEntity = ((DataDisplay) parent).npc; + } else if (parent instanceof EntityPlayer) { + this.animationEntity = (EntityLivingBase) parent; } } @@ -88,30 +57,6 @@ public class AnimationData implements IAnimationData { if(sendingEntity.dimension != sendingEntity.worldObj.provider.dimensionId) sendingEntity.dimension = sendingEntity.worldObj.provider.dimensionId; - this.animatingTime = 0; - - boolean prevIsClientAnimating = this.isClientAnimating && this.currentClientAnimation.currentFrame() != null; - this.isClientAnimating = this.allowAnimation && this.animation != null; - if (prevIsClientAnimating && (!this.isClientAnimating || this.animation != this.currentClientAnimation)) { - EventHooks.onAnimationEnded(this.currentClientAnimation); - } - if (this.isClientAnimating) { - this.currentClientAnimation = this.animation; - } - - if (this.animation != null && this.allowAnimation) { - if (EventHooks.onAnimationStarted(this.animation)) - return; - 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 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)); @@ -124,21 +69,13 @@ public class AnimationData implements IAnimationData { if (animationNBT == null && this.animation != null && !animationData.isCached(this.animation.getID())) { animationNBT = this.animation.writeToNBT(); } - animationData.viewAnimation(this.animation, this, animationNBT); + animationData.viewAnimation(this.animation, sendingEntity, this, animationNBT); } } } - public boolean isClientAnimating() { - return this.isClientAnimating; - } - public boolean isActive() { - return this.isActive(this.animation); - } - - public boolean isActive(Animation animation) { - if (!this.allowAnimation || animation == null || animation.currentFrame == animation.frames.size() || animation.currentFrame() == null) + if (!this.allowAnimation || this.animation == null || this.animation.currentFrame == this.animation.frames.size() || animation.currentFrame() == null) return false; if (this.parent instanceof DataDisplay) { @@ -163,22 +100,6 @@ public class AnimationData implements IAnimationData { } } - public void increaseTime() { - Animation updateAnimation = null; - if (this.isActive()) { - updateAnimation = this.animation; - } else if (this.isActive(animation.parent.currentClientAnimation)) { - updateAnimation = this.currentClientAnimation; - } - - if (updateAnimation != null && updateAnimation.increaseTime()) { - Frame frame = (Frame) updateAnimation.currentFrame(); - if (frame != null) { - this.animatingTime += frame.customized ? frame.tickDuration : updateAnimation.tickDuration; - } - } - } - public boolean isCached(int id) { return this.cachedAnimationIDs.contains(id); } @@ -195,63 +116,27 @@ public class AnimationData implements IAnimationData { this.cachedAnimationIDs.clear(); } - public void viewAnimation(Animation animation, AnimationData animationData, NBTTagCompound animationNBT) { - this.viewAnimation(animation, animationData, animationNBT, animationData.allowAnimation, -1, -1); - } - - public void viewAnimation(Animation animation, AnimationData animationData, NBTTagCompound animationNBT, boolean enabled, int currentFrame, int time) { - boolean prevEnabled = animationData.allowAnimation; - animationData.allowAnimation = enabled; - NBTTagCompound data = animationData.viewWriteNBT(new NBTTagCompound()); - animationData.allowAnimation = prevEnabled; - - if (animation != null && currentFrame >= 0 && currentFrame < animation.frames.size()) { - data.setInteger("Frame", currentFrame); - data.setInteger("Time", time); - } - + public void viewAnimation(Animation animation, EntityLivingBase entity, AnimationData animationData, NBTTagCompound animationNBT) { + NBTTagCompound data = animationData.writeToNBT(new NBTTagCompound()); if (animation != null) { - if (this.cachedAnimationIDs.contains(animation.getID()) && !data.hasKey("Frame")) { + if (this.cachedAnimationIDs.contains(animation.getID())) { data.setInteger("AnimationID", animation.getID()); } else { data.setTag("Animation", animationNBT); } } - - IAnimatable animatable = animationData.getEntity(); - Entity entity = ((IEntity) animatable).getMCEntity(); if (!(entity instanceof EntityPlayer)) { data.setInteger("EntityId", entity.getEntityId()); } - Server.sendData((EntityPlayerMP) ((PlayerData) parent).player, EnumPacketClient.UPDATE_ANIMATIONS, data, entity.getCommandSenderName()); } - public NBTTagCompound viewWriteNBT(NBTTagCompound compound) { - compound.setBoolean("AllowAnimation", allowAnimation); - return compound; - } - - public void viewReadFromNBT(NBTTagCompound compound) { - this.setEnabled(compound.getBoolean("AllowAnimation")); - } - public NBTTagCompound writeToNBT(NBTTagCompound compound) { - if (this.currentClientAnimation != null) { - compound.setTag("CurrentAnimation", currentClientAnimation.writeToNBT()); - compound.setBoolean("IsClientAnimating", isClientAnimating); - } compound.setBoolean("AllowAnimation", allowAnimation); return compound; } public void readFromNBT(NBTTagCompound compound) { - if (compound.hasKey("CurrentAnimation")) { - this.currentClientAnimation = new Animation(); - this.currentClientAnimation.parent = this; - this.currentClientAnimation.readFromNBT(compound.getCompoundTag("CurrentAnimation")); - this.isClientAnimating = compound.getBoolean("IsClientAnimating"); - } this.setEnabled(compound.getBoolean("AllowAnimation")); } @@ -269,50 +154,33 @@ public class AnimationData implements IAnimationData { } public void setAnimation(IAnimation animation) { - Animation newAnim = null; - if (animation != null) { - newAnim = new Animation(); + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + this.animation = (Animation) animation; + } else { + Animation newAnim = new Animation(); newAnim.readFromNBT(((Animation) animation).writeToNBT()); - newAnim.currentFrame = 0; - newAnim.currentFrameTime = 0; - newAnim.parent = this; - } - - - if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote && newAnim != null) { - this.animatingTime = 0; - synchronized (CommonProxy.clientPlayingAnimations) { - CommonProxy.clientPlayingAnimations.add(this); - } - } - - Animation prevAnim = this.animation; - this.animation = newAnim; - - if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote && - this.isActive() && prevAnim != null && newAnim != null && !newAnim.frames.isEmpty()) { - Frame frame = (Frame) prevAnim.currentFrame(); - if (frame != null) { - Frame firstFrame = newAnim.frames.get(0); - for (Map.Entry entry : frame.frameParts.entrySet()) { - if (firstFrame.frameParts.containsKey(entry.getKey())) { - FramePart prevFramePart = entry.getValue(); - FramePart newFramePart = firstFrame.frameParts.get(entry.getKey()); - for (int i = 0; i < 3; i++) { - newFramePart.prevPivots[i] = prevFramePart.prevPivots[i]; - newFramePart.prevRotations[i] = prevFramePart.prevRotations[i]; + if (this.isActive() && !newAnim.frames.isEmpty()) { + Frame frame = (Frame) this.animation.currentFrame(); + if (frame != null) { + Frame firstFrame = newAnim.frames.get(0); + for (Map.Entry entry : frame.frameParts.entrySet()) { + if (firstFrame.frameParts.containsKey(entry.getKey())) { + FramePart prevFramePart = entry.getValue(); + FramePart newFramePart = firstFrame.frameParts.get(entry.getKey()); + for (int i = 0; i < 3; i++) { + newFramePart.prevPivots[i] = prevFramePart.prevPivots[i]; + newFramePart.prevRotations[i] = prevFramePart.prevRotations[i]; + } } } } } + this.animation = newAnim; + newAnim.parent = this; } } public IAnimation getAnimation() { return animation; } - - public long getAnimatingTime() { - return this.animatingTime; - } } diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index d567f11d2..d1530f63d 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -236,14 +236,13 @@ public class DataScript implements INpcScriptHandler { @Override public void callScript(EnumScriptType type, Event event) { - ScriptController.Instance.globalNpcScripts.callScript(type, event); callScript(type, event, "$$IGNORED$$", null); } @Override public void callScript(String hookName, Event event) { try { - EnumScriptType enumScriptType = EnumScriptType.valueOfIgnoreCase(hookName); + EnumScriptType enumScriptType = EnumScriptType.valueOf(hookName); this.callScript(enumScriptType, event); } catch (IllegalArgumentException ignored) {} } diff --git a/src/main/java/noppes/npcs/controllers/data/Frame.java b/src/main/java/noppes/npcs/controllers/data/Frame.java index 004d80c28..df80096bd 100644 --- a/src/main/java/noppes/npcs/controllers/data/Frame.java +++ b/src/main/java/noppes/npcs/controllers/data/Frame.java @@ -14,14 +14,12 @@ public class Frame implements IFrame { public Animation parent; public HashMap frameParts = new HashMap<>(); public int duration = 0; - public int tickDuration = 50; - boolean customized = false; public float speed = 1.0F; public byte smooth = 0; + public boolean renderTicks = false; // If true, MC ticks are used. If false, render ticks are used. private int colorMarker = 0xFFFFFF; - private String comment = ""; public Frame(){} @@ -77,15 +75,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; } @@ -113,6 +102,15 @@ public class Frame implements IFrame { return this; } + public IFrame useRenderTicks(boolean renderTicks) { + this.renderTicks = renderTicks; + return this; + } + + public boolean useRenderTicks() { + return this.renderTicks; + } + public int getColorMarker() { return this.colorMarker; } @@ -121,22 +119,11 @@ public class Frame implements IFrame { this.colorMarker = color; } - public String getComment() { - return this.comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - public void readFromNBT(NBTTagCompound compound){ duration = compound.getInteger("Duration"); if (compound.hasKey("ColorMarker")) { this.setColorMarker(compound.getInteger("ColorMarker")); } - if (compound.hasKey("Comment")) { - this.comment = compound.getString("Comment"); - } // Customized = TRUE if Speed or Smooth Exist if(compound.hasKey("Speed")){ @@ -147,19 +134,15 @@ public class Frame implements IFrame { customized = true; smooth = compound.getByte("Smooth"); } - - if (compound.hasKey("TickDuration")) { - customized = true; - this.tickDuration = compound.getInteger("TickDuration"); - } else if(compound.hasKey("RenderTicks")){ + if(compound.hasKey("RenderTicks")){ customized = true; - this.tickDuration = compound.getBoolean("RenderTicks") ? 20 : 50; + renderTicks = compound.getBoolean("RenderTicks"); } - if (!customized && parent != null) { + if (!customized) { this.speed = parent.speed; this.smooth = parent.smooth; - this.tickDuration = parent.tickDuration; + this.renderTicks = parent.renderTicks; } HashMap frameParts = new HashMap<>(); @@ -181,12 +164,11 @@ public class Frame implements IFrame { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("Duration", duration); compound.setInteger("ColorMarker", this.colorMarker); - compound.setString("Comment", this.comment); if(customized){ compound.setFloat("Speed", speed); compound.setByte("Smooth", smooth); - compound.setInteger("TickDuration", tickDuration); + compound.setBoolean("RenderTicks", renderTicks); } NBTTagList list = new NBTTagList(); @@ -209,7 +191,7 @@ public class Frame implements IFrame { frame.customized = this.customized; frame.speed = this.speed; frame.smooth = this.smooth; - frame.tickDuration = this.tickDuration; + frame.renderTicks = this.renderTicks; frame.colorMarker = this.colorMarker; return frame; } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index dbd618fa5..85096dfe0 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -1,7 +1,6 @@ package noppes.npcs.controllers.data; import com.google.common.base.Preconditions; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; @@ -98,7 +97,7 @@ public class PlayerDataScript implements INpcScriptHandler { } public boolean isClient() { - return false; + return this.player.isClientWorld(); } public boolean getEnabled() { return ScriptController.Instance.playerScripts.enabled; diff --git a/src/main/java/noppes/npcs/scripted/event/AnimationEvent.java b/src/main/java/noppes/npcs/scripted/event/AnimationEvent.java deleted file mode 100644 index 1690f8e57..000000000 --- a/src/main/java/noppes/npcs/scripted/event/AnimationEvent.java +++ /dev/null @@ -1,108 +0,0 @@ -package noppes.npcs.scripted.event; - -import cpw.mods.fml.common.eventhandler.Cancelable; -import noppes.npcs.api.entity.IAnimatable; -import noppes.npcs.api.event.IAnimationEvent; -import noppes.npcs.api.handler.data.IAnimation; -import noppes.npcs.api.handler.data.IAnimationData; -import noppes.npcs.api.handler.data.IFrame; -import noppes.npcs.constants.EnumScriptType; -import noppes.npcs.controllers.data.Animation; -import noppes.npcs.controllers.data.Frame; - -public abstract class AnimationEvent extends CustomNPCsEvent implements IAnimationEvent { - protected final IAnimation animation; - protected final IAnimationData animationData; - protected final IAnimatable entity; - - public AnimationEvent(IAnimation animation) { - this.animation = animation; - this.animationData = animation.getParent(); - this.entity = this.animationData.getEntity(); - } - - @Override - public IAnimation getAnimation() { - return this.animation; - } - - @Override - public IAnimationData getAnimationData() { - return this.animationData; - } - - @Override - public IAnimatable getEntity() { - return this.entity; - } - - @Cancelable - public static class Started extends AnimationEvent { - - public Started(IAnimation animation) { - super(animation); - } - - @Override - public String getHookName() { - return EnumScriptType.ANIMATION_START.function; - } - } - - public static class Ended extends AnimationEvent { - - public Ended(IAnimation animation) { - super(animation); - } - - @Override - public String getHookName() { - return EnumScriptType.ANIMATION_END.function; - } - } - - public static abstract class FrameEvent extends AnimationEvent implements IFrameEvent { - private final IFrame frame; - private final int index; - - public FrameEvent(IAnimation animation, IFrame frame) { - super(animation); - this.frame = frame; - this.index = ((Animation)this.getAnimation()).frames.indexOf((Frame) this.frame); - } - - @Override - public int getIndex() { - return this.index; - } - - @Override - public IFrame getFrame() { - return this.frame; - } - - public static class Entered extends FrameEvent { - - public Entered(IAnimation animation, IFrame frame) { - super(animation, frame); - } - - @Override - public String getHookName() { - return EnumScriptType.ANIMATION_FRAME_ENTER.function; - } - } - - public static class Exited extends FrameEvent { - - public Exited(IAnimation animation, IFrame frame) { - super(animation, frame); - } - - @Override - public String getHookName() { - return EnumScriptType.ANIMATION_FRAME_EXIT.function; - } - } - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/BlockEvent.java b/src/main/java/noppes/npcs/scripted/event/BlockEvent.java index 48a03ec9e..3367a1699 100644 --- a/src/main/java/noppes/npcs/scripted/event/BlockEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/BlockEvent.java @@ -11,7 +11,7 @@ import noppes.npcs.api.event.IBlockEvent; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.scripted.NpcAPI; -public abstract class BlockEvent extends CustomNPCsEvent implements IBlockEvent { +public class BlockEvent extends CustomNPCsEvent implements IBlockEvent { public IBlock block; public BlockEvent(IBlock block){ this.block = block; diff --git a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java index a62c02156..130a6657c 100644 --- a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java @@ -10,7 +10,7 @@ import noppes.npcs.api.item.IItemStack; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.scripted.NpcAPI; -public abstract class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { +public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { public final IPlayer player; public final ICustomGui gui; diff --git a/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java index 2e77b5aff..0a0dfd2bb 100644 --- a/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java @@ -9,10 +9,12 @@ import noppes.npcs.api.event.ICustomNPCsEvent; import noppes.npcs.api.handler.data.INaturalSpawn; import noppes.npcs.constants.EnumScriptType; -public abstract class CustomNPCsEvent extends Event implements ICustomNPCsEvent { +public class CustomNPCsEvent extends Event implements ICustomNPCsEvent { public final AbstractNpcAPI API = AbstractNpcAPI.Instance(); - public abstract String getHookName(); + public String getHookName() { + return "CNPCEvent"; + } public CustomNPCsEvent() { } diff --git a/src/main/java/noppes/npcs/scripted/event/DialogEvent.java b/src/main/java/noppes/npcs/scripted/event/DialogEvent.java index a3dfb671b..84ace0ee7 100644 --- a/src/main/java/noppes/npcs/scripted/event/DialogEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/DialogEvent.java @@ -6,7 +6,7 @@ import noppes.npcs.api.event.IDialogEvent; import noppes.npcs.api.handler.data.IDialog; import noppes.npcs.constants.EnumScriptType; -public abstract class DialogEvent extends CustomNPCsEvent implements IDialogEvent { +public class DialogEvent extends CustomNPCsEvent implements IDialogEvent { public final IDialog dialog; public final IPlayer player; diff --git a/src/main/java/noppes/npcs/scripted/event/FactionEvent.java b/src/main/java/noppes/npcs/scripted/event/FactionEvent.java index ed0aca4a1..2741b669b 100644 --- a/src/main/java/noppes/npcs/scripted/event/FactionEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/FactionEvent.java @@ -6,7 +6,7 @@ import noppes.npcs.api.event.IFactionEvent; import noppes.npcs.api.handler.data.IFaction; import noppes.npcs.constants.EnumScriptType; -public abstract class FactionEvent extends CustomNPCsEvent implements IFactionEvent { +public class FactionEvent extends CustomNPCsEvent implements IFactionEvent { public final IFaction faction; public final IPlayer player; diff --git a/src/main/java/noppes/npcs/scripted/event/ItemEvent.java b/src/main/java/noppes/npcs/scripted/event/ItemEvent.java index 23881e9ad..d94c0448b 100644 --- a/src/main/java/noppes/npcs/scripted/event/ItemEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/ItemEvent.java @@ -7,7 +7,7 @@ import noppes.npcs.api.event.IItemEvent; import noppes.npcs.api.item.IItemCustom; import noppes.npcs.constants.EnumScriptType; -public abstract class ItemEvent extends CustomNPCsEvent implements IItemEvent { +public class ItemEvent extends CustomNPCsEvent implements IItemEvent { public final IItemCustom item; public ItemEvent(IItemCustom item) { diff --git a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java index 1631f3d9d..98c51e6ba 100644 --- a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java @@ -20,7 +20,7 @@ import noppes.npcs.scripted.NpcAPI; import java.util.ArrayList; -public abstract class NpcEvent extends CustomNPCsEvent implements INpcEvent { +public class NpcEvent extends CustomNPCsEvent implements INpcEvent { public final ICustomNpc npc; public NpcEvent(ICustomNpc npc) { diff --git a/src/main/java/noppes/npcs/scripted/event/PartyEvent.java b/src/main/java/noppes/npcs/scripted/event/PartyEvent.java index adaacc81f..d1df03e8d 100644 --- a/src/main/java/noppes/npcs/scripted/event/PartyEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PartyEvent.java @@ -7,7 +7,7 @@ import noppes.npcs.api.handler.data.IParty; import noppes.npcs.api.handler.data.IQuest; import noppes.npcs.constants.EnumScriptType; -public abstract class PartyEvent extends CustomNPCsEvent implements IPartyEvent { +public class PartyEvent extends CustomNPCsEvent implements IPartyEvent { public final IQuest quest; public final IParty party; diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index 0a57d95a5..e181668ac 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -18,7 +18,7 @@ import noppes.npcs.api.item.IItemStack; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.scripted.NpcAPI; -public abstract class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent { +public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent { public final IPlayer player; public PlayerEvent(IPlayer player) { diff --git a/src/main/java/noppes/npcs/scripted/event/ProjectileEvent.java b/src/main/java/noppes/npcs/scripted/event/ProjectileEvent.java index 060edfbe7..e485396b5 100644 --- a/src/main/java/noppes/npcs/scripted/event/ProjectileEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/ProjectileEvent.java @@ -4,9 +4,8 @@ import noppes.npcs.api.IBlock; import noppes.npcs.api.entity.IEntity; import noppes.npcs.api.entity.IProjectile; import noppes.npcs.api.event.IProjectileEvent; -import noppes.npcs.constants.EnumScriptType; -public abstract class ProjectileEvent extends CustomNPCsEvent implements IProjectileEvent { +public class ProjectileEvent extends CustomNPCsEvent implements IProjectileEvent { public IProjectile projectile; public IEntity source; @@ -30,11 +29,6 @@ public abstract class ProjectileEvent extends CustomNPCsEvent implements IProjec public UpdateEvent(IProjectile projectile) { super(projectile); } - - @Override - public String getHookName() { - return EnumScriptType.PROJECTILE_TICK.function; - } } /** @@ -68,10 +62,5 @@ public abstract class ProjectileEvent extends CustomNPCsEvent implements IProjec return (IBlock) target; return null; } - - @Override - public String getHookName() { - return EnumScriptType.PROJECTILE_IMPACT.function; - } } } diff --git a/src/main/java/noppes/npcs/scripted/event/QuestEvent.java b/src/main/java/noppes/npcs/scripted/event/QuestEvent.java index c5261f951..264e6f8c8 100644 --- a/src/main/java/noppes/npcs/scripted/event/QuestEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/QuestEvent.java @@ -7,7 +7,7 @@ import noppes.npcs.api.handler.data.IQuest; import noppes.npcs.api.item.IItemStack; import noppes.npcs.constants.EnumScriptType; -public abstract class QuestEvent extends CustomNPCsEvent implements IQuestEvent { +public class QuestEvent extends CustomNPCsEvent implements IQuestEvent { public final IQuest quest; public final IPlayer player; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index a7742ffae..8976c0fe6 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1172,7 +1172,9 @@ animation.smoothing=Smoothing animation.linear=Linear animation.smooth=Smooth animation.loop=Loop -animation.tickDuration=Tick Duration +animation.tickType=Tick Type +animation.mcTicks=MC Ticks +animation.renderTicks=Render Ticks animation.whileStanding=While Standing animation.whileAttacking=While Attacking animation.whileMoving=While Moving