Revert Animation Events

This commit is contained in:
Kam committed 2024-05-26 19:26:47 -04:00
1 parent 4c46496c82
commit 1ffddd3ce9
31 files changed
+208 -696

No files matched your search

@@ -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<Integer, OverlayCustom> customOverlays = new HashMap<>();
public static HashMap<UUID, HashMap<Integer, SkinOverlay>> skinOverlays = new HashMap<>();
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
public static Party party;
@@ -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;
@@ -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());
@@ -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;
}
@@ -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) {
@@ -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());
}
}
}
@@ -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();
}
}
}
@@ -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<EnumAnimationPart,FramePart> 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;
}
}
}
}
@@ -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();