Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/main/java/fr/dynamx/client/renders/model/ModelObjArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,42 +173,42 @@ public void renderPart(Matrix4f transform, EntityEquipmentSlot part, boolean for

public void renderHead(float scale) {
if (head != null) {
setModelAttributes(this); //Reset rotations
resetArmorRenderers();
head.render(scale);
}
}

public void renderChest(float scale) {
if (body != null) {
setModelAttributes(this); //Reset rotations
resetArmorRenderers();
body.render(scale);
}
}

public void renderLeftArm(float scale) {
if (arms != null) {
setModelAttributes(this); //Reset rotations
resetArmorRenderers();
renderPart(arms[0], scale);
}
}

public void renderRightArm(float scale) {
if (arms != null) {
setModelAttributes(this); //Reset rotations
resetArmorRenderers();
renderPart(arms[1], scale);
}
}

public void renderLeftLeg(float scale) {
if (legs != null) {
setModelAttributes(this); //Reset rotations
resetArmorRenderers();
renderPart(legs[0], scale);
}
}

public void renderRightLeg(float scale) {
if (legs != null) {
setModelAttributes(this); //Reset rotations
resetArmorRenderers();
renderPart(legs[1], scale);
}
}
Expand All @@ -222,6 +222,23 @@ protected void renderPart(Matrix4f transform, ArmorRenderer armor, boolean force
armor.render(tempTransform, forceVanillaRender);
}

public void resetArmorRenderers() {
if (head != null) resetRenderer(head);
if (body != null) resetRenderer(body);
if (arms != null) { for (ArmorRenderer arm : arms) resetRenderer(arm); }
if (legs != null) { for (ArmorRenderer leg : legs) resetRenderer(leg); }
if (foot != null) { for (ArmorRenderer f : foot) resetRenderer(f); }
}

private static void resetRenderer(ArmorRenderer armor) {
armor.rotationPointX = armor.offsetX;
armor.rotationPointY = armor.offsetY;
armor.rotationPointZ = armor.offsetZ;
armor.rotateAngleX = 0;
armor.rotateAngleY = 0;
armor.rotateAngleZ = 0;
}

private static void copyModelAnglesForArmor(ModelRenderer bodyPart, ModelRenderer armor) {
armor.rotationPointX = bodyPart.rotationPointX / 16f;
armor.rotationPointY = bodyPart.rotationPointY / 16f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public void render(BaseRenderContext.ArmorRenderContext context, A packInfo, Mat
public void renderItemModel(BaseRenderContext.ItemRenderContext context, A packInfo, Matrix4f transform) {
EntityEquipmentSlot slot = ((DynamXItemArmor<?>) context.getStack().getItem()).armorType;
packInfo.getObjArmor().setActivePart(slot, context.getTextureId());
//restore default rotations (contained in ModelBiped)
packInfo.getObjArmor().setModelAttributes(packInfo.getObjArmor());
packInfo.getObjArmor().resetArmorRenderers();
if (context.getRenderType() != ItemCameraTransforms.TransformType.GUI)
transform.rotate((float) (Math.PI / 2), 1, 0, 0);
switch (slot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,29 @@ public float getPowerOutputAtRevs() {
* @return the power at this rev-range, from 0 to getPower().
*/
public float evaluateSpline(LinearSpline powerGraph, float range) {
int index = powerGraph.getControlPoints().size() - 1;
int size = powerGraph.getControlPoints().size();
if (size < 2) {
return size == 1 ? powerGraph.getControlPoints().get(0).y : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why this is necessary. The clamp you added after isn't sufficient?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added it to prevent an IndexOutOfBoundsException. If the graph is empty or only has 1 point, the size - 2 logic in the clamp below results in a negative index and crashes the game. I think this just bails out safely before any of that happens.

}

int index = size - 1;
Vector3f point = powerGraph.getControlPoints().get(index);

while (point.x >= range && index > 0) {
index -= 1;
point = powerGraph.getControlPoints().get(index);
}

// Clamp index so that index + 1 stays within bounds
if (index >= size - 1) {
index = size - 2;
}

float start = point.x;
float end = powerGraph.getControlPoints().get(index + 1).x;

float interp = map(range, start, end, 0, 1);
interp = DynamXMath.clamp(interp, 0, 1);

return powerGraph.interpolate(interp, index, null).y;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ protected void stepSimulationImpl(Profiler profiler, Semaphore syncThreadsLock)
//e.getNetwork().onPrePhysicsTick(profiler);
e.getSynchronizer().onPrePhysicsTick(profiler);
} catch (Exception ex) {
throw new PhysicsEntityException(e, "prePhysicsTick", ex);
DynamXMain.log.error("Exception during prePhysicsTick for entity " + e + ", killing entity to prevent tick loops", ex);
e.setDead();
}
QuaternionPool.closePool();
Vector3fPool.closePool();
Expand Down Expand Up @@ -202,7 +203,8 @@ protected void stepSimulationImpl(Profiler profiler, Semaphore syncThreadsLock)
try {
e.getSynchronizer().onPostPhysicsTick(profiler);
} catch (Exception ex) {
throw new PhysicsEntityException(e, "postPhysicsTick", ex);
DynamXMain.log.error("Exception during postPhysicsTick for entity " + e + ", killing entity to prevent tick loops", ex);
e.setDead();
}
QuaternionPool.closePool();
Vector3fPool.closePool();
Expand Down Expand Up @@ -275,4 +277,4 @@ public void clearAll() {
ClientDebugSystem.trackedRigidBodies.clear();
}
}
}
}