Refactor JobPuppet and PartConfig

This commit is contained in:
KAMKEEL committed 2023-01-11 22:42:36 -05:00
1 parent c35c3cbb1d
commit 8f62daba3e
7 files changed
+213 -204

No files matched your search

@@ -15,6 +15,7 @@ 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;
@@ -32,7 +33,7 @@ public class ClientEventHandler {
public static EntityPlayer renderingPlayer;
public static RendererLivingEntity renderer;
public static boolean isPart(HashMap<JobPuppet.PartConfig,String> modelNameMap, JobPuppet.PartConfig puppetPart, String partName) {
public static boolean isPart(HashMap<PartConfig, String> modelNameMap, PartConfig puppetPart, String partName) {
return !puppetPart.disabled && partName.equals(modelNameMap.get(puppetPart));
}
@@ -8,7 +8,7 @@ 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.JobPuppet.PartConfig;
import noppes.npcs.roles.PartConfig;
public class GuiNpcPuppet extends GuiModelInterface implements ISliderListener, ITextfieldListener {
@@ -27,6 +27,7 @@ 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;
@@ -569,7 +570,7 @@ public class ModelMPM extends ModelNPCMale{
JobPuppet job = npc.display.modelData;
if (job.isActive()) {
JobPuppet.PartConfig[] partConfigs = new JobPuppet.PartConfig[]{job.head,job.body,job.larm,job.rarm,job.lleg,job.rleg};
PartConfig[] partConfigs = new PartConfig[]{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++) {
@@ -624,7 +625,7 @@ public class ModelMPM extends ModelNPCMale{
}
}
public void setInterpolatedAngles(ModelRenderer renderer, JobPuppet.PartConfig modelPart) {
public void setInterpolatedAngles(ModelRenderer renderer, PartConfig modelPart) {
renderer.rotateAngleX = modelPart.prevRotations[0];
renderer.rotateAngleY = modelPart.prevRotations[1];
renderer.rotateAngleZ = modelPart.prevRotations[2];
@@ -657,7 +658,7 @@ public class ModelMPM extends ModelNPCMale{
modelPart.prevRotations = new float[]{renderer.rotateAngleX,renderer.rotateAngleY,renderer.rotateAngleZ};
}
public void addInterpolatedOffset(ModelRenderer renderer, JobPuppet.PartConfig modelPart) {
public void addInterpolatedOffset(ModelRenderer renderer, PartConfig modelPart) {
if (!modelPart.animate) {
renderer.rotationPointX += modelPart.pivotX;
renderer.rotationPointY += modelPart.pivotY;
@@ -6,18 +6,18 @@ 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.JobPuppet;
import noppes.npcs.roles.PartConfig;
public class PlayerModelData implements IPlayerModelData {
public PlayerData parent;
public final EntityPlayer player;
public JobPuppet.PartConfig head = new JobPuppet.PartConfig(this);
public JobPuppet.PartConfig larm = new JobPuppet.PartConfig(this);
public JobPuppet.PartConfig rarm = new JobPuppet.PartConfig(this);
public JobPuppet.PartConfig body = new JobPuppet.PartConfig(this);
public JobPuppet.PartConfig lleg = new JobPuppet.PartConfig(this);
public JobPuppet.PartConfig rleg = new JobPuppet.PartConfig(this);
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;
@@ -11,6 +11,7 @@ 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;
@@ -42,15 +43,19 @@ public abstract class MixinModelRenderer {
@Shadow public List childModels;
@Shadow abstract void compileDisplayList(float p_78788_1_);
HashMap<JobPuppet.PartConfig,String> modelNameMap = new HashMap<>();
HashMap<PartConfig, String> modelNameMap = new HashMap<>();
String partName = "";
HashMap<String,String[]> partNames = new HashMap<>();
/**
* @author Someone
* @reason Because we need it
*/
@Overwrite
@SideOnly(Side.CLIENT)
public void render(float p_78785_1_)
{
JobPuppet.PartConfig currentPart = null;
PartConfig currentPart = null;
if (partNames.isEmpty()) {
String[] headNames = new String[]{"field_78116_c","bipedHead","bipedHeadwear","head","Head","bipedHeadAll",
@@ -70,12 +75,12 @@ public abstract class MixinModelRenderer {
}
if (ClientEventHandler.renderingPlayer != null && Client.playerModelData.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
PlayerModelData modelData = Client.playerModelData.get(ClientEventHandler.renderingPlayer.getUniqueID());
JobPuppet.PartConfig[] partConfigs = new JobPuppet.PartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg};
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);
this.setModelParts(modelData);
if (modelData.enabled) {
for (JobPuppet.PartConfig modelPart : partConfigs) {
if (ClientEventHandler.isPart(modelNameMap,modelPart,this.partName)) {
for (PartConfig modelPart : partConfigs) {
if (ClientEventHandler.isPart(modelNameMap, modelPart, this.partName)) {
this.rotateAngleX = modelPart.prevRotations[0];
this.rotateAngleY = modelPart.prevRotations[1];
this.rotateAngleZ = modelPart.prevRotations[2];
@@ -88,12 +93,12 @@ public abstract class MixinModelRenderer {
}
} else if (ClientEventHandler.renderingNpc != null) {
JobPuppet modelData = ClientEventHandler.renderingNpc.display.modelData;
JobPuppet.PartConfig[] partConfigs = new JobPuppet.PartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg};
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);
this.setModelParts(modelData);
if (RenderCustomNpc.entity != null) {
if (modelData.isActive()) {
for (JobPuppet.PartConfig modelPart : partConfigs) {
for (PartConfig modelPart : partConfigs) {
if (ClientEventHandler.isPart(modelNameMap,modelPart,this.partName)) {
currentPart = modelPart;
this.addInterpolatedOffset(modelPart);
@@ -204,7 +209,7 @@ public abstract class MixinModelRenderer {
public void addInterpolatedAngles(JobPuppet.PartConfig modelPart) {
public void addInterpolatedAngles(PartConfig modelPart) {
if (modelPart == null) {
return;
}
@@ -268,7 +273,7 @@ public abstract class MixinModelRenderer {
}
}
public void addInterpolatedOffset(JobPuppet.PartConfig modelPart) {
public void addInterpolatedOffset(PartConfig modelPart) {
if (modelPart == null) {
return;
}
@@ -1,10 +1,7 @@
package noppes.npcs.roles;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IModelPart;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.ValueUtil;
public class JobPuppet extends JobInterface{
public PartConfig head = new PartConfig(this);
@@ -76,185 +73,5 @@ public class JobPuppet extends JobInterface{
return true;
return false;
}
public static 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;
}
}
}
@@ -0,0 +1,185 @@
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;
}
}