Compare commits

...
15 Commits
Author SHA1 Message Date
KAMKEEL 0dc0e72b62 Revert the NPC tool click guard; Backhand now drops the offhand click itself 2026-10-06 01:58:05 -04:00
KAMKEEL 8f4fcae735 Using the Wand, Scripter or Cloner on an NPC no longer runs its interact through an offhand click 2026-10-06 01:51:13 -04:00
KAMKEEL 2c29f11550 Skin overlays keep the world's light directions instead of lighting from below 2026-10-06 01:51:13 -04:00
KAMKEEL cc2a1246d5 Stop the script editor typing each key twice under lwjgl3ify 2026-10-01 03:48:44 -04:00
KAMKEEL 5712541cae Stop the mount reset clearing a flying npc's flying flag every tick 2026-10-01 03:03:19 -04:00
KAMKEEL 9a7758a27b Cut wasted NPC tick work and stop the flying flag flipping every tick 2026-10-01 02:58:31 -04:00
KAMKEEL cf1e34b4a7 Smooth fast energy projectiles 2026-09-18 15:11:07 -04:00
KAMKEEL 3ecf0a8970 Skip inactive player pose work 2026-09-18 04:48:54 -04:00
KAMKEEL dbbca1c4ec Keep player pose for held items 2026-09-18 04:19:11 -04:00
KAMKEEL 3ee0df1865 Optional Late Mixins 2026-09-17 19:45:03 -04:00
KAMKEEL 3d530a207a Trace entry into the MPM player model 2026-09-17 18:51:16 -04:00
KAMKEEL fcb3384e5f Apply animations at the MPM model pose boundary 2026-09-17 18:50:20 -04:00
KAMKEEL 2ef2936496 Make MPM animation hooks fail loud and traceable 2026-09-17 18:38:31 -04:00
KAMKEEL e910691279 Animate MorePlayerModels limbs through the optional render mixin 2026-09-17 18:25:52 -04:00
KAMKEEL 3b039f67af Keep the script editor out of keys meant for another box 2026-09-10 04:10:09 -04:00
19 changed files with 820 additions and 65 deletions

No files matched your search

@@ -38,6 +38,9 @@ public abstract class RenderEnergy extends Render {
*/ */
protected boolean shouldSkipInitialActiveRender(Entity entity) { protected boolean shouldSkipInitialActiveRender(Entity entity) {
if (!(entity instanceof EntityEnergyAbility)) return false; if (!(entity instanceof EntityEnergyAbility)) return false;
// Moving projectiles must be visible at their launch point. Hiding their first
// tick makes faster shots first appear several blocks away from the caster.
if (entity instanceof EntityEnergyProjectile) return false;
EntityEnergyAbility ability = (EntityEnergyAbility) entity; EntityEnergyAbility ability = (EntityEnergyAbility) entity;
return !ability.isPreviewMode() && !ability.isCharging() && ability.ticksExisted <= HIDE_INITIAL_ACTIVE_TICKS; return !ability.isPreviewMode() && !ability.isCharging() && ability.ticksExisted <= HIDE_INITIAL_ACTIVE_TICKS;
} }
@@ -911,42 +911,17 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
@Override @Override
public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements) { public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements) {
int steps = Math.max(1, posRotationIncrements);
double dx = x - this.posX;
double dy = y - this.posY;
double dz = z - this.posZ;
double dotToCurrentMotion = dx * this.motionX + dy * this.motionY + dz * this.motionZ;
// Spawn-time and large correction snaps: avoid visible startup rubber-banding.
if (worldObj != null && worldObj.isRemote) {
double distSq = dx * dx + dy * dy + dz * dz;
// Launch-time stale tracker packets can arrive one update late and point behind
// an already-predicted projectile. Skipping these avoids visible backward "bounce".
if (ticksExisted <= 24 && distSq <= 4.0D && dotToCurrentMotion < -0.0025D) {
return;
}
if (ticksExisted <= 2 || distSq > 16.0D) {
this.setPosition(x, y, z);
syncPositionState(x, y, z, true);
return;
}
}
this.interpTargetX = x; this.interpTargetX = x;
this.interpTargetY = y; this.interpTargetY = y;
this.interpTargetZ = z; this.interpTargetZ = z;
if (worldObj != null && worldObj.isRemote && ticksExisted <= 24 && dotToCurrentMotion < 0.0D) { this.rotationYaw = yaw;
// Keep existing velocity when correction points opposite current travel this.rotationPitch = pitch;
// to prevent launch-time reverse lerp.
this.interpTargetMotionX = this.motionX; // Energy projectiles are tracked every tick. Minecraft's usual three-tick
this.interpTargetMotionY = this.motionY; // interpolation continually falls behind that update rate at higher speeds.
this.interpTargetMotionZ = this.motionZ; // One tick still gives RenderManager a full partial-tick transition without
} else { // accumulating a correction that later has to snap.
this.interpTargetMotionX = dx / steps; this.interpSteps = 1;
this.interpTargetMotionY = dy / steps;
this.interpTargetMotionZ = dz / steps;
}
this.interpSteps = steps;
} }
@Override @Override
@@ -959,14 +934,7 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
this.motionZ = motionZ; this.motionZ = motionZ;
} }
/** /** Move the client copy through the latest server position update. */
* Handle client-side position interpolation.
* Only moves position during active interpolation (interpSteps > 0).
* Does NOT predict/drift between server updates — the motion values are
* derived from correction deltas, not actual entity velocity, so applying
* them between updates causes entities to fly off in wrong directions.
* This matches vanilla Minecraft behavior for non-player entities.
*/
protected void handleClientInterpolation() { protected void handleClientInterpolation() {
if (this.interpSteps > 0) { if (this.interpSteps > 0) {
double dx = this.interpTargetX - this.posX; double dx = this.interpTargetX - this.posX;
@@ -984,10 +952,6 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
double newY = this.posY + dy / this.interpSteps; double newY = this.posY + dy / this.interpSteps;
double newZ = this.posZ + dz / this.interpSteps; double newZ = this.posZ + dz / this.interpSteps;
this.motionX = this.motionX + (this.interpTargetMotionX - this.motionX) / this.interpSteps;
this.motionY = this.motionY + (this.interpTargetMotionY - this.motionY) / this.interpSteps;
this.motionZ = this.motionZ + (this.interpTargetMotionZ - this.motionZ) / this.interpSteps;
this.setPosition(newX, newY, newZ); this.setPosition(newX, newY, newZ);
this.interpSteps--; this.interpSteps--;
} }
@@ -0,0 +1,35 @@
package noppes.npcs;
import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
import com.gtnewhorizon.gtnhmixins.LateMixin;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import noppes.npcs.config.ConfigMixin;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* The mixins into other mods' player models, loaded by UniMixins after every
* mod jar is on the class path. Only found when UniMixins is installed; the
* early plugin then leaves these out.
*/
@LateMixin
public class CustomNPCsLateMixins implements ILateMixinLoader {
@Override
public String getMixinConfig() {
return "mixins.customnpcs.late.json";
}
@Override
public List<String> getMixins(Set<String> loadedMods) {
List<String> mixins = new ArrayList<>();
if (!FMLLaunchHandler.side().isClient() || !ConfigMixin.AnimationMixin) {
return mixins;
}
mixins.addAll(OptionalModelMixins.playerModelMixins(true));
System.out.println("[CustomNPC+] Late player model mixins: " + mixins);
return mixins;
}
}
@@ -0,0 +1,115 @@
package noppes.npcs;
import net.minecraft.launchwrapper.Launch;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipFile;
/**
* Which mixins into other mods' player models to load, each only when its
* class is there. With UniMixins the late loader asks after every mod jar is
* on the class path. Without it the early plugin asks before that, finds the
* jar in the mods folder and lends it to the class loader so Mixin can read
* the target.
*/
public final class OptionalModelMixins {
/** Jars lent to the class loader early, taken off the source list again once read. */
private static final List<URL> lentJars = new ArrayList<URL>();
private OptionalModelMixins() {
}
/** UniMixins is a coremod, so its late loader interface is readable this early. */
public static boolean lateLoaderAvailable() {
try {
return Launch.classLoader.getClassBytes("com.gtnewhorizon.gtnhmixins.ILateMixinLoader") != null;
} catch (IOException exception) {
return false;
}
}
/** The mixin names, relative to the late package. */
public static List<String> playerModelMixins(boolean late) {
List<String> mixins = new ArrayList<String>();
if (hasClass("noppes.mpm.client.model.ModelMPM", late)) {
mixins.add("MixinMPMModel");
}
if (hasClass("noppes.mpm.client.model.ModelScaleRenderer", late)) {
mixins.add("MixinMPMModelScaleRenderer");
}
if (hasClass("micdoodle8.mods.galacticraft.core.client.model.ModelPlayerGC", late)) {
mixins.add("MixinGalacticraftPlayerModel");
}
if (hasClass("api.player.model.ModelPlayerAPI", late)) {
mixins.add("MixinPlayerAPIModel");
}
return mixins;
}
/**
* FML lists every class-path source as a mod source, so a lent jar left
* on the list is found twice and refused as a duplicate. Off the list the
* jar stays readable, and FML adds it once itself.
*/
public static void releaseLentJars() {
if (lentJars.isEmpty()) return;
Launch.classLoader.getSources().removeAll(lentJars);
System.out.println("[CustomNPC+] Took " + lentJars.size() + " optional mod jar(s) back off the source list");
lentJars.clear();
}
private static boolean hasClass(String className, boolean late) {
try {
if (Launch.classLoader.getClassBytes(className) != null) {
System.out.println("[CustomNPC+] Optional class " + className + ": on the class path");
return true;
}
} catch (IOException exception) {
System.out.println("[CustomNPC+] Could not inspect optional class " + className + ": " + exception);
}
File jar = late ? null : jarHolding(className);
if (jar == null) {
System.out.println("[CustomNPC+] Optional class " + className + ": not found");
return false;
}
// Mixin drops a @Pseudo target it cannot read when the config is
// prepared. Lending the jar now lets it read the class.
try {
URL url = jar.toURI().toURL();
Launch.classLoader.addURL(url);
lentJars.add(url);
System.out.println("[CustomNPC+] Optional class " + className + ": in mods/"
+ jar.getName() + ", lent to the class path");
return true;
} catch (MalformedURLException exception) {
System.out.println("[CustomNPC+] Optional class " + className + ": in mods/"
+ jar.getName() + " but it could not be lent to the class path: " + exception);
return false;
}
}
/** The jar under mods/ that holds the class, or null. */
private static File jarHolding(String className) {
String entry = className.replace('.', '/') + ".class";
File[] folders = {new File("mods"), new File("mods" + File.separator + "1.7.10")};
for (File folder : folders) {
File[] jars = folder.listFiles();
if (jars == null) continue;
for (File jar : jars) {
if (!jar.getName().toLowerCase().endsWith(".jar")) continue;
try (ZipFile zip = new ZipFile(jar)) {
if (zip.getEntry(entry) != null) return jar;
} catch (IOException ignored) {
// Not a readable jar; nothing to find in it.
}
}
}
return null;
}
}
@@ -28,6 +28,7 @@ import noppes.npcs.client.gui.hud.QuestTrackingComponent;
import noppes.npcs.client.gui.hud.ability.AbilityHotbarComponent; import noppes.npcs.client.gui.hud.ability.AbilityHotbarComponent;
import noppes.npcs.client.gui.player.AuctionTooltipHandler; import noppes.npcs.client.gui.player.AuctionTooltipHandler;
import noppes.npcs.client.KeyPressHandler; import noppes.npcs.client.KeyPressHandler;
import noppes.npcs.client.model.PlayerModelAnimation;
import noppes.npcs.client.renderer.MarkRenderer; import noppes.npcs.client.renderer.MarkRenderer;
import noppes.npcs.client.renderer.RenderCNPCPlayer; import noppes.npcs.client.renderer.RenderCNPCPlayer;
import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.constants.EnumAnimationPart;
@@ -46,6 +47,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
public class ClientEventHandler { public class ClientEventHandler {
private static boolean loggedPlayerRenderer;
public static final RenderCNPCPlayer renderCNPCSelf = new RenderCNPCPlayer(); public static final RenderCNPCPlayer renderCNPCSelf = new RenderCNPCPlayer();
public static final RenderCNPCPlayer renderCNPCPlayer = new RenderCNPCPlayer(); public static final RenderCNPCPlayer renderCNPCPlayer = new RenderCNPCPlayer();
public static HashMap<Integer, Long> disabledButtonTimes = new HashMap<>(); public static HashMap<Integer, Long> disabledButtonTimes = new HashMap<>();
@@ -62,6 +64,7 @@ public class ClientEventHandler {
public static boolean renderingEntityInGUI; public static boolean renderingEntityInGUI;
public static EntityNPCInterface renderingNpc; public static EntityNPCInterface renderingNpc;
public static EntityPlayer renderingPlayer; public static EntityPlayer renderingPlayer;
public static boolean renderingPlayerAnimation;
public static HashMap<EnumAnimationPart, String[]> partNames = new HashMap<>(); public static HashMap<EnumAnimationPart, String[]> partNames = new HashMap<>();
public static HashMap<Class<?>, Field[]> declaredFieldCache = new HashMap<>(); public static HashMap<Class<?>, Field[]> declaredFieldCache = new HashMap<>();
@@ -70,6 +73,7 @@ public class ClientEventHandler {
public static ModelBase playerModel; public static ModelBase playerModel;
private Class<?> renderPlayerJBRA; private Class<?> renderPlayerJBRA;
private PlayerModelAnimation.Pose equippedItemPose;
public ClientEventHandler() { public ClientEventHandler() {
try { try {
@@ -161,6 +165,7 @@ public class ClientEventHandler {
public void onRenderEntity(RenderLivingEvent.Pre event) { public void onRenderEntity(RenderLivingEvent.Pre event) {
if (event.entity instanceof EntityNPCInterface) { if (event.entity instanceof EntityNPCInterface) {
ClientEventHandler.renderingPlayer = null; ClientEventHandler.renderingPlayer = null;
ClientEventHandler.renderingPlayerAnimation = false;
ClientEventHandler.renderingNpc = (EntityNPCInterface) event.entity; ClientEventHandler.renderingNpc = (EntityNPCInterface) event.entity;
} }
ClientEventHandler.renderer = event.renderer; ClientEventHandler.renderer = event.renderer;
@@ -227,6 +232,17 @@ public class ClientEventHandler {
public void onRenderPlayer(RenderPlayerEvent.Pre event) { public void onRenderPlayer(RenderPlayerEvent.Pre event) {
ClientEventHandler.renderingNpc = null; ClientEventHandler.renderingNpc = null;
ClientEventHandler.renderingPlayer = event.entityPlayer; ClientEventHandler.renderingPlayer = event.entityPlayer;
ClientEventHandler.renderingPlayerAnimation = PlayerModelAnimation.shouldApply(event.entityPlayer);
if (!loggedPlayerRenderer) {
loggedPlayerRenderer = true;
String model = event.renderer.mainModel == null ? "null"
: event.renderer.mainModel.getClass().getName();
String arm = event.renderer.modelBipedMain == null
|| event.renderer.modelBipedMain.bipedRightArm == null ? "null"
: event.renderer.modelBipedMain.bipedRightArm.getClass().getName();
System.out.println("[CustomNPC+] Active player renderer="
+ event.renderer.getClass().getName() + "; model=" + model + "; arm=" + arm);
}
} }
@SubscribeEvent(priority = EventPriority.LOWEST) @SubscribeEvent(priority = EventPriority.LOWEST)
@@ -237,8 +253,10 @@ public class ClientEventHandler {
@SubscribeEvent @SubscribeEvent
public void onRenderPlayer(RenderPlayerEvent.Post event) { public void onRenderPlayer(RenderPlayerEvent.Post event) {
restoreEquippedItemPose();
EntityPlayer player = event.entityPlayer; EntityPlayer player = event.entityPlayer;
ClientEventHandler.renderingPlayer = null; ClientEventHandler.renderingPlayer = null;
ClientEventHandler.renderingPlayerAnimation = false;
if (hasOverlays(player)) { if (hasOverlays(player)) {
if (renderPlayerJBRA != null && renderPlayerJBRA.isInstance(event.renderer)) if (renderPlayerJBRA != null && renderPlayerJBRA.isInstance(event.renderer))
@@ -266,6 +284,35 @@ public class ClientEventHandler {
} }
} }
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void applyEquippedItemPose(RenderPlayerEvent.Specials.Pre event) {
restoreEquippedItemPose();
if (!ClientEventHandler.renderingPlayerAnimation) {
return;
}
ModelBiped model = event.renderer.modelBipedMain;
if (model == null) {
return;
}
equippedItemPose = PlayerModelAnimation.capture(model);
PlayerModelAnimation.apply(model);
}
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void restoreEquippedItemPose(RenderPlayerEvent.Specials.Post event) {
restoreEquippedItemPose();
}
private void restoreEquippedItemPose() {
if (equippedItemPose == null) {
return;
}
equippedItemPose.restore();
equippedItemPose = null;
}
@SubscribeEvent @SubscribeEvent
public void cancelSpecials(RenderPlayerEvent.Specials.Pre event) { public void cancelSpecials(RenderPlayerEvent.Specials.Pre event) {
if (event.renderer instanceof RenderCNPCPlayer) { if (event.renderer instanceof RenderCNPCPlayer) {
@@ -68,6 +68,8 @@ public class GuiScriptTextArea extends GuiNpcTextField {
public boolean doubleClicked = false; public boolean doubleClicked = false;
public boolean tripleClicked = false; public boolean tripleClicked = false;
private int clickCount = 0; private int clickCount = 0;
// Character the last key press carried, so its copy from lwjgl3ify's text input can be dropped.
private char lastKeyChar = 0;
private long lastClicked = 0L; private long lastClicked = 0L;
// ==================== TEXT & CONTAINER ==================== // ==================== TEXT & CONTAINER ====================
@@ -1780,6 +1782,17 @@ public class GuiScriptTextArea extends GuiNpcTextField {
*/ */
@Override @Override
public boolean textboxKeyTyped(char c, int i) { public boolean textboxKeyTyped(char c, int i) {
// With lwjgl3ify text input on, one key press sends the key with its
// character and then the same character again with key code 0. Drop the copy.
char previous = lastKeyChar;
lastKeyChar = i != 0 && ChatAllowedCharacters.isAllowedCharacter(c) ? c : 0;
if (i == 0 && previous != 0 && c == previous)
return false;
// Another box has the caret.
if (activeTextfield != null && activeTextfield != this) {
return false;
}
if (KEYS_OVERLAY.keyTyped(c, i)) if (KEYS_OVERLAY.keyTyped(c, i))
return true; return true;
@@ -0,0 +1,104 @@
package noppes.npcs.client.model;
import kamkeel.npcs.addon.DBCAddon;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import noppes.npcs.AnimationMixinFunctions;
import java.util.HashSet;
import java.util.Set;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.controllers.data.AnimationData;
public final class PlayerModelAnimation {
private PlayerModelAnimation() {
}
public static Pose capture(ModelBiped model) {
return new Pose(parts(model));
}
/**
* Avoids snapshotting and reapplying six model parts for every visible
* player when there is no animation capable of changing their pose.
* DBC is kept on the compatibility path because its optional addon owns
* its animation-active check inside applyRenderModel.
*/
public static boolean shouldApply(Entity entity) {
if (entity == null) {
return false;
}
AnimationData data = ClientCacheHandler.playerAnimations.get(entity.getUniqueID());
return data != null && data.animation != null && data.isActive()
|| DBCAddon.IsAvailable();
}
private static final Set<String> REPORTED = new HashSet<String>();
public static void apply(ModelBiped model) {
boolean applied = false;
for (ModelRenderer part : parts(model)) {
if (part != null && AnimationMixinFunctions.applyValues(part)) {
applied = true;
}
}
// Once per model class and outcome: whether the hook had an animation to put on.
String key = model.getClass().getName() + (applied ? " applied" : " nothing");
if (REPORTED.add(key)) {
System.out.println("[CustomNPC+] Player animation on " + model.getClass().getName()
+ ": " + (applied ? "values applied" : "nothing to apply")
+ " (renderingPlayer=" + (ClientEventHandler.renderingPlayer != null)
+ ", renderingNpc=" + (ClientEventHandler.renderingNpc != null) + ")");
}
}
private static ModelRenderer[] parts(ModelBiped model) {
return new ModelRenderer[]{
model.bipedHead,
model.bipedBody,
model.bipedRightArm,
model.bipedLeftArm,
model.bipedRightLeg,
model.bipedLeftLeg
};
}
public static final class Pose {
private final ModelRenderer[] parts;
private final float[][] values;
private Pose(ModelRenderer[] parts) {
this.parts = parts;
this.values = new float[parts.length][6];
for (int i = 0; i < parts.length; i++) {
ModelRenderer part = parts[i];
if (part == null) {
continue;
}
values[i][0] = part.rotationPointX;
values[i][1] = part.rotationPointY;
values[i][2] = part.rotationPointZ;
values[i][3] = part.rotateAngleX;
values[i][4] = part.rotateAngleY;
values[i][5] = part.rotateAngleZ;
}
}
public void restore() {
for (int i = 0; i < parts.length; i++) {
ModelRenderer part = parts[i];
if (part == null) {
continue;
}
part.rotationPointX = values[i][0];
part.rotationPointY = values[i][1];
part.rotationPointZ = values[i][2];
part.rotateAngleX = values[i][3];
part.rotateAngleY = values[i][4];
part.rotateAngleZ = values[i][5];
}
}
}
}
@@ -64,6 +64,10 @@ public class RenderCNPCPlayer extends RenderPlayer {
return false; return false;
} }
// Saved so postRenderOverlay can put the lights back where they were. Placing them again
// there would put them in the model's flipped space and light the overlay from below.
GL11.glPushAttrib(GL11.GL_LIGHTING_BIT | GL11.GL_ENABLE_BIT);
// Overlay & Glow // Overlay & Glow
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
if (overlayData.blend) { if (overlayData.blend) {
@@ -112,12 +116,10 @@ public class RenderCNPCPlayer extends RenderPlayer {
GL11.glLoadIdentity(); GL11.glLoadIdentity();
GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopAttrib();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_BLEND);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
Minecraft.getMinecraft().entityRenderer.enableLightmap((double) 0); Minecraft.getMinecraft().entityRenderer.enableLightmap((double) 0);
RenderHelper.enableStandardItemLighting();
} }
@Override @Override
@@ -46,7 +46,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
return; return;
if (!this.canFly() || this.hurtTime != 0 || !this.canBreathe()) { if (!this.canFly() || this.hurtTime != 0 || !this.canBreathe()) {
setNpcFlyingState(false); setNpcFlyingState(false);
super.moveEntityWithHeading(p_70612_1_, p_70612_2_); moveWithoutMountHandling(p_70612_1_, p_70612_2_);
return; return;
} }
@@ -70,7 +70,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
} else if (heightOffGround < Math.ceil(this.height) && this.motionY == 0) { } else if (heightOffGround < Math.ceil(this.height) && this.motionY == 0) {
this.flyLimitAllow = false; this.flyLimitAllow = false;
setNpcFlyingState(false); setNpcFlyingState(false);
super.moveEntityWithHeading(p_70612_1_, p_70612_2_); moveWithoutMountHandling(p_70612_1_, p_70612_2_);
return; return;
} }
this.flyLimitAllow = true; this.flyLimitAllow = true;
@@ -81,7 +81,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
desiredMotionY = -Math.abs(this.ais.flyGravity); desiredMotionY = -Math.abs(this.ais.flyGravity);
} }
this.motionY = desiredMotionY; this.motionY = desiredMotionY;
super.moveEntityWithHeading(p_70612_1_, p_70612_2_); moveWithoutMountHandling(p_70612_1_, p_70612_2_);
this.motionY = desiredMotionY; this.motionY = desiredMotionY;
this.updateLimbSwing(); this.updateLimbSwing();
@@ -434,7 +434,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
if (this.ticksExisted % 20 == 0) if (this.ticksExisted % 20 == 0)
faction = getFaction(); faction = getFaction();
if (!worldObj.isRemote) { if (!worldObj.isRemote) {
if (!isKilled() && this.ticksExisted % 20 == 0) { if (this.ticksExisted % 20 == 0 && !isKilled()) {
if (this.getHealth() < this.getMaxHealth()) { if (this.getHealth() < this.getMaxHealth()) {
if (stats.healthRegen > 0 && !isAttacking()) if (stats.healthRegen > 0 && !isAttacking())
heal(stats.healthRegen); heal(stats.healthRegen);
@@ -1338,13 +1338,17 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
this.height = newHeight; this.height = newHeight;
this.setPosition(posX, posY, posZ); this.setPosition(posX, posY, posZ);
if (newWidth > oldWidth && !this.firstUpdate && !this.worldObj.isRemote) { // Only push when the box really grew into a block, and only by the half-width it grew:
// setPosition already recentered it, unlike vanilla setSize which grows from the corner.
if (newWidth > oldWidth && !this.firstUpdate && !this.worldObj.isRemote
&& !worldObj.getCollidingBoundingBoxes(this, boundingBox).isEmpty()) {
// Lying and crawling widen the box, and moveEntity would answer that by stepping the // Lying and crawling widen the box, and moveEntity would answer that by stepping the
// npc up onto whatever it now touches. Only the horizontal push is wanted here. // npc up onto whatever it now touches. Only the horizontal push is wanted here.
float push = (oldWidth - newWidth) / 2;
float prevStepHeight = this.stepHeight; float prevStepHeight = this.stepHeight;
this.stepHeight = 0.0F; this.stepHeight = 0.0F;
try { try {
this.moveEntity(oldWidth - newWidth, 0.0D, oldWidth - newWidth); this.moveEntity(push, 0.0D, push);
} finally { } finally {
this.stepHeight = prevStepHeight; this.stepHeight = prevStepHeight;
} }
@@ -1419,7 +1423,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
} }
public void onCollide() { public void onCollide() {
if (!isEntityAlive() || ticksExisted % 4 != 0) if (ticksExisted % 4 != 0 || !isEntityAlive())
return; return;
AxisAlignedBB axisalignedbb = null; AxisAlignedBB axisalignedbb = null;
@@ -1666,11 +1670,14 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
} }
public boolean isVeryNearAssignedPlace() { public boolean isVeryNearAssignedPlace() {
// Scaled by the footprint: 0.2 for a default 0.6 wide npc, so big npcs are not held to a
// tolerance finer than their own body. Floored for corpses, which shrink to 0.00001.
double t = Math.max(0.2, width / 3);
double xx = posX - getStartXPos(); double xx = posX - getStartXPos();
double zz = posZ - getStartZPos(); double zz = posZ - getStartZPos();
if (xx < -0.2 || xx > 0.2) if (xx < -t || xx > t)
return false; return false;
return !(zz < -0.2) && !(zz > 0.2); return !(zz < -t) && !(zz > t);
} }
@Override @Override
@@ -2270,6 +2277,11 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
if (handleMountedMovement(strafe, forward)) { if (handleMountedMovement(strafe, forward)) {
return; return;
} }
moveWithoutMountHandling(strafe, forward);
}
/** Normal movement, for callers that already ran the mount handling this tick. */
protected void moveWithoutMountHandling(float strafe, float forward) {
double d0 = this.posX; double d0 = this.posX;
double d1 = this.posY; double d1 = this.posY;
double d2 = this.posZ; double d2 = this.posZ;
@@ -140,6 +140,9 @@ public class DataTimers implements ITimers {
} }
public void update() { public void update() {
// Runs every tick for every npc and player. Most have no timers, so skip the copy.
if (this.timers.isEmpty())
return;
Iterator<DataTimers.Timer> var1 = (new ArrayList<>(this.timers.values())).iterator(); Iterator<DataTimers.Timer> var1 = (new ArrayList<>(this.timers.values())).iterator();
while (var1.hasNext()) { while (var1.hasNext()) {
@@ -1,6 +1,7 @@
package noppes.npcs.mixin; package noppes.npcs.mixin;
import cpw.mods.fml.relauncher.FMLLaunchHandler; import cpw.mods.fml.relauncher.FMLLaunchHandler;
import noppes.npcs.OptionalModelMixins;
import noppes.npcs.config.ConfigMixin; import noppes.npcs.config.ConfigMixin;
import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
@@ -14,7 +15,7 @@ import java.util.Set;
public class CustomNPCsMixinPlugin implements IMixinConfigPlugin { public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
@Override @Override
public void onLoad(String mixinPackage) { public void onLoad(String mixinPackage) {
System.out.println("[CustomNPC+] Mixin plugin loaded from " + mixinPackage);
} }
@Override @Override
@@ -29,7 +30,8 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
@Override @Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
// The targets are read by now; a jar lent so Mixin could read one goes back.
OptionalModelMixins.releaseLentJars();
} }
@Override @Override
@@ -39,6 +41,9 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
String configPath = "config" + File.separator + "CustomNpcPlus" + File.separator; String configPath = "config" + File.separator + "CustomNpcPlus" + File.separator;
ConfigMixin.init(new File(configPath + "mixin.cfg")); ConfigMixin.init(new File(configPath + "mixin.cfg"));
boolean client = FMLLaunchHandler.side().isClient(); boolean client = FMLLaunchHandler.side().isClient();
System.out.println("[CustomNPC+] Choosing mixins: side=" + FMLLaunchHandler.side()
+ ", animation=" + ConfigMixin.AnimationMixin
+ ", firstPersonAnimation=" + ConfigMixin.FirstPersonAnimationMixin);
List<String> mixins = new ArrayList<>(); List<String> mixins = new ArrayList<>();
@@ -49,8 +54,16 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
} }
if (ConfigMixin.AnimationMixin) { if (ConfigMixin.AnimationMixin) {
mixins.add("MixinModelRenderer"); mixins.add("MixinModelRenderer");
if (OptionalModelMixins.lateLoaderAvailable()) {
System.out.println("[CustomNPC+] UniMixins is here; the other mods' model mixins load late");
} else {
for (String name : OptionalModelMixins.playerModelMixins(false)) {
mixins.add("late." + name);
}
}
mixins.add("MixinRendererLivingEntity"); mixins.add("MixinRendererLivingEntity");
} }
System.out.println("[CustomNPC+] Client mixins chosen: " + mixins);
if (ConfigMixin.FirstPersonAnimationMixin) { if (ConfigMixin.FirstPersonAnimationMixin) {
mixins.add("MixinItemRenderer"); mixins.add("MixinItemRenderer");
} }
@@ -64,16 +77,28 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
mixins.add("MixinEntityTrackerEntry"); mixins.add("MixinEntityTrackerEntry");
} }
System.out.println("[CustomNPC+] Selected mixins: " + mixins);
return mixins; return mixins;
} }
@Override @Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
if (isPlayerCompatibilityMixin(mixinClassName)) {
System.out.println("[CustomNPC+] Applying player animation mixin to " + targetClassName);
}
} }
@Override @Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
if (isPlayerCompatibilityMixin(mixinClassName)) {
System.out.println("[CustomNPC+] Applied player animation mixin to " + targetClassName);
}
}
private static boolean isPlayerCompatibilityMixin(String mixinClassName) {
return mixinClassName.contains("MixinMPMModel")
|| mixinClassName.contains("MixinGalacticraftPlayerModel")
|| mixinClassName.contains("MixinPlayerAPIModel");
} }
} }
@@ -4,6 +4,7 @@ import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.AnimationMixinFunctions; import noppes.npcs.AnimationMixinFunctions;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -11,11 +12,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(RendererLivingEntity.class) @Mixin(RendererLivingEntity.class)
public class MixinRendererLivingEntity { public class MixinRendererLivingEntity {
@Unique private static boolean cnpc$loggedLivingRenderHook;
@Inject(method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", at = @At( @Inject(method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/client/renderer/entity/RendererLivingEntity;renderModel(Lnet/minecraft/entity/EntityLivingBase;FFFFFF)V", target = "Lnet/minecraft/client/renderer/entity/RendererLivingEntity;renderModel(Lnet/minecraft/entity/EntityLivingBase;FFFFFF)V",
shift = At.Shift.BEFORE)) shift = At.Shift.BEFORE))
public void render_pre(EntityLivingBase p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_, CallbackInfo ci) { public void render_pre(EntityLivingBase p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_, CallbackInfo ci) {
if (!cnpc$loggedLivingRenderHook) {
cnpc$loggedLivingRenderHook = true;
System.out.println("[CustomNPC+] RendererLivingEntity animation hook is running");
}
AnimationMixinFunctions.playerFullModel_head(p_76986_1_, ci); AnimationMixinFunctions.playerFullModel_head(p_76986_1_, ci);
} }
} }
@@ -0,0 +1,86 @@
package noppes.npcs.mixin.late;
import net.minecraft.client.model.ModelBiped;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.client.model.PlayerModelAnimation;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/** Applies player animations after Galacticraft calculates its player pose. */
@Pseudo
@Mixin(targets = "micdoodle8.mods.galacticraft.core.client.model.ModelPlayerGC", remap = false)
public abstract class MixinGalacticraftPlayerModel {
@Unique private PlayerModelAnimation.Pose cnpc$pose;
@Unique private boolean cnpc$rendering;
@Unique private static boolean cnpc$loggedHook;
@Inject(
method = {
"render(Lnet/minecraft/entity/Entity;FFFFFF)V",
"func_78088_a(Lnet/minecraft/entity/Entity;FFFFFF)V"
},
at = @At("HEAD"),
remap = false,
require = 1
)
private void cnpc$beginRender(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
cnpc$rendering = ClientEventHandler.renderingPlayer == entity
&& ClientEventHandler.renderingPlayerAnimation;
if (!cnpc$rendering) {
cnpc$pose = null;
return;
}
ModelBiped model = (ModelBiped) (Object) this;
cnpc$pose = PlayerModelAnimation.capture(model);
}
@Inject(
method = {
"setRotationAngles(FFFFFFLnet/minecraft/entity/Entity;)V",
"func_78087_a(FFFFFFLnet/minecraft/entity/Entity;)V"
},
at = @At("RETURN"),
remap = false,
require = 1
)
private void cnpc$applyAnimation(float limbSwing, float limbSwingAmount, float age,
float yaw, float pitch, float scale, Entity entity,
CallbackInfo callbackInfo) {
if (!cnpc$rendering) {
return;
}
ModelBiped model = (ModelBiped) (Object) this;
PlayerModelAnimation.apply(model);
if (!cnpc$loggedHook) {
cnpc$loggedHook = true;
System.out.println("[CustomNPC+] Galacticraft ModelPlayerGC animation hook is running");
}
}
@Inject(
method = {
"render(Lnet/minecraft/entity/Entity;FFFFFF)V",
"func_78088_a(Lnet/minecraft/entity/Entity;FFFFFF)V"
},
at = @At("RETURN"),
remap = false,
require = 1
)
private void cnpc$endRender(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
if (cnpc$pose != null) {
cnpc$pose.restore();
}
cnpc$pose = null;
cnpc$rendering = false;
}
}
@@ -0,0 +1,100 @@
package noppes.npcs.mixin.late;
import net.minecraft.client.model.ModelBiped;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.client.model.PlayerModelAnimation;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* Applies CustomNPC+ animation values after MPM calculates its ordinary pose
* and immediately before MPM draws its replacement player model.
*/
@Pseudo
@Mixin(targets = "noppes.mpm.client.model.ModelMPM", remap = false)
public abstract class MixinMPMModel {
@Unique private static boolean cnpc$loggedModelEntry;
@Unique private static boolean cnpc$loggedModelHook;
@Unique private PlayerModelAnimation.Pose cnpc$pose;
@Unique private boolean cnpc$rendering;
@Inject(
method = {
"render(Lnet/minecraft/entity/Entity;FFFFFF)V",
"func_78088_a(Lnet/minecraft/entity/Entity;FFFFFF)V"
},
at = @At("HEAD"),
remap = false,
require = 1
)
private void cnpc$logModelEntry(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
if (!cnpc$loggedModelEntry) {
cnpc$loggedModelEntry = true;
System.out.println("[CustomNPC+] MPM ModelMPM render method is running");
}
cnpc$rendering = ClientEventHandler.renderingPlayer == entity
&& ClientEventHandler.renderingPlayerAnimation;
cnpc$pose = cnpc$rendering
? PlayerModelAnimation.capture((ModelBiped) (Object) this)
: null;
}
@Inject(
method = {
"render(Lnet/minecraft/entity/Entity;FFFFFF)V",
"func_78088_a(Lnet/minecraft/entity/Entity;FFFFFF)V"
},
at = @At(
value = "INVOKE",
target = "Lnoppes/mpm/client/model/ModelMPM;renderHead(Lnet/minecraft/entity/Entity;F)V",
shift = At.Shift.BEFORE,
remap = false
),
remap = false,
require = 1
)
private void cnpc$applyPlayerAnimation(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
if (!cnpc$rendering) {
return;
}
ModelBiped model = (ModelBiped) (Object) this;
if (!cnpc$loggedModelHook) {
cnpc$loggedModelHook = true;
System.out.println("[CustomNPC+] MPM ModelMPM pose hook is running; arm="
+ model.bipedRightArm.getClass().getName());
}
PlayerModelAnimation.apply(model);
}
@Inject(
method = {
"render(Lnet/minecraft/entity/Entity;FFFFFF)V",
"func_78088_a(Lnet/minecraft/entity/Entity;FFFFFF)V"
},
at = @At("RETURN"),
remap = false,
require = 1
)
private void cnpc$restorePlayerPose(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
if (cnpc$pose != null) {
cnpc$pose.restore();
cnpc$pose = null;
}
cnpc$rendering = false;
}
}
@@ -0,0 +1,104 @@
package noppes.npcs.mixin.late;
import net.minecraft.client.model.ModelRenderer;
import noppes.npcs.AnimationMixinFunctions;
import noppes.npcs.client.ClientEventHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* Lets CustomNPC+ animations reach MorePlayerModels+' replacement limbs.
*
* MPM's ModelScaleRenderer overrides ModelRenderer.render without calling the
* parent implementation, so the normal animation mixin is bypassed. The
* string target and {@link Pseudo} keep this integration entirely optional.
*/
@Pseudo
@Mixin(targets = "noppes.mpm.client.model.ModelScaleRenderer", remap = false)
public abstract class MixinMPMModelScaleRenderer {
@Unique private boolean cnpc$changed;
@Unique private float cnpc$pointX;
@Unique private float cnpc$pointY;
@Unique private float cnpc$pointZ;
@Unique private float cnpc$angleX;
@Unique private float cnpc$angleY;
@Unique private float cnpc$angleZ;
@Unique private float cnpc$offsetX;
@Unique private float cnpc$offsetY;
@Unique private float cnpc$offsetZ;
@Unique private static boolean cnpc$loggedRenderHook;
@Unique private static boolean cnpc$loggedAnimation;
@Unique private static boolean cnpc$loggedChangedValues;
@Inject(method = {"render(F)V", "func_78785_a(F)V"}, at = @At("HEAD"), remap = false, require = 1)
private void cnpc$applyAnimation(float scale, CallbackInfo callbackInfo) {
ModelRenderer renderer = (ModelRenderer) (Object) this;
if (!cnpc$loggedRenderHook) {
cnpc$loggedRenderHook = true;
System.out.println("[CustomNPC+] MPM ModelScaleRenderer render hook is running; model="
+ renderer.baseModel.getClass().getName());
}
cnpc$changed = false;
if (!ClientEventHandler.renderingPlayerAnimation) {
return;
}
cnpc$pointX = renderer.rotationPointX;
cnpc$pointY = renderer.rotationPointY;
cnpc$pointZ = renderer.rotationPointZ;
cnpc$angleX = renderer.rotateAngleX;
cnpc$angleY = renderer.rotateAngleY;
cnpc$angleZ = renderer.rotateAngleZ;
cnpc$offsetX = renderer.offsetX;
cnpc$offsetY = renderer.offsetY;
cnpc$offsetZ = renderer.offsetZ;
try {
cnpc$changed = AnimationMixinFunctions.applyValues(renderer);
if (ClientEventHandler.renderingPlayer != null) {
boolean valuesChanged = cnpc$pointX != renderer.rotationPointX
|| cnpc$pointY != renderer.rotationPointY
|| cnpc$pointZ != renderer.rotationPointZ
|| cnpc$angleX != renderer.rotateAngleX
|| cnpc$angleY != renderer.rotateAngleY
|| cnpc$angleZ != renderer.rotateAngleZ;
if (!cnpc$loggedAnimation) {
cnpc$loggedAnimation = true;
System.out.println("[CustomNPC+] MPM render hook sees active animation for "
+ ClientEventHandler.renderingPlayer.getCommandSenderName());
}
if (valuesChanged && !cnpc$loggedChangedValues) {
cnpc$loggedChangedValues = true;
System.out.println("[CustomNPC+] MPM animation changed limb values; limb="
+ renderer.getClass().getName());
}
}
} catch (Exception ignored) {
cnpc$changed = false;
System.out.println("[CustomNPC+] MPM animation hook failed: " + ignored);
ignored.printStackTrace(System.out);
}
}
@Inject(method = {"render(F)V", "func_78785_a(F)V"}, at = @At("RETURN"), remap = false, require = 1)
private void cnpc$restoreAnimation(float scale, CallbackInfo callbackInfo) {
if (!cnpc$changed) return;
ModelRenderer renderer = (ModelRenderer) (Object) this;
renderer.rotationPointX = cnpc$pointX;
renderer.rotationPointY = cnpc$pointY;
renderer.rotationPointZ = cnpc$pointZ;
renderer.rotateAngleX = cnpc$angleX;
renderer.rotateAngleY = cnpc$angleY;
renderer.rotateAngleZ = cnpc$angleZ;
renderer.offsetX = cnpc$offsetX;
renderer.offsetY = cnpc$offsetY;
renderer.offsetZ = cnpc$offsetZ;
cnpc$changed = false;
}
}
@@ -0,0 +1,108 @@
package noppes.npcs.mixin.late;
import net.minecraft.client.model.ModelBiped;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.client.model.PlayerModelAnimation;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
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;
/** Applies player animations after PlayerAPI and its model bases calculate the pose. */
@Pseudo
@Mixin(targets = "api.player.model.ModelPlayerAPI", remap = false)
public abstract class MixinPlayerAPIModel {
@Unique private static Field cnpc$modelField;
@Unique private static boolean cnpc$modelLookupFailed;
@Unique private static boolean cnpc$loggedHook;
@Unique private PlayerModelAnimation.Pose cnpc$pose;
@Unique private boolean cnpc$rendering;
@Inject(
method = "render(Lnet/minecraft/entity/Entity;FFFFFF)V",
at = @At("HEAD"),
remap = false,
require = 1
)
private void cnpc$beginRender(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
cnpc$rendering = ClientEventHandler.renderingPlayer == entity
&& ClientEventHandler.renderingPlayerAnimation;
if (!cnpc$rendering) {
cnpc$pose = null;
return;
}
ModelBiped model = cnpc$model();
if (model == null) {
cnpc$rendering = false;
return;
}
cnpc$pose = PlayerModelAnimation.capture(model);
}
@Inject(
method = "setRotationAngles(FFFFFFLnet/minecraft/entity/Entity;)V",
at = @At("RETURN"),
remap = false,
require = 1
)
private void cnpc$applyAnimation(float limbSwing, float limbSwingAmount, float age,
float yaw, float pitch, float scale, Entity entity,
CallbackInfo callbackInfo) {
if (!cnpc$rendering) {
return;
}
ModelBiped model = cnpc$model();
if (model == null) {
return;
}
PlayerModelAnimation.apply(model);
if (!cnpc$loggedHook) {
cnpc$loggedHook = true;
System.out.println("[CustomNPC+] PlayerAPI model animation hook is running; model="
+ model.getClass().getName());
}
}
@Inject(
method = "render(Lnet/minecraft/entity/Entity;FFFFFF)V",
at = @At("RETURN"),
remap = false,
require = 1
)
private void cnpc$endRender(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
if (cnpc$pose != null) {
cnpc$pose.restore();
}
cnpc$pose = null;
cnpc$rendering = false;
}
@Unique
private ModelBiped cnpc$model() {
if (cnpc$modelLookupFailed) {
return null;
}
try {
if (cnpc$modelField == null) {
cnpc$modelField = this.getClass().getDeclaredField("modelPlayer");
cnpc$modelField.setAccessible(true);
}
Object model = cnpc$modelField.get(this);
return model instanceof ModelBiped ? (ModelBiped) model : null;
} catch (ReflectiveOperationException exception) {
cnpc$modelLookupFailed = true;
System.out.println("[CustomNPC+] PlayerAPI model lookup failed: " + exception);
return null;
}
}
}
@@ -26,7 +26,7 @@ public final class NPCMountUtil {
public static boolean handleMountedMovement(EntityNPCInterface npc, MountState state, float strafe, float forward) { public static boolean handleMountedMovement(EntityNPCInterface npc, MountState state, float strafe, float forward) {
if (npc.advanced.role != EnumRoleType.Mount || !(npc.roleInterface instanceof RoleMount)) { if (npc.advanced.role != EnumRoleType.Mount || !(npc.roleInterface instanceof RoleMount)) {
resetMountedFlightState(npc, state); resetWithoutRider(npc, state);
return false; return false;
} }
if (npc.riddenByEntity != null && !(npc.riddenByEntity instanceof EntityPlayer)) { if (npc.riddenByEntity != null && !(npc.riddenByEntity instanceof EntityPlayer)) {
@@ -34,7 +34,7 @@ public final class NPCMountUtil {
return false; return false;
} }
if (!(npc.riddenByEntity instanceof EntityPlayer)) { if (!(npc.riddenByEntity instanceof EntityPlayer)) {
resetMountedFlightState(npc, state); resetWithoutRider(npc, state);
return false; return false;
} }
@@ -233,14 +233,15 @@ public final class NPCMountUtil {
} }
public static void applyUnriddenFlightDescent(EntityNPCInterface npc, MountState state, RoleMount mount) { public static void applyUnriddenFlightDescent(EntityNPCInterface npc, MountState state, RoleMount mount) {
// A flying npc's own movement sets its flying flag.
if (npc.canFly()) {
return;
}
if (mount == null || !mount.isFlyingMountEnabled()) { if (mount == null || !mount.isFlyingMountEnabled()) {
npc.setNpcFlyingState(false); npc.setNpcFlyingState(false);
npc.setNpcJumpingState(false); npc.setNpcJumpingState(false);
return; return;
} }
if (npc.canFly()) {
return;
}
if (npc.onGround) { if (npc.onGround) {
npc.motionY = 0.0D; npc.motionY = 0.0D;
npc.setNpcFlyingState(false); npc.setNpcFlyingState(false);
@@ -314,6 +315,21 @@ public final class NPCMountUtil {
return state.flightMode; return state.flightMode;
} }
/**
* Reset for an npc with no player on it. A flying npc sets its flying flag right after this,
* so clearing it here would flip it every tick and resend the npc's data every tick.
*/
private static void resetWithoutRider(EntityNPCInterface npc, MountState state) {
if (!npc.canFly()) {
resetMountedFlightState(npc, state);
return;
}
state.flightMode = false;
state.jumpPressed = false;
state.flightToggleTimer = 0;
npc.setNpcJumpingState(false);
}
public static void resetMountedFlightState(EntityNPCInterface npc, MountState state) { public static void resetMountedFlightState(EntityNPCInterface npc, MountState state) {
state.flightMode = false; state.flightMode = false;
state.jumpPressed = false; state.jumpPressed = false;
@@ -0,0 +1,11 @@
{
"required": true,
"minVersion": "0.7.11",
"package": "noppes.npcs.mixin.late",
"refmap": "mixins.customnpcs.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixins": [],
"client": [],
"server": []
}