Animation Data overhaul

This commit is contained in:
Luis C.M committed 2023-01-12 15:07:45 -06:00
1 parent 1d94e5f1e7
commit 54d53041ac
17 files changed
+118 -636

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ public class AnimationData extends AnimationDataShared {
public boolean whileMoving = false;
public AnimationData(EntityNPCInterface npc, Object parent){
super(null);
super(parent);
this.npc = npc;
}
@@ -2,10 +2,11 @@ package noppes.npcs;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.IPlayerModelData;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.data.PlayerData;
public class AnimationDataShared {
public class AnimationDataShared implements IPlayerModelData {
public Object parent;
public AnimationPartConfig head = new AnimationPartConfig();
@@ -1,8 +1,9 @@
package noppes.npcs;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IModelPart;
public class AnimationPartConfig {
public class AnimationPartConfig implements IModelPart {
public float rotationX = 0f, rotationY = 0f, rotationZ = 0f;
public float pivotX = 0f, pivotY = 0f, pivotZ = 0f;
@@ -19,7 +19,6 @@ import noppes.npcs.roles.JobFollower;
import noppes.npcs.roles.JobGuard;
import noppes.npcs.roles.JobHealer;
import noppes.npcs.roles.JobItemGiver;
import noppes.npcs.roles.JobPuppet;
import noppes.npcs.roles.JobSpawner;
import noppes.npcs.roles.RoleBank;
import noppes.npcs.roles.RoleCompanion;
+3 -5
View File
@@ -12,7 +12,6 @@ import noppes.npcs.config.ConfigMain;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.entity.data.DataSkinOverlays;
import noppes.npcs.roles.JobPuppet;
import noppes.npcs.util.ValueUtil;
import com.google.common.collect.Iterables;
@@ -39,7 +38,6 @@ public class DataDisplay {
public DataSkinOverlays skinOverlayData;
public long overlayRenderTicks = 0;
public JobPuppet modelData;
public AnimationData animationData;
public String glowTexture = "";
@@ -66,7 +64,7 @@ public class DataDisplay {
markovGeneratorId = new Random().nextInt(CustomNpcs.MARKOV_GENERATOR.length-1);
skinOverlayData = new DataSkinOverlays(npc);
name = getRandomName();
modelData = new JobPuppet(npc);
animationData = new AnimationData(npc,this);
}
public String getRandomName() {
@@ -86,7 +84,7 @@ public class DataDisplay {
nbttagcompound = skinOverlayData.writeToNBT(nbttagcompound);
nbttagcompound = modelData.writeToNBT(nbttagcompound);
nbttagcompound = animationData.writeToNBT(nbttagcompound);
if (this.playerProfile != null)
{
@@ -162,7 +160,7 @@ public class DataDisplay {
skinOverlayData.readFromNBT(nbttagcompound);
modelData.readFromNBT(nbttagcompound);
animationData.readFromNBT(nbttagcompound);
modelSize = ValueUtil.CorrectInt(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE);
if(modelSize > ConfigMain.NpcSizeLimit)
+2 -3
View File
@@ -7,21 +7,20 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.UUID;
import net.minecraft.client.Minecraft;
import noppes.npcs.AnimationDataShared;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.client.gui.OverlayQuestTracking;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.constants.EnumPacketServer;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import noppes.npcs.controllers.data.PlayerModelData;
import noppes.npcs.controllers.data.SkinOverlay;
public class Client {
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, PlayerModelData> playerModelData = new HashMap<>();
public static HashMap<UUID, AnimationDataShared> playerModelData = new HashMap<>();
public static void sendData(EnumPacketServer enu, Object... obs) {
ByteBuf buffer = Unpooled.buffer();
@@ -2,23 +2,14 @@ package noppes.npcs.client;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.client.event.*;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.renderer.RenderCNPCPlayer;
import noppes.npcs.controllers.data.PlayerModelData;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.JobPuppet;
import noppes.npcs.roles.PartConfig;
import org.lwjgl.opengl.GL11;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@@ -33,51 +24,6 @@ public class ClientEventHandler {
public static EntityPlayer renderingPlayer;
public static RendererLivingEntity renderer;
public static boolean isPart(HashMap<PartConfig, String> modelNameMap, PartConfig puppetPart, String partName) {
return !puppetPart.disabled && partName.equals(modelNameMap.get(puppetPart));
}
public static String getPartName(ModelRenderer renderer, HashMap<String,String[]> partNames) {
Class<?> RenderClass = renderer.baseModel.getClass();
Object model = renderer.baseModel;
String returnName = "";
while (returnName.isEmpty()) {
for (Field f : RenderClass.getDeclaredFields()) {
f.setAccessible(true);
try {
if (renderer == f.get(model)) {
int i = 0;
break;
}
} catch (Exception ignored) {
}
}
for (Map.Entry<String, String[]> entry : partNames.entrySet()) {
String[] names = entry.getValue();
for (String partName : names) {
try {
Field field = RenderClass.getDeclaredField(partName);
field.setAccessible(true);
if (renderer == field.get(model)) {
returnName = entry.getKey();
break;
}
} catch (Exception ignored) {
}
}
}
if (RenderClass == ModelBase.class || RenderClass.getSuperclass() == null) {
break;
}
RenderClass = RenderClass.getSuperclass();
}
return returnName;
}
@SubscribeEvent
public void onMouse(MouseEvent event) {
if (Minecraft.getMinecraft().currentScreen != null)
@@ -20,9 +20,8 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Util;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import noppes.npcs.AnimationDataShared;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.Server;
import noppes.npcs.client.fx.CustomFX;
import noppes.npcs.client.gui.player.GuiDialogInteract;
@@ -32,17 +31,14 @@ import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.IScrollData;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.constants.EnumPlayerPacket;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.data.PlayerModelData;
import noppes.npcs.controllers.data.Quest;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.ScriptParticle;
import org.lwjgl.Sys;
import org.lwjgl.opengl.NVProgram;
public class NoppesUtil {
@@ -95,9 +91,9 @@ public class NoppesUtil {
}
public static void updatePlayerModelData(EntityPlayer player, NBTTagCompound compound) {
PlayerModelData data;
AnimationDataShared data;
if (!Client.playerModelData.containsKey(player.getUniqueID())) {
data = new PlayerModelData(player);
data = new AnimationDataShared(null);
data.readFromNBT(compound);
data.modelRotations = new float[]{data.rotationX, data.rotationY, data.rotationZ};
} else {
@@ -3,19 +3,19 @@ package noppes.npcs.client.gui.roles;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.AnimationData;
import noppes.npcs.AnimationPartConfig;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.roles.JobPuppet;
import noppes.npcs.roles.PartConfig;
public class GuiNpcPuppet extends GuiModelInterface implements ISliderListener, ITextfieldListener {
private GuiScreen parent;
private int type = 6;
private JobPuppet job;
private PartConfig part;
private AnimationData job;
private AnimationPartConfig part;
private GuiNpcSlider rotateX;
private GuiNpcSlider rotateY;
@@ -26,7 +26,7 @@ public class GuiNpcPuppet extends GuiModelInterface implements ISliderListener,
this.parent = parent;
this.xOffset = 100;
ySize = 230;
job = npc.display.modelData;
job = npc.display.animationData;
}
@Override
@@ -106,9 +106,9 @@ public class GuiNpcPuppet extends GuiModelInterface implements ISliderListener,
}
private float drawSlider(int y, PartConfig config){
private float drawSlider(int y, AnimationPartConfig config){
part = config;
addButton(new GuiNpcButton(29, guiLeft + 100, y , 80, 20, new String[]{"gui.enabled","gui.disabled"}, config.disabled?1:0));
addButton(new GuiNpcButton(29, guiLeft + 100, y , 80, 20, new String[]{"gui.enabled","gui.disabled"}, !config.enablePart?1:0));
y += 22;
addLabel(new GuiNpcLabel(10, "X", guiLeft, y + 5, 0xFFFFFF));
rotateX = new GuiNpcSlider(this, 10, guiLeft + 50, y, config.rotationX + 0.5f);
@@ -156,7 +156,7 @@ public class GuiNpcPuppet extends GuiModelInterface implements ISliderListener,
GuiNpcButton button = (GuiNpcButton) btn;
if(btn.id == 29){
part.disabled = button.getValue() == 1;
part.enablePart = button.getValue() == 0;
}
if(btn.id == 30){
job.whileStanding = button.getValue() == 0;
@@ -11,9 +11,7 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.CustomItems;
import noppes.npcs.ModelPartConfig;
import noppes.npcs.ModelPartData;
import noppes.npcs.*;
import noppes.npcs.client.model.animation.AniCrawling;
import noppes.npcs.client.model.animation.AniHug;
import noppes.npcs.client.model.part.*;
@@ -21,13 +19,10 @@ import noppes.npcs.client.model.util.ModelPartInterface;
import noppes.npcs.client.model.util.ModelScaleRenderer;
import noppes.npcs.client.renderer.RenderNPCInterface;
import noppes.npcs.constants.EnumAnimation;
import noppes.npcs.constants.EnumJobType;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.roles.JobPuppet;
import noppes.npcs.api.ISkinOverlay;
import noppes.npcs.roles.PartConfig;
import org.lwjgl.opengl.GL11;
import static noppes.npcs.client.ClientProxy.bindTexture;
@@ -568,13 +563,13 @@ public class ModelMPM extends ModelNPCMale{
this.bipedBody.rotateAngleX = 0.5F / npc.modelData.body.scaleY;
}
JobPuppet job = npc.display.modelData;
AnimationData job = npc.display.animationData;
if (job.isActive()) {
PartConfig[] partConfigs = new PartConfig[]{job.head,job.body,job.larm,job.rarm,job.lleg,job.rleg};
AnimationPartConfig[] partConfigs = new AnimationPartConfig[]{job.head,job.body,job.larm,job.rarm,job.lleg,job.rleg};
ModelRenderer[] mainModelParts = new ModelRenderer[]{bipedHead,bipedBody,bipedLeftArm,bipedRightArm,bipedLeftLeg,bipedRightLeg};
for (int i = 0; i < partConfigs.length; i++) {
if (!partConfigs[i].disabled) {
if (partConfigs[i].enablePart) {
this.setInterpolatedAngles(mainModelParts[i],partConfigs[i]);
}
}
@@ -618,14 +613,14 @@ public class ModelMPM extends ModelNPCMale{
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleY) * 12.0F;
for (int i = 0; i < partConfigs.length; i++) {
if (!partConfigs[i].disabled) {
if (partConfigs[i].enablePart) {
this.addInterpolatedOffset(mainModelParts[i],partConfigs[i]);
}
}
}
}
public void setInterpolatedAngles(ModelRenderer renderer, PartConfig modelPart) {
public void setInterpolatedAngles(ModelRenderer renderer, AnimationPartConfig modelPart) {
renderer.rotateAngleX = modelPart.prevRotations[0];
renderer.rotateAngleY = modelPart.prevRotations[1];
renderer.rotateAngleZ = modelPart.prevRotations[2];
@@ -658,7 +653,7 @@ public class ModelMPM extends ModelNPCMale{
modelPart.prevRotations = new float[]{renderer.rotateAngleX,renderer.rotateAngleY,renderer.rotateAngleZ};
}
public void addInterpolatedOffset(ModelRenderer renderer, PartConfig modelPart) {
public void addInterpolatedOffset(ModelRenderer renderer, AnimationPartConfig modelPart) {
if (!modelPart.animate) {
renderer.rotationPointX += modelPart.pivotX;
renderer.rotationPointY += modelPart.pivotY;
@@ -6,6 +6,7 @@ import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import noppes.npcs.AnimationDataShared;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.constants.EnumRoleType;
@@ -31,7 +32,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public PlayerFactionData factionData = new PlayerFactionData(this);
public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this);
public PlayerMailData mailData = new PlayerMailData(this);
public PlayerModelData modelData = new PlayerModelData(this);
public AnimationDataShared modelData = new AnimationDataShared(this);
public DataTimers timers = new DataTimers(this);
public DataSkinOverlays skinOverlays = new DataSkinOverlays(this);
@@ -1,232 +0,0 @@
package noppes.npcs.controllers.data;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.Server;
import noppes.npcs.api.handler.IPlayerModelData;
import noppes.npcs.api.handler.data.IModelPart;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.roles.PartConfig;
public class PlayerModelData implements IPlayerModelData {
// REMOVE THIS CLASS - LOUIS :D
public PlayerData parent;
public final EntityPlayer player;
public PartConfig head = new PartConfig(this);
public PartConfig larm = new PartConfig(this);
public PartConfig rarm = new PartConfig(this);
public PartConfig body = new PartConfig(this);
public PartConfig lleg = new PartConfig(this);
public PartConfig rleg = new PartConfig(this);
public boolean enabled = false;
public float rotationX, rotationY, rotationZ;
public boolean rotationEnabledX, rotationEnabledY, rotationEnabledZ;
public boolean animate = false;
public float animRate = 1.0F;
public boolean fullAngles;
public boolean interpolate;
//Client-sided use
public float modelRotPartialTicks;
public float[] modelRotations = {0,0,0};
public PlayerModelData(PlayerData parent) {
this.parent = parent;
this.player = parent.player;
}
public PlayerModelData(EntityPlayer player) {
this.player = player;
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setTag("PuppetHead", head.writeNBT());
compound.setTag("PuppetLArm", larm.writeNBT());
compound.setTag("PuppetRArm", rarm.writeNBT());
compound.setTag("PuppetBody", body.writeNBT());
compound.setTag("PuppetLLeg", lleg.writeNBT());
compound.setTag("PuppetRLeg", rleg.writeNBT());
compound.setBoolean("PuppetEnabled", enabled);
compound.setFloat("PuppetRotationX",rotationX);
compound.setFloat("PuppetRotationY",rotationY);
compound.setFloat("PuppetRotationZ",rotationZ);
compound.setBoolean("PuppetRotationEnabledX",rotationEnabledX);
compound.setBoolean("PuppetRotationEnabledY",rotationEnabledY);
compound.setBoolean("PuppetRotationEnabledZ",rotationEnabledZ);
compound.setBoolean("PuppetFullAngles", fullAngles);
compound.setBoolean("PuppetInterpolate", interpolate);
compound.setBoolean("PuppetAnimate", animate);
compound.setFloat("PuppetAnimSpeed", animRate);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
head.readNBT(compound.getCompoundTag("PuppetHead"));
larm.readNBT(compound.getCompoundTag("PuppetLArm"));
rarm.readNBT(compound.getCompoundTag("PuppetRArm"));
body.readNBT(compound.getCompoundTag("PuppetBody"));
lleg.readNBT(compound.getCompoundTag("PuppetLLeg"));
rleg.readNBT(compound.getCompoundTag("PuppetRLeg"));
enabled = compound.getBoolean("PuppetEnabled");
rotationX = compound.getFloat("PuppetRotationX");
rotationY = compound.getFloat("PuppetRotationY");
rotationZ = compound.getFloat("PuppetRotationZ");
rotationEnabledX = compound.getBoolean("PuppetRotationEnabledX");
rotationEnabledY = compound.getBoolean("PuppetRotationEnabledY");
rotationEnabledZ = compound.getBoolean("PuppetRotationEnabledZ");
fullAngles = compound.getBoolean("PuppetFullAngles");
if (!compound.hasKey("PuppetInterpolate")) {
interpolate = true;
} else {
interpolate = compound.getBoolean("PuppetInterpolate");
}
animate = compound.getBoolean("PuppetAnimate");
animRate = compound.getFloat("PuppetAnimSpeed");
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean enabled() {
return this.enabled;
}
public void setAnimated(boolean animated) {
this.animate = animated;
}
public boolean isAnimated() {
return this.animate;
}
public void setInterpolated(boolean interpolate) {
this.interpolate = interpolate;
}
public boolean isInterpolated() {
return this.interpolate;
}
public void setFullAngles(boolean limit) {
fullAngles = limit;
}
public boolean fullAngles() {
return fullAngles;
}
public void setAnimRate(float animRate) {
if (animRate < 0)
animRate = 0;
this.animRate = animRate;
}
public float getAnimRate() {
return this.animRate;
}
public void setRotation(float rotationX, float rotationY, float rotationZ) {
this.setRotationX(rotationX);
this.setRotationY(rotationY);
this.setRotationZ(rotationZ);
}
public void setRotationX(float rotationX) {
this.rotationX = rotationX;
}
public void setRotationY(float rotationY) {
this.rotationY = rotationY;
}
public void setRotationZ(float rotationZ) {
this.rotationZ = rotationZ;
}
public float getRotationX() {
return rotationX;
}
public float getRotationY() {
return rotationY;
}
public float getRotationZ() {
return rotationZ;
}
public void setRotationEnabled(boolean enabledX, boolean enabledY, boolean enabledZ) {
this.setRotationEnabledX(enabledX);
this.setRotationEnabledY(enabledY);
this.setRotationEnabledZ(enabledZ);
}
public void setRotationEnabledX(boolean enabled) {
this.rotationEnabledX = enabled;
}
public void setRotationEnabledY(boolean enabled) {
this.rotationEnabledY = enabled;
}
public void setRotationEnabledZ(boolean enabled) {
this.rotationEnabledZ = enabled;
}
public boolean rotationEnabledX() {
return rotationEnabledX;
}
public boolean rotationEnabledY() {
return rotationEnabledY;
}
public boolean rotationEnabledZ() {
return rotationEnabledZ;
}
public void allEnabled(boolean enabled) {
for (int i = 0; i < 6; i++) {
this.getPart(i).setEnabled(enabled);
}
}
public void allAnimated(boolean animated) {
for (int i = 0; i < 6; i++) {
this.getPart(i).setAnimated(animated);
}
}
public void allInterpolated(boolean interpolate) {
for (int i = 0; i < 6; i++) {
this.getPart(i).setAnimated(interpolate);
}
}
public void allFullAngles(boolean fullAngles) {
for (int i = 0; i < 6; i++) {
this.getPart(i).setFullAngles(fullAngles);
}
}
public void allAnimRate(float animRate) {
if (animRate < 0)
animRate = 0;
for (int i = 0; i < 6; i++) {
this.getPart(i).setAnimRate(animRate);
}
}
}
@@ -2,23 +2,18 @@ package noppes.npcs.mixin;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.AnimationData;
import noppes.npcs.AnimationDataShared;
import noppes.npcs.AnimationPartConfig;
import noppes.npcs.client.Client;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.client.renderer.RenderCustomNpc;
import noppes.npcs.controllers.data.PlayerModelData;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.JobPuppet;
import noppes.npcs.roles.PartConfig;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.lang.reflect.Field;
import java.util.HashMap;
@@ -43,7 +38,7 @@ public abstract class MixinModelRenderer {
@Shadow public List childModels;
@Shadow abstract void compileDisplayList(float p_78788_1_);
HashMap<PartConfig, String> modelNameMap = new HashMap<>();
HashMap<AnimationPartConfig, String> modelNameMap = new HashMap<>();
String partName = "";
HashMap<String,String[]> partNames = new HashMap<>();
@@ -55,7 +50,7 @@ public abstract class MixinModelRenderer {
@SideOnly(Side.CLIENT)
public void render(float p_78785_1_)
{
PartConfig currentPart = null;
AnimationPartConfig currentPart = null;
if (partNames.isEmpty()) {
String[] headNames = new String[]{"field_78116_c","bipedHead","bipedHeadwear","head","Head","bipedHeadAll",
@@ -74,13 +69,13 @@ public abstract class MixinModelRenderer {
partNames.put("rleg", rlegNames);
}
if (ClientEventHandler.renderingPlayer != null && Client.playerModelData.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
PlayerModelData modelData = Client.playerModelData.get(ClientEventHandler.renderingPlayer.getUniqueID());
PartConfig[] partConfigs = new PartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg};
this.partName = ClientEventHandler.getPartName((ModelRenderer) (Object) this, this.partNames);
AnimationDataShared modelData = Client.playerModelData.get(ClientEventHandler.renderingPlayer.getUniqueID());
AnimationPartConfig[] partConfigs = new AnimationPartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg};
this.partName = this.getPartName((ModelRenderer) (Object) this, this.partNames);
this.setModelParts(modelData);
if (modelData.enabled) {
for (PartConfig modelPart : partConfigs) {
if (ClientEventHandler.isPart(modelNameMap, modelPart, this.partName)) {
if (modelData.enabled()) {
for (AnimationPartConfig modelPart : partConfigs) {
if (this.isPart(modelNameMap, modelPart, this.partName)) {
this.rotateAngleX = modelPart.prevRotations[0];
this.rotateAngleY = modelPart.prevRotations[1];
this.rotateAngleZ = modelPart.prevRotations[2];
@@ -92,14 +87,14 @@ public abstract class MixinModelRenderer {
}
}
} else if (ClientEventHandler.renderingNpc != null) {
JobPuppet modelData = ClientEventHandler.renderingNpc.display.modelData;
PartConfig[] partConfigs = new PartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg};
this.partName = ClientEventHandler.getPartName((ModelRenderer) (Object) this, this.partNames);
AnimationData modelData = ClientEventHandler.renderingNpc.display.animationData;
AnimationPartConfig[] partConfigs = new AnimationPartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg};
this.partName = this.getPartName((ModelRenderer) (Object) this, this.partNames);
this.setModelParts(modelData);
if (RenderCustomNpc.entity != null) {
if (modelData.isActive()) {
for (PartConfig modelPart : partConfigs) {
if (ClientEventHandler.isPart(modelNameMap,modelPart,this.partName)) {
for (AnimationPartConfig modelPart : partConfigs) {
if (this.isPart(modelNameMap,modelPart,this.partName)) {
currentPart = modelPart;
this.addInterpolatedOffset(modelPart);
this.addInterpolatedAngles(modelPart);
@@ -209,7 +204,7 @@ public abstract class MixinModelRenderer {
public void addInterpolatedAngles(PartConfig modelPart) {
public void addInterpolatedAngles(AnimationPartConfig modelPart) {
if (modelPart == null) {
return;
}
@@ -273,7 +268,7 @@ public abstract class MixinModelRenderer {
}
}
public void addInterpolatedOffset(PartConfig modelPart) {
public void addInterpolatedOffset(AnimationPartConfig modelPart) {
if (modelPart == null) {
return;
}
@@ -306,21 +301,66 @@ public abstract class MixinModelRenderer {
}
public void setModelParts(Object modelData) {
if (modelData instanceof PlayerModelData) {
modelNameMap.put(((PlayerModelData) modelData).head, "head");
modelNameMap.put(((PlayerModelData) modelData).body, "body");
modelNameMap.put(((PlayerModelData) modelData).rarm, "rarm");
modelNameMap.put(((PlayerModelData) modelData).larm, "larm");
modelNameMap.put(((PlayerModelData) modelData).rleg, "rleg");
modelNameMap.put(((PlayerModelData) modelData).lleg, "lleg");
if (modelData instanceof AnimationDataShared) {
modelNameMap.put(((AnimationDataShared) modelData).head, "head");
modelNameMap.put(((AnimationDataShared) modelData).body, "body");
modelNameMap.put(((AnimationDataShared) modelData).rarm, "rarm");
modelNameMap.put(((AnimationDataShared) modelData).larm, "larm");
modelNameMap.put(((AnimationDataShared) modelData).rleg, "rleg");
modelNameMap.put(((AnimationDataShared) modelData).lleg, "lleg");
}
if (modelData instanceof JobPuppet) {
modelNameMap.put(((JobPuppet) modelData).head, "head");
modelNameMap.put(((JobPuppet) modelData).body, "body");
modelNameMap.put(((JobPuppet) modelData).rarm, "rarm");
modelNameMap.put(((JobPuppet) modelData).larm, "larm");
modelNameMap.put(((JobPuppet) modelData).rleg, "rleg");
modelNameMap.put(((JobPuppet) modelData).lleg, "lleg");
if (modelData instanceof AnimationData) {
modelNameMap.put(((AnimationData) modelData).head, "head");
modelNameMap.put(((AnimationData) modelData).body, "body");
modelNameMap.put(((AnimationData) modelData).rarm, "rarm");
modelNameMap.put(((AnimationData) modelData).larm, "larm");
modelNameMap.put(((AnimationData) modelData).rleg, "rleg");
modelNameMap.put(((AnimationData) modelData).lleg, "lleg");
}
}
public boolean isPart(HashMap<AnimationPartConfig, String> modelNameMap, AnimationPartConfig puppetPart, String partName) {
return puppetPart.enablePart && partName.equals(modelNameMap.get(puppetPart));
}
public String getPartName(ModelRenderer renderer, HashMap<String,String[]> partNames) {
Class<?> RenderClass = renderer.baseModel.getClass();
Object model = renderer.baseModel;
String returnName = "";
while (returnName.isEmpty()) {
for (Field f : RenderClass.getDeclaredFields()) {
f.setAccessible(true);
try {
if (renderer == f.get(model)) {
int i = 0;
break;
}
} catch (Exception ignored) {
}
}
for (Map.Entry<String, String[]> entry : partNames.entrySet()) {
String[] names = entry.getValue();
for (String partName : names) {
try {
Field field = RenderClass.getDeclaredField(partName);
field.setAccessible(true);
if (renderer == field.get(model)) {
returnName = entry.getKey();
break;
}
} catch (Exception ignored) {
}
}
}
if (RenderClass == ModelBase.class || RenderClass.getSuperclass() == null) {
break;
}
RenderClass = RenderClass.getSuperclass();
}
return returnName;
}
}
@@ -4,9 +4,9 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.entity.RenderPlayer;
import noppes.npcs.AnimationDataShared;
import noppes.npcs.client.Client;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.controllers.data.PlayerModelData;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@@ -21,8 +21,8 @@ public class MixinRenderPlayer {
protected void modelDataRotations(AbstractClientPlayer p_77039_1_, double p_77039_2_, double p_77039_4_, double p_77039_6_, CallbackInfo callbackInfo)
{
if (Client.playerModelData.containsKey(p_77039_1_.getUniqueID())) {
PlayerModelData data = Client.playerModelData.get(p_77039_1_.getUniqueID());
if (data.enabled) {
AnimationDataShared data = Client.playerModelData.get(p_77039_1_.getUniqueID());
if (data.allowAnimation) {
this.setInterpolatedAngles(data);
if (data.rotationEnabledX) {
GL11.glRotatef(data.modelRotations[0], 1, 0, 0);
@@ -37,9 +37,9 @@ public class MixinRenderPlayer {
}
}
public void setInterpolatedAngles(PlayerModelData modelData) {
public void setInterpolatedAngles(AnimationDataShared modelData) {
float pi = (float) Math.PI * (modelData.fullAngles ? 2 : 1);
if (!modelData.animate) {
if (!modelData.fullAnimate) {
modelData.modelRotations[0] = modelData.rotationX * pi;
modelData.modelRotations[1] = modelData.rotationY * pi;
modelData.modelRotations[2] = modelData.rotationZ * pi;
@@ -1,77 +0,0 @@
package noppes.npcs.roles;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.entity.EntityNPCInterface;
public class JobPuppet extends JobInterface{
public PartConfig head = new PartConfig(this);
public PartConfig larm = new PartConfig(this);
public PartConfig rarm = new PartConfig(this);
public PartConfig body = new PartConfig(this);
public PartConfig lleg = new PartConfig(this);
public PartConfig rleg = new PartConfig(this);
public boolean enabled = false;
public boolean whileStanding = true;
public boolean whileAttacking = false;
public boolean whileMoving = false;
public JobPuppet(EntityNPCInterface npc) {
super(npc);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setTag("PuppetHead", head.writeNBT());
compound.setTag("PuppetLArm", larm.writeNBT());
compound.setTag("PuppetRArm", rarm.writeNBT());
compound.setTag("PuppetBody", body.writeNBT());
compound.setTag("PuppetLLeg", lleg.writeNBT());
compound.setTag("PuppetRLeg", rleg.writeNBT());
compound.setBoolean("PuppetEnabled", enabled);
compound.setBoolean("PuppetStanding", whileStanding);
compound.setBoolean("PuppetAttacking", whileAttacking);
compound.setBoolean("PuppetMoving", whileMoving);
return compound;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
head.readNBT(compound.getCompoundTag("PuppetHead"));
larm.readNBT(compound.getCompoundTag("PuppetLArm"));
rarm.readNBT(compound.getCompoundTag("PuppetRArm"));
body.readNBT(compound.getCompoundTag("PuppetBody"));
lleg.readNBT(compound.getCompoundTag("PuppetLLeg"));
rleg.readNBT(compound.getCompoundTag("PuppetRLeg"));
enabled = compound.getBoolean("PuppetEnabled");
whileStanding = compound.getBoolean("PuppetStanding");
whileAttacking = compound.getBoolean("PuppetAttacking");
whileMoving = compound.getBoolean("PuppetMoving");
}
@Override
public boolean aiShouldExecute() {
return false;
}
@Override
public void reset() {
}
public void delete() {
}
public boolean isActive() {
if (!this.enabled)
return false;
if(!npc.isEntityAlive())
return false;
if(whileAttacking && npc.isAttacking() || whileMoving && npc.isWalking() || whileStanding && !npc.isWalking())
return true;
return false;
}
}
@@ -1,185 +0,0 @@
package noppes.npcs.roles;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IModelPart;
public class PartConfig implements IModelPart {
public Object parent;
public float rotationX = 0f;
public float rotationY = 0f;
public float rotationZ = 0f;
public float pivotX = 0f;
public float pivotY = 0f;
public float pivotZ = 0f;
public boolean fullAngles = false;
public boolean animate = false;
public float animRate = 1.0F;
public boolean interpolate = true;
public boolean disabled = false;
// vvv Client-sided use vvv
public float[] prevRotations = new float[]{0, 0, 0};
public float[] prevPivots = new float[]{0, 0, 0};
public float partialRotationTick = 0f;
public float partialPivotTick = 0f;
// ^^^ Client-sided use ^^^
public PartConfig(Object parent) {
this.parent = parent;
}
public NBTTagCompound writeNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setFloat("RotationX", rotationX);
compound.setFloat("RotationY", rotationY);
compound.setFloat("RotationZ", rotationZ);
compound.setFloat("PivotX", pivotX);
compound.setFloat("PivotY", pivotY);
compound.setFloat("PivotZ", pivotZ);
compound.setBoolean("Disabled", disabled);
compound.setBoolean("PuppetFullAngles", fullAngles);
compound.setBoolean("PuppetInterpolate", interpolate);
compound.setBoolean("PuppetAnimate", animate);
compound.setFloat("PuppetAnimSpeed", animRate);
return compound;
}
public void readNBT(NBTTagCompound compound) {
rotationX = compound.getFloat("RotationX");
rotationY = compound.getFloat("RotationY");
rotationZ = compound.getFloat("RotationZ");
pivotX = compound.getFloat("PivotX");
pivotY = compound.getFloat("PivotY");
pivotZ = compound.getFloat("PivotZ");
disabled = compound.getBoolean("Disabled");
fullAngles = compound.getBoolean("PuppetFullAngles");
if (!compound.hasKey("PuppetInterpolate")) {
interpolate = true;
} else {
interpolate = compound.getBoolean("PuppetInterpolate");
}
animate = compound.getBoolean("PuppetAnimate");
animRate = compound.getFloat("PuppetAnimSpeed");
}
public void setEnabled(boolean bo) {
this.disabled = !bo;
}
public boolean isEnabled() {
return !this.disabled;
}
public void setAnimated(boolean animated) {
this.animate = animated;
}
public boolean isAnimated() {
return this.animate;
}
public void setInterpolated(boolean interpolate) {
this.interpolate = interpolate;
}
public boolean isInterpolated() {
return this.interpolate;
}
public void setFullAngles(boolean fullAngles) {
this.fullAngles = fullAngles;
}
public boolean fullAngles() {
return this.fullAngles;
}
public void setAnimRate(float animRate) {
this.animRate = animRate;
}
public float getAnimRate() {
return this.animRate;
}
public void setRotation(float rotationX, float rotationY, float rotationZ) {
this.setRotationX(rotationX);
this.setRotationY(rotationY);
this.setRotationZ(rotationZ);
}
public void setRotationX(float rotation) {
float f = rotation / 360f - 0.5f;
if (this.getRotationX() != f && parent instanceof JobPuppet)
((JobPuppet) parent).npc.script.clientNeedsUpdate = true;
this.rotationX = f;
}
public void setRotationY(float rotation) {
float f = rotation / 360f - 0.5f;
if (this.getRotationY() != f && parent instanceof JobPuppet)
((JobPuppet) parent).npc.script.clientNeedsUpdate = true;
this.rotationY = f;
}
public void setRotationZ(float rotation) {
float f = rotation / 360f - 0.5f;
if (this.getRotationZ() != f && parent instanceof JobPuppet)
((JobPuppet) parent).npc.script.clientNeedsUpdate = true;
this.rotationZ = f;
}
public float getRotationX() {
return this.rotationX;
}
public float getRotationY() {
return this.rotationY;
}
public float getRotationZ() {
return this.rotationZ;
}
public void setOffset(float offsetX, float offsetY, float offsetZ) {
this.setOffsetX(offsetX);
this.setOffsetY(offsetY);
this.setOffsetZ(offsetZ);
}
public void setOffsetX(float offset) {
if (this.getOffsetX() != offset && parent instanceof JobPuppet)
((JobPuppet) parent).npc.script.clientNeedsUpdate = true;
this.pivotX = offset;
}
public void setOffsetY(float offset) {
if (this.getOffsetY() != offset && parent instanceof JobPuppet)
((JobPuppet) parent).npc.script.clientNeedsUpdate = true;
this.pivotY = offset;
}
public void setOffsetZ(float offset) {
if (this.getOffsetZ() != offset && parent instanceof JobPuppet)
((JobPuppet) parent).npc.script.clientNeedsUpdate = true;
this.pivotZ = offset;
}
public float getOffsetX() {
return this.pivotX;
}
public float getOffsetY() {
return this.pivotY;
}
public float getOffsetZ() {
return this.pivotZ;
}
}
@@ -1,24 +1,24 @@
package noppes.npcs.scripted.roles;
import noppes.npcs.AnimationData;
import noppes.npcs.api.handler.data.IModelPart;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.JobPuppet;
import noppes.npcs.scripted.constants.JobType;
import noppes.npcs.api.jobs.IJobPuppet;
public class ScriptJobPuppet extends ScriptJobInterface implements IJobPuppet {
private JobPuppet job;
private AnimationData job;
public ScriptJobPuppet(EntityNPCInterface npc){
super(npc);
this.job = npc.display.modelData;
this.job = npc.display.animationData;
}
public void setEnabled(boolean enabled) {
this.job.enabled = enabled;
this.job.allowAnimation = enabled;
}
public boolean enabled() {
return this.job.enabled;
return this.job.allowAnimation;
}
public IModelPart getPart(int part) {