mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 03:52:18 +00:00
Added player rotations/pivots/animations, similar to NPC's.
This commit is contained in:
1 parent
d638c98d81
commit
51263a9f82
13 files changed
+726
-10
No files matched your search
@@ -14,12 +14,14 @@ 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 void sendData(EnumPacketServer enu, Object... obs) {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
|
||||
@@ -2,12 +2,12 @@ package noppes.npcs.client;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
||||
import noppes.npcs.client.renderer.RenderCNPCPlayer;
|
||||
|
||||
@@ -20,6 +20,10 @@ public class ClientEventHandler {
|
||||
public static HashMap<Integer,Long> disabledButtonTimes = new HashMap<>();
|
||||
public static float partialHandTicks;
|
||||
|
||||
public static float partialRenderTick;
|
||||
public static EntityPlayer renderingPlayer;
|
||||
public static RenderPlayer renderer;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouse(MouseEvent event) {
|
||||
if (Minecraft.getMinecraft().currentScreen != null)
|
||||
@@ -55,8 +59,17 @@ public class ClientEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderPlayer(RenderPlayerEvent.Pre event) {
|
||||
ClientEventHandler.renderingPlayer = event.entityPlayer;
|
||||
ClientEventHandler.renderer = event.renderer;
|
||||
ClientEventHandler.partialRenderTick = event.partialRenderTick;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderPlayer(RenderPlayerEvent.Post event) {
|
||||
ClientEventHandler.renderingPlayer = null;
|
||||
|
||||
if (hasOverlays(event.entityPlayer)) {
|
||||
try {
|
||||
Class<?> renderPlayerJBRA = Class.forName("JinRyuu.JBRA.RenderPlayerJBRA");
|
||||
|
||||
@@ -35,6 +35,7 @@ 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;
|
||||
@@ -85,6 +86,17 @@ public class NoppesUtil {
|
||||
Client.skinOverlays.put(player.getUniqueID(), skinOverlays);
|
||||
}
|
||||
|
||||
public static void updatePlayerModelData(EntityPlayer player, NBTTagCompound compound) {
|
||||
PlayerModelData modelData;
|
||||
if (!Client.playerModelData.containsKey(player.getUniqueID())) {
|
||||
modelData = new PlayerModelData(player);
|
||||
} else {
|
||||
modelData = Client.playerModelData.get(player.getUniqueID());
|
||||
}
|
||||
modelData.readFromNBT(compound);
|
||||
Client.playerModelData.put(player.getUniqueID(), modelData);
|
||||
}
|
||||
|
||||
public static void spawnScriptedParticle(EntityPlayer player, ByteBuf buffer){
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
|
||||
|
||||
@@ -292,6 +292,13 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
NoppesUtil.updateSkinOverlayData(sendingPlayer, compound);
|
||||
}
|
||||
}
|
||||
else if(type == EnumPacketClient.PLAYER_UPDATE_MODEL_DATA) {
|
||||
EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(Server.readString(buffer));
|
||||
NBTTagCompound compound = Server.readNBT(buffer);
|
||||
if (sendingPlayer != null) {
|
||||
NoppesUtil.updatePlayerModelData(sendingPlayer, compound);
|
||||
}
|
||||
}
|
||||
else if(type == EnumPacketClient.DISABLE_MOUSE_INPUT) {
|
||||
long length = buffer.readLong();
|
||||
try {
|
||||
|
||||
@@ -39,6 +39,7 @@ public enum EnumPacketClient {
|
||||
SWING_PLAYER_ARM,
|
||||
UPDATE_ITEM,
|
||||
PLAYER_UPDATE_SKIN_OVERLAYS,
|
||||
PLAYER_UPDATE_MODEL_DATA,
|
||||
OVERLAY_QUEST_TRACKING,
|
||||
DISABLE_MOUSE_INPUT,
|
||||
PLAY_SOUND_TO,
|
||||
|
||||
@@ -31,6 +31,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 DataTimers timers = new DataTimers(this);
|
||||
public DataSkinOverlays skinOverlays = new DataSkinOverlays(this);
|
||||
@@ -80,6 +81,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
mailData.loadNBTData(data);
|
||||
timers.readFromNBT(data);
|
||||
skinOverlays.readFromNBT(data);
|
||||
modelData.readFromNBT(data);
|
||||
|
||||
if(player != null){
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -117,6 +119,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
mailData.saveNBTData(compound);
|
||||
timers.writeToNBT(compound);
|
||||
skinOverlays.writeToNBT(compound);
|
||||
modelData.writeToNBT(compound);
|
||||
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
@@ -298,6 +301,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
return mailData;
|
||||
}
|
||||
|
||||
public IPlayerModelData getModelData() {
|
||||
return modelData;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
PlayerDataController.instance.savePlayerData(this);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,423 @@
|
||||
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.constants.EnumPacketClient;
|
||||
import noppes.npcs.roles.JobPuppet;
|
||||
|
||||
public class PlayerModelData implements IPlayerModelData {
|
||||
public PlayerData parent;
|
||||
public final EntityPlayer player;
|
||||
|
||||
public JobPuppet.PartConfig head = new JobPuppet.PartConfig();
|
||||
public JobPuppet.PartConfig larm = new JobPuppet.PartConfig();
|
||||
public JobPuppet.PartConfig rarm = new JobPuppet.PartConfig();
|
||||
public JobPuppet.PartConfig body = new JobPuppet.PartConfig();
|
||||
public JobPuppet.PartConfig lleg = new JobPuppet.PartConfig();
|
||||
public JobPuppet.PartConfig rleg = new JobPuppet.PartConfig();
|
||||
|
||||
public boolean enabled = false;
|
||||
public boolean whileStanding = true;
|
||||
public boolean whileAttacking = false;
|
||||
public boolean whileMoving = false;
|
||||
public boolean fullAngles = false;
|
||||
|
||||
public boolean animate = false;
|
||||
public float animRate = 1.0F;
|
||||
|
||||
//Client-sided use
|
||||
public float[] bipedRotsHead = {0,0,0};
|
||||
public float[] bipedRotsBody = {0,0,0};
|
||||
public float[] bipedRotsLeftArm = {0,0,0};
|
||||
public float[] bipedRotsRightArm = {0,0,0};
|
||||
public float[] bipedRotsLeftLeg = {0,0,0};
|
||||
public float[] bipedRotsRightLeg = {0,0,0};
|
||||
|
||||
public PlayerModelData(PlayerData parent) {
|
||||
this.parent = parent;
|
||||
this.player = parent.player;
|
||||
}
|
||||
|
||||
public PlayerModelData(EntityPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void updateClient() {
|
||||
Server.sendToAll(EnumPacketClient.PLAYER_UPDATE_MODEL_DATA, ((PlayerData) parent).player.getCommandSenderName(), this.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
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);
|
||||
compound.setBoolean("PuppetFullAngles", fullAngles);
|
||||
|
||||
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");
|
||||
whileStanding = compound.getBoolean("PuppetStanding");
|
||||
whileAttacking = compound.getBoolean("PuppetAttacking");
|
||||
whileMoving = compound.getBoolean("PuppetMoving");
|
||||
fullAngles = compound.getBoolean("PuppetFullAngles");
|
||||
|
||||
animate = compound.getBoolean("PuppetAnimate");
|
||||
animRate = compound.getFloat("PuppetAnimSpeed");
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean getEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setAnimated(boolean animated) {
|
||||
this.animate = animated;
|
||||
}
|
||||
|
||||
public boolean fullAngles() {
|
||||
return fullAngles;
|
||||
}
|
||||
|
||||
public void setFullAngles(boolean limit) {
|
||||
fullAngles = limit;
|
||||
}
|
||||
|
||||
public boolean isAnimated() {
|
||||
return this.animate;
|
||||
}
|
||||
|
||||
public void setAnimRate(float animRate) {
|
||||
this.animRate = animRate;
|
||||
}
|
||||
|
||||
public float getAnimRate() {
|
||||
return this.animRate;
|
||||
}
|
||||
|
||||
public void doWhileStanding(boolean whileStanding) {
|
||||
this.whileStanding = whileStanding;
|
||||
}
|
||||
|
||||
public boolean doWhileStanding() {
|
||||
return this.whileStanding;
|
||||
}
|
||||
|
||||
public void doWhileAttacking(boolean whileAttacking) {
|
||||
this.whileAttacking = whileAttacking;
|
||||
}
|
||||
|
||||
public boolean doWhileAttacking() {
|
||||
return this.whileAttacking;
|
||||
}
|
||||
|
||||
public void doWhileMoving(boolean whileMoving) {
|
||||
this.whileMoving = whileMoving;
|
||||
}
|
||||
|
||||
public boolean doWhileMoving() {
|
||||
return this.whileMoving;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg)
|
||||
* @return Returns X rotation in degrees (0-360)
|
||||
*/
|
||||
public int getRotationX(int part){
|
||||
if(part == 0)
|
||||
return floatToInt(head.rotationX);
|
||||
if(part == 1)
|
||||
return floatToInt(body.rotationX);
|
||||
if(part == 2)
|
||||
return floatToInt(larm.rotationX);
|
||||
if(part == 3)
|
||||
return floatToInt(rarm.rotationX);
|
||||
if(part == 4)
|
||||
return floatToInt(lleg.rotationX);
|
||||
if(part == 5)
|
||||
return floatToInt(rleg.rotationX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg)
|
||||
* @return Returns Y rotation in degrees (0-360)
|
||||
*/
|
||||
public int getRotationY(int part){
|
||||
if(part == 0)
|
||||
return floatToInt(head.rotationY);
|
||||
if(part == 1)
|
||||
return floatToInt(body.rotationY);
|
||||
if(part == 2)
|
||||
return floatToInt(larm.rotationY);
|
||||
if(part == 3)
|
||||
return floatToInt(rarm.rotationY);
|
||||
if(part == 4)
|
||||
return floatToInt(lleg.rotationY);
|
||||
if(part == 5)
|
||||
return floatToInt(rleg.rotationY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg)
|
||||
* @return Returns Z rotation in degrees (0-360)
|
||||
*/
|
||||
public int getRotationZ(int part){
|
||||
if(part == 0)
|
||||
return floatToInt(head.rotationZ);
|
||||
if(part == 1)
|
||||
return floatToInt(body.rotationZ);
|
||||
if(part == 2)
|
||||
return floatToInt(larm.rotationZ);
|
||||
if(part == 3)
|
||||
return floatToInt(rarm.rotationZ);
|
||||
if(part == 4)
|
||||
return floatToInt(lleg.rotationZ);
|
||||
if(part == 5)
|
||||
return floatToInt(rleg.rotationZ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setRotation(int part, int rotationX, int rotationY, int rotationZ) {
|
||||
this.setRotationX(part,rotationX);
|
||||
this.setRotationY(part,rotationY);
|
||||
this.setRotationZ(part,rotationZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg)
|
||||
* @param rotation Rotation the of the body part
|
||||
*/
|
||||
public void setRotationX(int part, int rotation){
|
||||
float f = rotation / 360f - 0.5f;
|
||||
|
||||
if(part == 0)
|
||||
head.rotationX = f;
|
||||
if(part == 1)
|
||||
body.rotationX = f;
|
||||
if(part == 2)
|
||||
larm.rotationX = f;
|
||||
if(part == 3)
|
||||
rarm.rotationX = f;
|
||||
if(part == 4)
|
||||
lleg.rotationX = f;
|
||||
if(part == 5)
|
||||
rleg.rotationX = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg)
|
||||
* @param rotation Rotation the of the body part
|
||||
*/
|
||||
public void setRotationY(int part, int rotation){
|
||||
float f = rotation / 360f - 0.5f;
|
||||
|
||||
if(part == 0)
|
||||
head.rotationY = f;
|
||||
if(part == 1)
|
||||
body.rotationY = f;
|
||||
if(part == 2)
|
||||
larm.rotationY = f;
|
||||
if(part == 3)
|
||||
rarm.rotationY = f;
|
||||
if(part == 4)
|
||||
lleg.rotationY = f;
|
||||
if(part == 5)
|
||||
rleg.rotationY = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg)
|
||||
* @param rotation Rotation the of the body part
|
||||
*/
|
||||
public void setRotationZ(int part, int rotation){
|
||||
float f = rotation / 360f - 0.5f;
|
||||
|
||||
if(part == 0)
|
||||
head.rotationZ = f;
|
||||
if(part == 1)
|
||||
body.rotationZ = f;
|
||||
if(part == 2)
|
||||
larm.rotationZ = f;
|
||||
if(part == 3)
|
||||
rarm.rotationZ = f;
|
||||
if(part == 4)
|
||||
lleg.rotationZ = f;
|
||||
if(part == 5)
|
||||
rleg.rotationZ = f;
|
||||
}
|
||||
|
||||
public int getOffsetX(int part) {
|
||||
if(part == 0)
|
||||
return floatToInt(head.pivotX);
|
||||
if(part == 1)
|
||||
return floatToInt(body.pivotX);
|
||||
if(part == 2)
|
||||
return floatToInt(larm.pivotX);
|
||||
if(part == 3)
|
||||
return floatToInt(rarm.pivotX);
|
||||
if(part == 4)
|
||||
return floatToInt(lleg.pivotX);
|
||||
if(part == 5)
|
||||
return floatToInt(rleg.pivotX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getOffsetY(int part) {
|
||||
if(part == 0)
|
||||
return floatToInt(head.pivotY);
|
||||
if(part == 1)
|
||||
return floatToInt(body.pivotY);
|
||||
if(part == 2)
|
||||
return floatToInt(larm.pivotY);
|
||||
if(part == 3)
|
||||
return floatToInt(rarm.pivotY);
|
||||
if(part == 4)
|
||||
return floatToInt(lleg.pivotY);
|
||||
if(part == 5)
|
||||
return floatToInt(rleg.pivotY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getOffsetZ(int part) {
|
||||
if(part == 0)
|
||||
return floatToInt(head.pivotZ);
|
||||
if(part == 1)
|
||||
return floatToInt(body.pivotZ);
|
||||
if(part == 2)
|
||||
return floatToInt(larm.pivotZ);
|
||||
if(part == 3)
|
||||
return floatToInt(rarm.pivotZ);
|
||||
if(part == 4)
|
||||
return floatToInt(lleg.pivotZ);
|
||||
if(part == 5)
|
||||
return floatToInt(rleg.pivotZ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setOffset(int part, int offsetX, int offsetY, int offsetZ) {
|
||||
this.setOffsetX(part,offsetX);
|
||||
this.setOffsetY(part,offsetY);
|
||||
this.setOffsetZ(part,offsetZ);
|
||||
}
|
||||
|
||||
public void setOffsetX(int part, int offset) {
|
||||
if(part == 0)
|
||||
head.pivotX = offset;
|
||||
if(part == 1)
|
||||
body.pivotX = offset;
|
||||
if(part == 2)
|
||||
larm.pivotX = offset;
|
||||
if(part == 3)
|
||||
rarm.pivotX = offset;
|
||||
if(part == 4)
|
||||
lleg.pivotX = offset;
|
||||
if(part == 5)
|
||||
rleg.pivotX = offset;
|
||||
}
|
||||
|
||||
public void setOffsetY(int part, int offset) {
|
||||
if(part == 0)
|
||||
head.pivotY = offset;
|
||||
if(part == 1)
|
||||
body.pivotY = offset;
|
||||
if(part == 2)
|
||||
larm.pivotY = offset;
|
||||
if(part == 3)
|
||||
rarm.pivotY = offset;
|
||||
if(part == 4)
|
||||
lleg.pivotY = offset;
|
||||
if(part == 5)
|
||||
rleg.pivotY = offset;
|
||||
}
|
||||
|
||||
public void setOffsetZ(int part, int offset) {
|
||||
if(part == 0)
|
||||
head.pivotZ = offset;
|
||||
if(part == 1)
|
||||
body.pivotZ = offset;
|
||||
if(part == 2)
|
||||
larm.pivotZ = offset;
|
||||
if(part == 3)
|
||||
rarm.pivotZ = offset;
|
||||
if(part == 4)
|
||||
lleg.pivotZ = offset;
|
||||
if(part == 5)
|
||||
rleg.pivotZ = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg)
|
||||
* @return Returns whether or not the body part is enabled
|
||||
*/
|
||||
public boolean isEnabled(int part){
|
||||
if(part == 0)
|
||||
return !head.disabled;
|
||||
if(part == 1)
|
||||
return !body.disabled;
|
||||
if(part == 2)
|
||||
return !larm.disabled;
|
||||
if(part == 3)
|
||||
return !rarm.disabled;
|
||||
if(part == 4)
|
||||
return !lleg.disabled;
|
||||
if(part == 5)
|
||||
return !rleg.disabled;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg)
|
||||
* @param bo Whether or not the body part is enabled
|
||||
*/
|
||||
public void setEnabled(int part, boolean bo){
|
||||
if(part == 0)
|
||||
head.disabled = !bo;
|
||||
if(part == 1)
|
||||
body.disabled = !bo;
|
||||
if(part == 2)
|
||||
larm.disabled = !bo;
|
||||
if(part == 3)
|
||||
rarm.disabled = !bo;
|
||||
if(part == 4)
|
||||
lleg.disabled = !bo;
|
||||
if(part == 5)
|
||||
rleg.disabled = !bo;
|
||||
}
|
||||
|
||||
private int floatToInt(float f){
|
||||
return (int)((f + 0.5) * 360);
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
|
||||
if (CustomNpcs.EntityRendererMixin){
|
||||
mixins.add("MixinEntityRenderer");
|
||||
}
|
||||
mixins.add("MixinModelRenderer");
|
||||
return mixins;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
package noppes.npcs.mixin;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.ClientEventHandler;
|
||||
import noppes.npcs.controllers.data.PlayerModelData;
|
||||
import noppes.npcs.roles.JobPuppet;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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.util.HashMap;
|
||||
|
||||
@Mixin(value = ModelRenderer.class)
|
||||
public 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;
|
||||
|
||||
HashMap<JobPuppet.PartConfig,String> partNames = new HashMap<>();
|
||||
String partName = "";
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Inject(method = "render", at = @At(value = "HEAD"))
|
||||
private void puppetRotations(float p_78785_1_, CallbackInfo callbackInfo)
|
||||
{
|
||||
if (ClientEventHandler.renderingPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Client.playerModelData.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.partName = this.getPartName((ModelRenderer)(Object)this);
|
||||
PlayerModelData modelData = Client.playerModelData.get(ClientEventHandler.renderingPlayer.getUniqueID());
|
||||
this.setModelParts(modelData);
|
||||
if (modelData.enabled) {
|
||||
if(isPart(modelData.head)){
|
||||
this.rotateAngleX = modelData.bipedRotsHead[0];
|
||||
this.rotateAngleY = modelData.bipedRotsHead[1];
|
||||
this.rotateAngleZ = modelData.bipedRotsHead[2];
|
||||
this.setInterpolatedAngles(modelData,modelData.head);
|
||||
}
|
||||
|
||||
if(isPart(modelData.body)){
|
||||
this.rotateAngleX = modelData.bipedRotsBody[0];
|
||||
this.rotateAngleY = modelData.bipedRotsBody[1];
|
||||
this.rotateAngleZ = modelData.bipedRotsBody[2];
|
||||
this.setInterpolatedAngles(modelData,modelData.body);
|
||||
}
|
||||
|
||||
if(isPart(modelData.larm)){
|
||||
this.rotateAngleX = modelData.bipedRotsLeftArm[0];
|
||||
this.rotateAngleY = modelData.bipedRotsLeftArm[1];
|
||||
this.rotateAngleZ = modelData.bipedRotsLeftArm[2];
|
||||
this.setInterpolatedAngles(modelData,modelData.larm);
|
||||
}
|
||||
|
||||
if(isPart(modelData.rarm)){
|
||||
this.rotateAngleX = modelData.bipedRotsRightArm[0];
|
||||
this.rotateAngleY = modelData.bipedRotsRightArm[1];
|
||||
this.rotateAngleZ = modelData.bipedRotsRightArm[2];
|
||||
this.setInterpolatedAngles(modelData,modelData.rarm);
|
||||
}
|
||||
|
||||
if(isPart(modelData.lleg)){
|
||||
this.rotateAngleX = modelData.bipedRotsLeftLeg[0];
|
||||
this.rotateAngleY = modelData.bipedRotsLeftLeg[1];
|
||||
this.rotateAngleZ = modelData.bipedRotsLeftLeg[2];
|
||||
this.setInterpolatedAngles(modelData,modelData.lleg);
|
||||
}
|
||||
|
||||
if(isPart(modelData.rleg)){
|
||||
this.rotateAngleX = modelData.bipedRotsRightLeg[0];
|
||||
this.rotateAngleY = modelData.bipedRotsRightLeg[1];
|
||||
this.rotateAngleZ = modelData.bipedRotsRightLeg[2];
|
||||
this.setInterpolatedAngles(modelData,modelData.rleg);
|
||||
}
|
||||
|
||||
if(isPart(modelData.head)){
|
||||
this.addInterpolatedOffset(modelData, modelData.head);
|
||||
}
|
||||
if(isPart(modelData.body)){
|
||||
this.addInterpolatedOffset(modelData, modelData.body);
|
||||
}
|
||||
if(isPart(modelData.larm)){
|
||||
this.addInterpolatedOffset(modelData, modelData.larm);
|
||||
}
|
||||
if(isPart(modelData.rarm)){
|
||||
this.addInterpolatedOffset(modelData, modelData.rarm);
|
||||
}
|
||||
if(isPart(modelData.lleg)){
|
||||
this.addInterpolatedOffset(modelData, modelData.lleg);
|
||||
}
|
||||
if(isPart(modelData.rleg)){
|
||||
this.addInterpolatedOffset(modelData, modelData.rleg);
|
||||
}
|
||||
|
||||
if(isPart(modelData.head)) {
|
||||
modelData.bipedRotsHead = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
|
||||
}
|
||||
if(isPart(modelData.body)) {
|
||||
modelData.bipedRotsBody = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
|
||||
}
|
||||
if(isPart(modelData.larm)) {
|
||||
modelData.bipedRotsLeftArm = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
|
||||
}
|
||||
if(isPart(modelData.rarm)) {
|
||||
modelData.bipedRotsRightArm = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
|
||||
}
|
||||
if(isPart(modelData.lleg)) {
|
||||
modelData.bipedRotsLeftLeg = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
|
||||
}
|
||||
if(isPart(modelData.rleg)) {
|
||||
modelData.bipedRotsRightLeg = new float[]{this.rotateAngleX, this.rotateAngleY, this.rotateAngleZ};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getPartName(ModelRenderer renderer) {
|
||||
if (renderer == ((ModelBiped) ((ModelRenderer)renderer).baseModel).bipedHead
|
||||
|| renderer == ((ModelBiped) ((ModelRenderer)renderer).baseModel).bipedHeadwear) {
|
||||
return "head";
|
||||
}
|
||||
if (renderer == ((ModelBiped) ((ModelRenderer)renderer).baseModel).bipedBody) {
|
||||
return "body";
|
||||
}
|
||||
if (renderer == ((ModelBiped) ((ModelRenderer)renderer).baseModel).bipedRightArm) {
|
||||
return "rarm";
|
||||
}
|
||||
if (renderer == ((ModelBiped) ((ModelRenderer)renderer).baseModel).bipedLeftArm) {
|
||||
return "larm";
|
||||
}
|
||||
if (renderer == ((ModelBiped) ((ModelRenderer)renderer).baseModel).bipedRightLeg) {
|
||||
return "rleg";
|
||||
}
|
||||
if (renderer == ((ModelBiped) ((ModelRenderer)renderer).baseModel).bipedLeftLeg) {
|
||||
return "lleg";
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> ModelBipedBody = Class.forName("JinRyuu.JRMCore.entity.ModelBipedBody");
|
||||
Object m = renderer.baseModel;
|
||||
|
||||
if (renderer == (ModelRenderer) ModelBipedBody.getField("bipedHeadwear").get(m)
|
||||
|| renderer == (ModelRenderer) ModelBipedBody.getField("bipedHead").get(m)) {
|
||||
return "head";
|
||||
}
|
||||
if (renderer == (ModelRenderer) ModelBipedBody.getField("B1").get(m)
|
||||
|| renderer == (ModelRenderer) ModelBipedBody.getField("bipedBody").get(m)) {
|
||||
return "body";
|
||||
}
|
||||
if (renderer == (ModelRenderer) ModelBipedBody.getField("RA").get(m)
|
||||
|| renderer == (ModelRenderer) ModelBipedBody.getField("bipedRightArm").get(m)) {
|
||||
return "rarm";
|
||||
}
|
||||
if (renderer == (ModelRenderer) ModelBipedBody.getField("LA").get(m)
|
||||
|| renderer == (ModelRenderer) ModelBipedBody.getField("bipedLeftArm").get(m)) {
|
||||
return "larm";
|
||||
}
|
||||
if (renderer == (ModelRenderer) ModelBipedBody.getField("RL").get(m)
|
||||
|| renderer == (ModelRenderer) ModelBipedBody.getField("bipedRightLeg").get(m)) {
|
||||
return "rleg";
|
||||
}
|
||||
if (renderer == (ModelRenderer) ModelBipedBody.getField("LL").get(m)
|
||||
|| renderer == (ModelRenderer) ModelBipedBody.getField("bipedLeftLeg").get(m)) {
|
||||
return "lleg";
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isPart(JobPuppet.PartConfig puppetPart) {
|
||||
return !puppetPart.disabled && this.partName.equals(partNames.get(puppetPart));
|
||||
}
|
||||
|
||||
public void setInterpolatedAngles(PlayerModelData modelData, JobPuppet.PartConfig puppetPart) {
|
||||
float pi = (float) Math.PI * (modelData.fullAngles ? 2 : 1);
|
||||
if (!modelData.animate) {
|
||||
this.rotateAngleX = puppetPart.rotationX * pi;
|
||||
this.rotateAngleY = puppetPart.rotationY * pi;
|
||||
this.rotateAngleZ = puppetPart.rotationZ * pi;
|
||||
} else if (puppetPart.partialRotationTick != ClientEventHandler.partialRenderTick) {
|
||||
puppetPart.partialRotationTick = ClientEventHandler.partialRenderTick;
|
||||
if (puppetPart.rotationX * pi - this.rotateAngleX != 0)
|
||||
this.rotateAngleX = (puppetPart.rotationX * pi - this.rotateAngleX) * modelData.animRate /10f + this.rotateAngleX;
|
||||
if (puppetPart.rotationY * pi - this.rotateAngleY != 0)
|
||||
this.rotateAngleY = (puppetPart.rotationY * pi - this.rotateAngleY) * modelData.animRate /10f + this.rotateAngleY;
|
||||
if (puppetPart.rotationZ * pi - this.rotateAngleZ != 0)
|
||||
this.rotateAngleZ = (puppetPart.rotationZ * pi - this.rotateAngleZ) * modelData.animRate /10f + this.rotateAngleZ;
|
||||
}
|
||||
}
|
||||
|
||||
public void addInterpolatedOffset(PlayerModelData modelData, JobPuppet.PartConfig puppetPart) {
|
||||
if (!puppetPart.setOriginalPivot) {
|
||||
puppetPart.setOriginalPivot = true;
|
||||
puppetPart.originalPivotX = this.rotationPointX;
|
||||
puppetPart.originalPivotY = this.rotationPointY;
|
||||
puppetPart.originalPivotZ = this.rotationPointZ;
|
||||
}
|
||||
|
||||
if (!modelData.animate) {
|
||||
this.rotationPointX = puppetPart.originalPivotX + puppetPart.pivotX;
|
||||
this.rotationPointY = puppetPart.originalPivotY + puppetPart.pivotY;
|
||||
this.rotationPointZ = puppetPart.originalPivotZ + puppetPart.pivotZ;
|
||||
} else if (puppetPart.partialPivotTick != ClientEventHandler.partialRenderTick) {
|
||||
puppetPart.partialPivotTick = ClientEventHandler.partialRenderTick;
|
||||
puppetPart.destPivotX = (puppetPart.pivotX - puppetPart.destPivotX) * modelData.animRate /10f + puppetPart.destPivotX;
|
||||
this.rotationPointX = puppetPart.originalPivotX + puppetPart.destPivotX;
|
||||
puppetPart.destPivotY = (puppetPart.pivotY - puppetPart.destPivotY) * modelData.animRate /10f + puppetPart.destPivotY;
|
||||
this.rotationPointY = puppetPart.originalPivotY + puppetPart.destPivotY;
|
||||
puppetPart.destPivotZ = (puppetPart.pivotZ - puppetPart.destPivotZ) * modelData.animRate /10f + puppetPart.destPivotZ;
|
||||
this.rotationPointZ = puppetPart.originalPivotZ + puppetPart.destPivotZ;
|
||||
}
|
||||
}
|
||||
|
||||
public void setModelParts(PlayerModelData modelData) {
|
||||
partNames.put(modelData.head,"head");
|
||||
partNames.put(modelData.body,"body");
|
||||
partNames.put(modelData.rarm,"rarm");
|
||||
partNames.put(modelData.larm,"larm");
|
||||
partNames.put(modelData.rleg,"rleg");
|
||||
partNames.put(modelData.lleg,"lleg");
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,17 @@ public class JobPuppet extends JobInterface{
|
||||
public float prevPivotX = 0f;
|
||||
public float prevPivotY = 0f;
|
||||
public float prevPivotZ = 0f;
|
||||
|
||||
|
||||
public float partialRotationTick = 0f;
|
||||
public float partialPivotTick = 0f;
|
||||
public float destPivotX = 0f;
|
||||
public float destPivotY = 0f;
|
||||
public float destPivotZ = 0f;
|
||||
public boolean setOriginalPivot = false;
|
||||
public float originalPivotX = 0f;
|
||||
public float originalPivotY = 0f;
|
||||
public float originalPivotZ = 0f;
|
||||
|
||||
public boolean disabled = false;
|
||||
|
||||
public NBTTagCompound writeNBT(){
|
||||
|
||||
@@ -256,7 +256,7 @@ public class ScriptJobPuppet extends ScriptJobInterface implements IJobPuppet {
|
||||
}
|
||||
|
||||
public void setOffsetX(int part, int offset) {
|
||||
if(getRotationZ(part) != offset)
|
||||
if(getOffsetX(part) != offset)
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
|
||||
if(part == 0)
|
||||
@@ -274,7 +274,7 @@ public class ScriptJobPuppet extends ScriptJobInterface implements IJobPuppet {
|
||||
}
|
||||
|
||||
public void setOffsetY(int part, int offset) {
|
||||
if(getRotationZ(part) != offset)
|
||||
if(getOffsetY(part) != offset)
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
|
||||
if(part == 0)
|
||||
@@ -292,7 +292,7 @@ public class ScriptJobPuppet extends ScriptJobInterface implements IJobPuppet {
|
||||
}
|
||||
|
||||
public void setOffsetZ(int part, int offset) {
|
||||
if(getRotationZ(part) != offset)
|
||||
if(getOffsetZ(part) != offset)
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
|
||||
if(part == 0)
|
||||
|
||||
Reference in new issue
Block a user