Moved NPC puppet data to display data.

Improved mixin functionality, offsets and rotations always reset if the puppet "job" (not a job anymore, always in display) is disabled.
This commit is contained in:
Luis C.M committed 2023-01-11 19:12:53 -06:00
1 parent 974bf2ca66
commit 8905f5f42e
14 files changed
+325 -197

No files matched your search

@@ -236,8 +236,6 @@ public class DataAdvanced {
npc.jobInterface = new JobConversation(npc);
else if (job == EnumJobType.ChunkLoader && !(npc.jobInterface instanceof JobChunkLoader))
npc.jobInterface = new JobChunkLoader(npc);
else if (job == EnumJobType.Puppet && !(npc.jobInterface instanceof JobPuppet))
npc.jobInterface = new JobPuppet(npc);
}
public boolean hasWorldLines() {
@@ -12,6 +12,7 @@ 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;
@@ -38,6 +39,8 @@ public class DataDisplay {
public DataSkinOverlays skinOverlayData;
public long overlayRenderTicks = 0;
public JobPuppet modelData;
public String glowTexture = "";
public int visible = 0; //0:visible 1:Invisible 2:semi-invisible
@@ -62,6 +65,7 @@ public class DataDisplay {
markovGeneratorId = new Random().nextInt(CustomNpcs.MARKOV_GENERATOR.length-1);
skinOverlayData = new DataSkinOverlays(npc);
name = getRandomName();
modelData = new JobPuppet(npc);
}
public String getRandomName() {
@@ -81,6 +85,8 @@ public class DataDisplay {
nbttagcompound = skinOverlayData.writeToNBT(nbttagcompound);
nbttagcompound = modelData.writeToNBT(nbttagcompound);
if (this.playerProfile != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
@@ -155,6 +161,8 @@ public class DataDisplay {
skinOverlayData.readFromNBT(nbttagcompound);
modelData.readFromNBT(nbttagcompound);
modelSize = ValueUtil.CorrectInt(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE);
if(modelSize > ConfigMain.NpcSizeLimit)
modelSize = ConfigMain.NpcSizeLimit;
@@ -2,6 +2,7 @@ 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;
@@ -31,8 +32,50 @@ public class ClientEventHandler {
public static EntityPlayer renderingPlayer;
public static RendererLivingEntity renderer;
public static float[] undoRotations = new float[]{0,0,0};
public static float[] undoPivots = new float[]{0,0,0};
public static boolean isPart(HashMap<JobPuppet.PartConfig,String> modelNameMap, JobPuppet.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) {
@@ -17,7 +17,6 @@ import noppes.npcs.client.gui.roles.GuiNpcConversation;
import noppes.npcs.client.gui.roles.GuiNpcFollowerJob;
import noppes.npcs.client.gui.roles.GuiNpcGuard;
import noppes.npcs.client.gui.roles.GuiNpcHealer;
import noppes.npcs.client.gui.roles.GuiNpcPuppet;
import noppes.npcs.client.gui.roles.GuiNpcSpawner;
import noppes.npcs.client.gui.roles.GuiNpcTransporter;
import noppes.npcs.client.gui.util.GuiNPCInterface2;
@@ -27,7 +26,6 @@ import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumJobType;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
@@ -46,7 +44,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman);
this.addButton(new GuiNpcButton(4, guiLeft + 85 + 160, guiTop + 43, 52, 20, "selectServer.edit"));
this.addButton(new GuiNpcButton(5, guiLeft + 85, guiTop + 43,155,20, new String[]{"job.none","job.bard","job.healer","job.guard","job.itemgiver","role.follower", "job.spawner", "job.conversation", "job.chunkloader", "job.puppet"},npc.advanced.job.ordinal()));
this.addButton(new GuiNpcButton(5, guiLeft + 85, guiTop + 43,155,20, new String[]{"job.none","job.bard","job.healer","job.guard","job.itemgiver","role.follower", "job.spawner", "job.conversation", "job.chunkloader"},npc.advanced.job.ordinal()));
getButton(4).setEnabled(npc.advanced.job != EnumJobType.None && npc.advanced.job != EnumJobType.ChunkLoader);
@@ -143,8 +141,6 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
NoppesUtil.openGUI(player, new GuiNpcSpawner(npc));
else if(npc.advanced.job == EnumJobType.Conversation)
NoppesUtil.openGUI(player, new GuiNpcConversation(npc));
else if(npc.advanced.job == EnumJobType.Puppet)
NoppesUtil.openGUI(player, new GuiNpcPuppet(this,(EntityCustomNpc) npc));
}
else{
npc.advanced.readToNBT(compound);
@@ -26,7 +26,7 @@ public class GuiNpcPuppet extends GuiModelInterface implements ISliderListener,
this.parent = parent;
this.xOffset = 100;
ySize = 230;
job = (JobPuppet) npc.jobInterface;
job = npc.display.modelData;
}
@Override
@@ -567,61 +567,58 @@ public class ModelMPM extends ModelNPCMale{
this.bipedBody.rotateAngleX = 0.5F / npc.modelData.body.scaleY;
}
if(npc.advanced.job == EnumJobType.Puppet){
JobPuppet job = (JobPuppet) npc.jobInterface;
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};
ModelRenderer[] mainModelParts = new ModelRenderer[]{bipedHead,bipedBody,bipedLeftArm,bipedRightArm,bipedLeftLeg,bipedRightLeg};
if(job.isActive()){
JobPuppet.PartConfig[] partConfigs = new JobPuppet.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++) {
if (!partConfigs[i].disabled) {
this.setInterpolatedAngles(mainModelParts[i],partConfigs[i]);
}
for (int i = 0; i < partConfigs.length; i++) {
if (!partConfigs[i].disabled) {
this.setInterpolatedAngles(mainModelParts[i],partConfigs[i]);
}
}
this.bipedRightArm.rotationPointX =
-MathHelper.cos(this.bipedBody.rotateAngleY) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 5.0F;
this.bipedRightArm.rotationPointY =
MathHelper.cos(this.bipedBody.rotateAngleZ) * 2 +
-MathHelper.sin(this.bipedBody.rotateAngleZ) * MathHelper.cos(this.bipedBody.rotateAngleY) * 5;
this.bipedRightArm.rotationPointZ = MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F +
MathHelper.sin(this.bipedBody.rotateAngleY);
this.bipedRightArm.rotationPointX =
-MathHelper.cos(this.bipedBody.rotateAngleY) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 5.0F;
this.bipedRightArm.rotationPointY =
MathHelper.cos(this.bipedBody.rotateAngleZ) * 2 +
-MathHelper.sin(this.bipedBody.rotateAngleZ) * MathHelper.cos(this.bipedBody.rotateAngleY) * 5;
this.bipedRightArm.rotationPointZ = MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F +
MathHelper.sin(this.bipedBody.rotateAngleY);
this.bipedLeftArm.rotationPointX =
MathHelper.cos(this.bipedBody.rotateAngleY) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 5.0F;
this.bipedLeftArm.rotationPointY =
MathHelper.cos(this.bipedBody.rotateAngleZ) * 2 +
MathHelper.sin(this.bipedBody.rotateAngleZ) * MathHelper.cos(this.bipedBody.rotateAngleY) * 5;
this.bipedLeftArm.rotationPointZ = -MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F +
-MathHelper.sin(this.bipedBody.rotateAngleY);
this.bipedLeftArm.rotationPointX =
MathHelper.cos(this.bipedBody.rotateAngleY) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 5.0F;
this.bipedLeftArm.rotationPointY =
MathHelper.cos(this.bipedBody.rotateAngleZ) * 2 +
MathHelper.sin(this.bipedBody.rotateAngleZ) * MathHelper.cos(this.bipedBody.rotateAngleY) * 5;
this.bipedLeftArm.rotationPointZ = -MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F +
-MathHelper.sin(this.bipedBody.rotateAngleY);
this.bipedRightLeg.rotationPointX =
-MathHelper.cos(this.bipedBody.rotateAngleY) * 2.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleY) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 12.0F +
-MathHelper.cos(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleZ) * 12.0F;
this.bipedRightLeg.rotationPointY =
MathHelper.cos(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 12.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleY) * MathHelper.sin(this.bipedBody.rotateAngleZ) * 12.0F;
this.bipedRightLeg.rotationPointZ =
MathHelper.sin(this.bipedBody.rotateAngleY) * 2.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleY) * 12.0F;
this.bipedRightLeg.rotationPointX =
-MathHelper.cos(this.bipedBody.rotateAngleY) * 2.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleY) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 12.0F +
-MathHelper.cos(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleZ) * 12.0F;
this.bipedRightLeg.rotationPointY =
MathHelper.cos(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 12.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleY) * MathHelper.sin(this.bipedBody.rotateAngleZ) * 12.0F;
this.bipedRightLeg.rotationPointZ =
MathHelper.sin(this.bipedBody.rotateAngleY) * 2.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleY) * 12.0F;
this.bipedLeftLeg.rotationPointX =
MathHelper.cos(this.bipedBody.rotateAngleY) * 2.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleY) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 12.0F +
-MathHelper.cos(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleZ) * 12.0F;
this.bipedLeftLeg.rotationPointY =
MathHelper.cos(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 12.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleY) * MathHelper.sin(this.bipedBody.rotateAngleZ) * 12.0F;
this.bipedLeftLeg.rotationPointZ =
-MathHelper.sin(this.bipedBody.rotateAngleY) * 2.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleY) * 12.0F;
this.bipedLeftLeg.rotationPointX =
MathHelper.cos(this.bipedBody.rotateAngleY) * 2.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleY) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 12.0F +
-MathHelper.cos(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleZ) * 12.0F;
this.bipedLeftLeg.rotationPointY =
MathHelper.cos(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleZ) * 12.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.sin(this.bipedBody.rotateAngleY) * MathHelper.sin(this.bipedBody.rotateAngleZ) * 12.0F;
this.bipedLeftLeg.rotationPointZ =
-MathHelper.sin(this.bipedBody.rotateAngleY) * 2.0F +
MathHelper.sin(this.bipedBody.rotateAngleX) * MathHelper.cos(this.bipedBody.rotateAngleY) * 12.0F;
for (int i = 0; i < partConfigs.length; i++) {
if (!partConfigs[i].disabled) {
this.addInterpolatedOffset(mainModelParts[i],partConfigs[i]);
}
for (int i = 0; i < partConfigs.length; i++) {
if (!partConfigs[i].disabled) {
this.addInterpolatedOffset(mainModelParts[i],partConfigs[i]);
}
}
}
@@ -1,5 +1,5 @@
package noppes.npcs.constants;
public enum EnumJobType {
None, Bard, Healer, Guard, ItemGiver, Follower, Spawner, Conversation, ChunkLoader, Puppet
None, Bard, Healer, Guard, ItemGiver, Follower, Spawner, Conversation, ChunkLoader
}
@@ -1548,11 +1548,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
jobInterface.writeToNBT(bard);
compound.setTag("Bard", bard);
}
if(advanced.job == EnumJobType.Puppet){
NBTTagCompound bard = new NBTTagCompound();
jobInterface.writeToNBT(bard);
compound.setTag("Puppet", bard);
}
if(advanced.role == EnumRoleType.Companion){
NBTTagCompound bard = new NBTTagCompound();
roleInterface.writeToNBT(bard);
@@ -1588,10 +1583,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
NBTTagCompound bard = compound.getCompoundTag("Bard");
jobInterface.readFromNBT(bard);
}
if(advanced.job == EnumJobType.Puppet){
NBTTagCompound puppet = compound.getCompoundTag("Puppet");
jobInterface.readFromNBT(puppet);
}
if(advanced.role == EnumRoleType.Companion){
NBTTagCompound puppet = compound.getCompoundTag("Companion");
roleInterface.readFromNBT(puppet);
@@ -11,7 +11,9 @@ import noppes.npcs.controllers.data.PlayerModelData;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.JobPuppet;
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;
@@ -19,33 +21,45 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Mixin(value = ModelRenderer.class)
public class MixinModelRenderer {
public abstract class MixinModelRenderer {
@Shadow public float rotationPointX;
@Shadow public float rotationPointY;
@Shadow public float rotationPointZ;
@Shadow public float rotateAngleX;
@Shadow public float rotateAngleY;
@Shadow public float rotateAngleZ;
@Shadow public float offsetX;
@Shadow public float offsetY;
@Shadow public float offsetZ;
@Shadow public boolean isHidden;
@Shadow public boolean showModel;
@Shadow public boolean compiled;
@Shadow private int displayList;
@Shadow public List childModels;
@Shadow abstract void compileDisplayList(float p_78788_1_);
HashMap<JobPuppet.PartConfig,String> modelNameMap = new HashMap<>();
String partName = "";
HashMap<String,String[]> partNames = new HashMap<>();
@Overwrite
@SideOnly(Side.CLIENT)
@Inject(method = "render", at = @At(value = "HEAD"))
private void puppetRotations(float p_78785_1_, CallbackInfo callbackInfo)
public void render(float p_78785_1_)
{
JobPuppet.PartConfig currentPart = null;
if (partNames.isEmpty()) {
String[] headNames = new String[]{"bipedHead","bipedHeadwear","head","Head","bipedHeadAll",
String[] headNames = new String[]{"field_78116_c","bipedHead","bipedHeadwear","head","Head","bipedHeadAll",
"bipedHeadg","bipedHeadt","bipedHeadgh","bipedHeadv","bipedHeadb","bipedHeadt2"};
String[] bodyNames = new String[]{"bipedBody","B1","body","UpperBody","Body1","BodyBase"};
String[] larmNames = new String[]{"bipedLeftArm","LA","leftarm","ArmL","Arm1L","ArmL1"};
String[] rarmNames = new String[]{"bipedRightArm","RA","rightarm","ArmR","Arm1R","ArmR1"};
String[] llegNames = new String[]{"bipedLeftLeg","LL","leftleg","LegL","Leg1L","LegL1"};
String[] rlegNames = new String[]{"bipedRightLeg","RL","rightleg","LegR","Leg1R","LegR1"};
String[] bodyNames = new String[]{"field_78115_e","bipedBody","B1","body","UpperBody","Body1","BodyBase"};
String[] larmNames = new String[]{"field_78113_g","bipedLeftArm","LA","leftarm","ArmL","Arm1L","ArmL1"};
String[] rarmNames = new String[]{"field_78112_f","bipedRightArm","RA","rightarm","ArmR","Arm1R","ArmR1"};
String[] llegNames = new String[]{"field_78124_i","bipedLeftLeg","LL","leftleg","LegL","Leg1L","LegL1"};
String[] rlegNames = new String[]{"field_78123_h","bipedRightLeg","RL","rightleg","LegR","Leg1R","LegR1"};
partNames.put("head", headNames);
partNames.put("body", bodyNames);
@@ -54,148 +68,217 @@ public class MixinModelRenderer {
partNames.put("lleg", llegNames);
partNames.put("rleg", rlegNames);
}
if (ClientEventHandler.renderingPlayer != null && Client.playerModelData.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
this.partName = this.getPartName((ModelRenderer) (Object) this, this.partNames);
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};
this.partName = ClientEventHandler.getPartName((ModelRenderer) (Object) this, this.partNames);
this.setModelParts(modelData);
if (modelData.enabled) {
JobPuppet.PartConfig[] partConfigs = new JobPuppet.PartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg};
for (JobPuppet.PartConfig partConfig : partConfigs) {
if (isPart(partConfig)) {
this.rotateAngleX = partConfig.prevRotations[0];
this.rotateAngleY = partConfig.prevRotations[1];
this.rotateAngleZ = partConfig.prevRotations[2];
this.setInterpolatedAngles(partConfig);
this.addInterpolatedOffset(partConfig);
partConfig.prevRotations = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
for (JobPuppet.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];
this.addInterpolatedOffset(modelPart);
this.addInterpolatedAngles(modelPart);
modelPart.prevRotations = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
break;
}
}
}
}
if (ClientEventHandler.renderingNpc != null && ClientEventHandler.renderingNpc.jobInterface instanceof JobPuppet && RenderCustomNpc.entity != null) {
ClientEventHandler.undoRotations = new float[]{this.rotateAngleX,this.rotateAngleY,this.rotateAngleZ};
ClientEventHandler.undoPivots = new float[]{this.rotationPointX,this.rotationPointY,this.rotationPointZ};
this.partName = this.getPartName((ModelRenderer) (Object) this, this.partNames);
JobPuppet modelData = (JobPuppet) ClientEventHandler.renderingNpc.jobInterface;
} 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};
this.partName = ClientEventHandler.getPartName((ModelRenderer) (Object) this, this.partNames);
this.setModelParts(modelData);
if (modelData.isActive()) {
JobPuppet.PartConfig[] partConfigs = new JobPuppet.PartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg};
for (JobPuppet.PartConfig partConfig : partConfigs) {
if (isPart(partConfig)) {
if (partConfig.npcModel == null || !partConfig.npcModel.getClass().equals(RenderCustomNpc.entity.getClass())) {
partConfig.setOriginalPivot = false;
partConfig.npcModel = RenderCustomNpc.entity;
if (RenderCustomNpc.entity != null) {
if (modelData.isActive()) {
for (JobPuppet.PartConfig modelPart : partConfigs) {
if (ClientEventHandler.isPart(modelNameMap,modelPart,this.partName)) {
currentPart = modelPart;
this.addInterpolatedOffset(modelPart);
this.addInterpolatedAngles(modelPart);
break;
}
this.rotateAngleX = partConfig.prevRotations[0];
this.rotateAngleY = partConfig.prevRotations[1];
this.rotateAngleZ = partConfig.prevRotations[2];
this.setInterpolatedAngles(partConfig);
this.addInterpolatedOffset(partConfig);
partConfig.prevRotations = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
}
}
}
}
if (!this.isHidden)
{
if (this.showModel)
{
if (!this.compiled)
{
this.compileDisplayList(p_78785_1_);
}
if (currentPart != null) {
this.rotationPointX += currentPart.prevPivots[0];
this.rotationPointY += currentPart.prevPivots[1];
this.rotationPointZ += currentPart.prevPivots[2];
this.rotateAngleX += currentPart.prevRotations[0];
this.rotateAngleY += currentPart.prevRotations[1];
this.rotateAngleZ += currentPart.prevRotations[2];
}
GL11.glTranslatef(this.offsetX, this.offsetY, this.offsetZ);
int i;
if (this.rotateAngleX == 0.0F && this.rotateAngleY == 0.0F && this.rotateAngleZ == 0.0F)
{
if (this.rotationPointX == 0.0F && this.rotationPointY == 0.0F && this.rotationPointZ == 0.0F)
{
GL11.glCallList(this.displayList);
if (this.childModels != null)
{
for (i = 0; i < this.childModels.size(); ++i)
{
((ModelRenderer)this.childModels.get(i)).render(p_78785_1_);
}
}
}
else
{
GL11.glTranslatef(this.rotationPointX * p_78785_1_, this.rotationPointY * p_78785_1_, this.rotationPointZ * p_78785_1_);
GL11.glCallList(this.displayList);
if (this.childModels != null)
{
for (i = 0; i < this.childModels.size(); ++i)
{
((ModelRenderer)this.childModels.get(i)).render(p_78785_1_);
}
}
GL11.glTranslatef(-this.rotationPointX * p_78785_1_, -this.rotationPointY * p_78785_1_, -this.rotationPointZ * p_78785_1_);
}
}
else
{
GL11.glPushMatrix();
GL11.glTranslatef(this.rotationPointX * p_78785_1_, this.rotationPointY * p_78785_1_, this.rotationPointZ * p_78785_1_);
if (this.rotateAngleZ != 0.0F)
{
GL11.glRotatef(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
}
if (this.rotateAngleY != 0.0F)
{
GL11.glRotatef(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
}
if (this.rotateAngleX != 0.0F)
{
GL11.glRotatef(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
}
GL11.glCallList(this.displayList);
if (this.childModels != null)
{
for (i = 0; i < this.childModels.size(); ++i)
{
((ModelRenderer)this.childModels.get(i)).render(p_78785_1_);
}
}
GL11.glPopMatrix();
}
if (currentPart != null) {
this.rotationPointX -= currentPart.prevPivots[0];
this.rotationPointY -= currentPart.prevPivots[1];
this.rotationPointZ -= currentPart.prevPivots[2];
this.rotateAngleX -= currentPart.prevRotations[0];
this.rotateAngleY -= currentPart.prevRotations[1];
this.rotateAngleZ -= currentPart.prevRotations[2];
}
}
}
}
@SideOnly(Side.CLIENT)
@Inject(method = "render", at = @At(value = "TAIL"))
private void originalRotations(float p_78785_1_, CallbackInfo callbackInfo)
{
if (ClientEventHandler.undoRotations != null) {
this.rotateAngleX = ClientEventHandler.undoRotations[0];
this.rotateAngleY = ClientEventHandler.undoRotations[1];
this.rotateAngleZ = ClientEventHandler.undoRotations[2];
ClientEventHandler.undoRotations = null;
}
if (ClientEventHandler.undoPivots != null) {
this.rotationPointX = ClientEventHandler.undoPivots[0];
this.rotationPointY = ClientEventHandler.undoPivots[1];
this.rotationPointZ = ClientEventHandler.undoPivots[2];
ClientEventHandler.undoPivots = null;
}
}
public String getPartName(ModelRenderer renderer, HashMap<String,String[]> partNames) {
Class<?> RenderClass = renderer.baseModel.getClass();
Object model = renderer.baseModel;
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)) {
return entry.getKey();
}
} catch (Exception ignored) {}
}
public void addInterpolatedAngles(JobPuppet.PartConfig modelPart) {
if (modelPart == null) {
return;
}
return "";
}
public boolean isPart(JobPuppet.PartConfig puppetPart) {
return !puppetPart.disabled && this.partName.equals(modelNameMap.get(puppetPart));
}
public void setInterpolatedAngles(JobPuppet.PartConfig modelPart) {
float pi = (float) Math.PI * (modelPart.fullAngles ? 2 : 1);
if (!modelPart.animate) {
this.rotateAngleX = modelPart.rotationX * pi;
this.rotateAngleY = modelPart.rotationY * pi;
this.rotateAngleZ = modelPart.rotationZ * pi;
} else if (modelPart.partialRotationTick != ClientEventHandler.partialRenderTick) {
modelPart.partialRotationTick = ClientEventHandler.partialRenderTick;
if (modelPart.interpolate) {
if (modelPart.rotationX * pi - this.rotateAngleX != 0)
this.rotateAngleX = (modelPart.rotationX * pi - this.rotateAngleX) * Math.abs(modelPart.animRate) / 10f + this.rotateAngleX;
if (modelPart.rotationY * pi - this.rotateAngleY != 0)
this.rotateAngleY = (modelPart.rotationY * pi - this.rotateAngleY) * Math.abs(modelPart.animRate) / 10f + this.rotateAngleY;
if (modelPart.rotationZ * pi - this.rotateAngleZ != 0)
this.rotateAngleZ = (modelPart.rotationZ * pi - this.rotateAngleZ) * Math.abs(modelPart.animRate) / 10f + this.rotateAngleZ;
} else {
int directionX = Float.compare(modelPart.rotationX * pi, this.rotateAngleX);
this.rotateAngleX += directionX * Math.abs(modelPart.animRate) / 10f;
this.rotateAngleX = directionX == 1 ?
Math.min(modelPart.rotationX * pi,this.rotateAngleX) : Math.max(modelPart.rotationX * pi,this.rotateAngleX);
int directionY = Float.compare(modelPart.rotationY * pi, this.rotateAngleY);
this.rotateAngleY += directionY * Math.abs(modelPart.animRate) / 10f;
this.rotateAngleY = directionY == 1 ?
Math.min(modelPart.rotationY * pi,this.rotateAngleY) : Math.max(modelPart.rotationY * pi,this.rotateAngleY);
int directionZ = Float.compare(modelPart.rotationZ * pi, this.rotateAngleZ);
this.rotateAngleZ += directionZ * Math.abs(modelPart.animRate) / 10f;
this.rotateAngleZ = directionZ == 1 ?
Math.min(modelPart.rotationZ * pi,this.rotateAngleZ) : Math.max(modelPart.rotationZ * pi,this.rotateAngleZ);
if (ClientEventHandler.renderingNpc != null) {
if (!modelPart.animate) {
modelPart.prevRotations[0] = modelPart.rotationX * pi;
modelPart.prevRotations[1] = modelPart.rotationY * pi;
modelPart.prevRotations[2] = modelPart.rotationZ * pi;
} else if (modelPart.partialRotationTick != ClientEventHandler.partialRenderTick) {
modelPart.partialRotationTick = ClientEventHandler.partialRenderTick;
if (modelPart.interpolate) {
modelPart.prevRotations[0] = (modelPart.rotationX * pi - modelPart.prevRotations[0]) * Math.abs(modelPart.animRate) / 10f + modelPart.prevRotations[0];
modelPart.prevRotations[1] = (modelPart.rotationY * pi - modelPart.prevRotations[1]) * Math.abs(modelPart.animRate) / 10f + modelPart.prevRotations[1];
modelPart.prevRotations[2] = (modelPart.rotationZ * pi - modelPart.prevRotations[2]) * Math.abs(modelPart.animRate) / 10f + modelPart.prevRotations[2];
} else {
int directionX = Float.compare(modelPart.rotationX * pi, modelPart.prevRotations[0]);
modelPart.prevRotations[0] += directionX * modelPart.animRate / 10f;
modelPart.prevRotations[0] = directionX == 1 ?
Math.min(modelPart.rotationX * pi, modelPart.prevRotations[0]) : Math.max(modelPart.rotationX * pi, modelPart.prevRotations[0]);
int directionY = Float.compare(modelPart.rotationY * pi, modelPart.prevRotations[1]);
modelPart.prevRotations[1] += directionY * modelPart.animRate / 10f;
modelPart.prevRotations[1] = directionY == 1 ?
Math.min(modelPart.rotationY * pi, modelPart.prevRotations[1]) : Math.max(modelPart.rotationY * pi, modelPart.prevRotations[1]);
int directionZ = Float.compare(modelPart.rotationZ * pi, modelPart.prevRotations[2]);
modelPart.prevRotations[2] += directionZ * modelPart.animRate / 10f;
modelPart.prevRotations[2] = directionZ == 1 ?
Math.min(modelPart.rotationZ * pi, modelPart.prevRotations[2]) : Math.max(modelPart.rotationZ * pi, modelPart.prevRotations[2]);
}
}
} else {
if (!modelPart.animate) {
this.rotateAngleX = modelPart.rotationX * pi;
this.rotateAngleY = modelPart.rotationY * pi;
this.rotateAngleZ = modelPart.rotationZ * pi;
} else if (modelPart.partialRotationTick != ClientEventHandler.partialRenderTick) {
modelPart.partialRotationTick = ClientEventHandler.partialRenderTick;
if (modelPart.interpolate) {
if (modelPart.rotationX * pi - this.rotateAngleX != 0)
this.rotateAngleX = (modelPart.rotationX * pi - this.rotateAngleX) * Math.abs(modelPart.animRate) / 10f + this.rotateAngleX;
if (modelPart.rotationY * pi - this.rotateAngleY != 0)
this.rotateAngleY = (modelPart.rotationY * pi - this.rotateAngleY) * Math.abs(modelPart.animRate) / 10f + this.rotateAngleY;
if (modelPart.rotationZ * pi - this.rotateAngleZ != 0)
this.rotateAngleZ = (modelPart.rotationZ * pi - this.rotateAngleZ) * Math.abs(modelPart.animRate) / 10f + this.rotateAngleZ;
} else {
int directionX = Float.compare(modelPart.rotationX * pi, this.rotateAngleX);
this.rotateAngleX += directionX * Math.abs(modelPart.animRate) / 10f;
this.rotateAngleX = directionX == 1 ?
Math.min(modelPart.rotationX * pi, this.rotateAngleX) : Math.max(modelPart.rotationX * pi, this.rotateAngleX);
int directionY = Float.compare(modelPart.rotationY * pi, this.rotateAngleY);
this.rotateAngleY += directionY * Math.abs(modelPart.animRate) / 10f;
this.rotateAngleY = directionY == 1 ?
Math.min(modelPart.rotationY * pi, this.rotateAngleY) : Math.max(modelPart.rotationY * pi, this.rotateAngleY);
int directionZ = Float.compare(modelPart.rotationZ * pi, this.rotateAngleZ);
this.rotateAngleZ += directionZ * Math.abs(modelPart.animRate) / 10f;
this.rotateAngleZ = directionZ == 1 ?
Math.min(modelPart.rotationZ * pi, this.rotateAngleZ) : Math.max(modelPart.rotationZ * pi, this.rotateAngleZ);
}
}
}
}
public void addInterpolatedOffset(JobPuppet.PartConfig modelPart) {
if (!modelPart.setOriginalPivot) {
modelPart.setOriginalPivot = true;
modelPart.originalPivotX = this.rotationPointX;
modelPart.originalPivotY = this.rotationPointY;
modelPart.originalPivotZ = this.rotationPointZ;
if (modelPart == null) {
return;
}
if (!modelPart.animate) {
this.rotationPointX = modelPart.originalPivotX + modelPart.pivotX;
this.rotationPointY = modelPart.originalPivotY + modelPart.pivotY;
this.rotationPointZ = modelPart.originalPivotZ + modelPart.pivotZ;
modelPart.prevPivots[0] = modelPart.pivotX;
modelPart.prevPivots[1] = modelPart.pivotY;
modelPart.prevPivots[2] = modelPart.pivotZ;
} else if (modelPart.partialPivotTick != ClientEventHandler.partialRenderTick) {
modelPart.partialPivotTick = ClientEventHandler.partialRenderTick;
this.rotationPointX = modelPart.originalPivotX + modelPart.prevPivots[0];
this.rotationPointY = modelPart.originalPivotY + modelPart.prevPivots[1];
this.rotationPointZ = modelPart.originalPivotZ + modelPart.prevPivots[2];
if (modelPart.interpolate) {
modelPart.prevPivots[0] = (modelPart.pivotX - modelPart.prevPivots[0]) * Math.abs(modelPart.animRate) / 10f + modelPart.prevPivots[0];
modelPart.prevPivots[1] = (modelPart.pivotY - modelPart.prevPivots[1]) * Math.abs(modelPart.animRate) / 10f + modelPart.prevPivots[1];
@@ -13,7 +13,8 @@ public class JobPuppet extends JobInterface{
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;
@@ -31,6 +32,7 @@ public class JobPuppet extends JobInterface{
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);
@@ -46,6 +48,7 @@ public class JobPuppet extends JobInterface{
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");
@@ -63,6 +66,9 @@ public class JobPuppet extends JobInterface{
}
public boolean isActive() {
if (!this.enabled)
return false;
if(!npc.isEntityAlive())
return false;
@@ -90,14 +96,8 @@ public class JobPuppet extends JobInterface{
// 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;
public boolean setOriginalPivot;
public float originalPivotX;
public float originalPivotY;
public float originalPivotZ;
public EntityLivingBase npcModel;
// ^^^ Client-sided use ^^^
public PartConfig(Object parent) {
@@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.jobs.IJob;
import noppes.npcs.api.jobs.IJobPuppet;
import noppes.npcs.api.roles.IRole;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.*;
@@ -354,6 +355,10 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
npc.reset();
}
public IJobPuppet getModelData() {
return new ScriptJobPuppet(npc);
}
/**
* @return Returns the npcs current role
*/
@@ -395,8 +400,6 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
return new ScriptJobGuard(npc);
else if(npc.advanced.job == EnumJobType.Healer)
return new ScriptJobHealer(npc);
else if(npc.advanced.job == EnumJobType.Puppet)
return new ScriptJobPuppet(npc);
else if(npc.advanced.job == EnumJobType.ItemGiver)
return new ScriptJobItemGiver(npc);
else if(npc.advanced.job == EnumJobType.Spawner)
@@ -10,7 +10,15 @@ public class ScriptJobPuppet extends ScriptJobInterface implements IJobPuppet {
private JobPuppet job;
public ScriptJobPuppet(EntityNPCInterface npc){
super(npc);
this.job = (JobPuppet) npc.jobInterface;
this.job = npc.display.modelData;
}
public void setEnabled(boolean enabled) {
this.job.enabled = enabled;
}
public boolean enabled() {
return this.job.enabled;
}
public IModelPart getPart(int part) {