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
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.paneedah.weaponlib.vehicle.jimphysics;
package com.paneedah.mwc.utils;

import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;

import static com.paneedah.mwc.proxies.ClientProxy.MC;

public class InterpolationKit {
public class InterpolationUtil {


public static Vec3d interpolatedEntityPosition(Entity en) {
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/com/paneedah/mwc/utils/MWCUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,6 @@ public static RayTraceResult rayTraceBlocks(final World world, final Vector3D st
*/
@SideOnly(Side.CLIENT)
public static Vec3d getInterpolatedPlayerPos() {
EntityPlayer player = MC.player;

final float renderPartialTicks = MC.getRenderPartialTicks();

final double interpolatedX = (player.posX - player.prevPosX) * renderPartialTicks + player.prevPosX;
final double interpolatedY = (player.posY - player.prevPosY) * renderPartialTicks + player.prevPosY;
final double interpolatedZ = (player.posZ - player.prevPosZ) * renderPartialTicks + player.prevPosZ;

return new Vec3d(interpolatedX, interpolatedY, interpolatedZ);
return InterpolationUtil.interpolatedEntityPosition(MC.player);
}
}
19 changes: 3 additions & 16 deletions src/main/java/com/paneedah/weaponlib/AsyncWeaponState.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.paneedah.weaponlib;

import lombok.Getter;

@Getter
public class AsyncWeaponState {

private final WeaponState state;
Expand All @@ -20,20 +23,4 @@ public AsyncWeaponState(WeaponState state, long timestamp, long duration) {
this.duration = duration;
}

public WeaponState getState() {
return state;
}

public long getTimestamp() {
return timestamp;
}

public long getDuration() {
return duration;
}

public boolean isInfinite() {
return isInfinite;
}

}
42 changes: 15 additions & 27 deletions src/main/java/com/paneedah/weaponlib/EntityBounceable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.paneedah.mwc.ProjectConstants;
import com.paneedah.mwc.utils.MWCUtil;
import com.paneedah.mwc.utils.VectorUtil;
import dev.redstudio.redcore.math.vectors.Vector3F;
import io.netty.buffer.ByteBuf;
import dev.redstudio.redcore.math.vectors.Vector3D;
import net.jafama.FastMath;
Expand Down Expand Up @@ -43,15 +44,11 @@

private float initialYaw;
private float initialPitch;
private float xRotation;
private float yRotation;
private float zRotation;
private float xRotationChange;
private float yRotationChange;
private float zRotationChange;
private final Vector3F ROTATION = new Vector3F();
private final Vector3F ROTATION_CHANGE = new Vector3F();

private float rotationSlowdownFactor = 0.99f;
private final float maxRotationChange = 20f;
private final float MAX_ROTATION_CHANGE = 20f;

protected boolean stopped;

Expand Down Expand Up @@ -111,9 +108,9 @@
}

private void setRotations() {
xRotationChange = maxRotationChange * (float) rand.nextGaussian();
yRotationChange = maxRotationChange * (float) rand.nextGaussian();
zRotationChange = maxRotationChange * (float) rand.nextGaussian();
ROTATION_CHANGE.x = MAX_ROTATION_CHANGE * (float) rand.nextGaussian();
ROTATION_CHANGE.y = MAX_ROTATION_CHANGE * (float) rand.nextGaussian();
ROTATION_CHANGE.z = MAX_ROTATION_CHANGE * (float) rand.nextGaussian();
}

@Override
Expand All @@ -134,189 +131,180 @@
return;
}

xRotation += xRotationChange;
yRotation += yRotationChange;
zRotation += zRotationChange;
ROTATION.add(ROTATION_CHANGE);

xRotationChange *= rotationSlowdownFactor;
yRotationChange *= rotationSlowdownFactor;
zRotationChange *= rotationSlowdownFactor;
ROTATION_CHANGE.multiply(rotationSlowdownFactor);

this.lastTickPosX = this.posX;
this.lastTickPosY = this.posY;
this.lastTickPosZ = this.posZ;
super.onUpdate();

++this.ticksInAir;

if (stopped) {
return;
}

Vec3d vec3 = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vec31 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

RayTraceResult movingobjectposition = MWCUtil.rayTraceBlocks(world, VectorUtil.convertToVector3D(vec3), VectorUtil.convertToVector3D(vec31), (block, blockMetadata) -> canCollideWithBlock(block, blockMetadata));

vec3 = new Vec3d(this.posX, this.posY, this.posZ);
vec31 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

if (movingobjectposition != null) {
vec31 = new Vec3d(movingobjectposition.hitVec.x, movingobjectposition.hitVec.y, movingobjectposition.hitVec.z);
}

if (thrower != null) { //if(!this.worldObj.isRemote)
Entity entity = null;
List<?> list = world.getEntitiesWithinAABBExcludingEntity(entity, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D)); // compatibility.getEntitiesWithinAABBExcludingEntity(world, this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;
EntityLivingBase entitylivingbase = this.getThrower();

RayTraceResult entityMovingObjectPosition = null;
for (int j = 0; j < list.size(); ++j) {
Entity entity1 = (Entity) list.get(j);
for (Object o : list) {
Entity entity1 = (Entity) o;

if (entity1.canBeCollidedWith() && (entity1 != entitylivingbase || this.ticksInAir >= 5)) {
float f = 0.3F;
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand(f, f, f);
RayTraceResult movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);

if (movingobjectposition1 != null) {
double d1 = vec3.distanceTo(movingobjectposition1.hitVec); //hitVec

if (d1 < d0 || d0 == 0.0D) {
entity = entity1;
entityMovingObjectPosition = movingobjectposition1;
d0 = d1;
}
}
}
}

if (entity != null) {
movingobjectposition = new RayTraceResult(entity);
movingobjectposition.sideHit = entityMovingObjectPosition.sideHit;
movingobjectposition.hitVec = entityMovingObjectPosition.hitVec;
}
}

ProjectConstants.LOGGER.trace("Ori position to {}, {}, {}, motion {} {} {} ", this.posX, this.posY, this.posZ,
motionX, motionY, motionZ);

if (movingobjectposition != null && (movingobjectposition.typeOfHit == RayTraceResult.Type.BLOCK || (movingobjectposition.typeOfHit == RayTraceResult.Type.ENTITY))) {

//TODO: remove logging since it's creating wrapper objects
ProjectConstants.LOGGER.trace("Hit {}, vec set to {}, {}, {}", movingobjectposition.typeOfHit,
movingobjectposition.hitVec.x,
movingobjectposition.hitVec.y,
movingobjectposition.hitVec.z);

ProjectConstants.LOGGER.trace("Before bouncing {}, side {}, motion set to {}, {}, {}", bounceCount,
movingobjectposition.sideHit,
motionX, motionY, motionZ);

this.posX = movingobjectposition.hitVec.x;
this.posY = movingobjectposition.hitVec.y;
this.posZ = movingobjectposition.hitVec.z;

switch (movingobjectposition.sideHit) {
case DOWN:
this.motionY = -this.motionY;
this.posY += motionY;
break;
case UP:
this.motionY = -this.motionY;
// if(this.motionY - gravityVelocity < 0.05) {
// log.debug("Force stopping entity");
// gravityVelocity = (float) this.motionY;
// forcedStop = true;
// }
break;
case NORTH:
this.motionZ = -this.motionZ;
this.posZ += motionZ;
break;
case SOUTH:
this.motionZ = -this.motionZ;
break;
case WEST:
this.motionX = -this.motionX;
this.posX += motionX;
break;
case EAST:
this.motionX = -this.motionX;
break;
}

setPosition(posX, posY, posZ);
if (movingobjectposition.typeOfHit == RayTraceResult.Type.ENTITY) {
avoidEntityCollisionAfterBounce(movingobjectposition);
} else if (movingobjectposition.typeOfHit == RayTraceResult.Type.BLOCK) {
avoidBlockCollisionAfterBounce(movingobjectposition);
}

ProjectConstants.LOGGER.trace("After bouncing {} motion set to {}, {}, {}", bounceCount, motionX, motionY, motionZ);
onBounce(movingobjectposition);
bounceCount++;
if (this.isDead) {
return;
}
} else {
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
}

setPosition(this.posX, this.posY, this.posZ);

float motionSquared = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);

this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);

for (this.rotationPitch = (float) (Math.atan2(this.motionY, motionSquared) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
}

while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
this.prevRotationPitch += 360.0F;
}

while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
this.prevRotationYaw -= 360.0F;
}

while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
this.prevRotationYaw += 360.0F;
}

this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
float f2 = 0.99F;
float currentGravityVelocity = this.getGravityVelocity();

if (this.isInWater()) {
for (int i = 0; i < 4; ++i) {
float f4 = 0.25F;
EnumParticleTypes particleType = EnumParticleTypes.getByName("bubble");
if (particleType != null) {
world.spawnParticle(particleType, this.posX - this.motionX * (double) f4, this.posY - this.motionY * (double) f4, this.posZ - this.motionZ * (double) f4, this.motionX, this.motionY, this.motionZ);
}
}

f2 = 0.8F;
}

if (movingobjectposition != null &&
(movingobjectposition.typeOfHit == RayTraceResult.Type.BLOCK || movingobjectposition.typeOfHit == RayTraceResult.Type.ENTITY)) {
f2 = slowdownFactor;
rotationSlowdownFactor = rotationSlowdownFactor * (slowdownFactor * 1.5f);
}

this.motionX *= f2;
this.motionY *= f2;
this.motionZ *= f2;

recordVelocityHistory();

if (!velocityHistory.stream().anyMatch(v -> v > STOP_THRESHOLD)) {
if (velocityHistory.stream().noneMatch(v -> v > STOP_THRESHOLD)) {

Check notice on line 307 in src/main/java/com/paneedah/weaponlib/EntityBounceable.java

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (next)

โœ… Getting better: Complex Method

onUpdate decreases in cyclomatic complexity from 38 to 37, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
motionX = motionY = motionZ = 0.0;
stopped = true;
ProjectConstants.LOGGER.trace("Stopping {}", this);
Expand Down Expand Up @@ -475,15 +463,15 @@
}

public float getXRotation() {
return xRotation;
return ROTATION.x;
}

public float getYRotation() {
return yRotation - initialYaw - 90f;
return ROTATION.y - initialYaw - 90f;
}

public float getZRotation() {
return zRotation;
return ROTATION.z;
}

public boolean canCollideWithBlock(Block block, IBlockState iBlockState) {
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/paneedah/weaponlib/MiscUtils.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
package com.paneedah.weaponlib;

public class MiscUtils {
import dev.redstudio.redcore.math.ClampUtil;

public class MiscUtils {

/**
* Cubic Hermite
*/
public static float smoothstep(float edge0, float edge1, float x) {
x = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
x = ClampUtil.clampMinFirst((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
return x * x * (3 - 2 * x);
}

/**
* @deprecated Use {@link dev.redstudio.redcore.math.ClampUtil} instead.
*/
@Deprecated
public static float clamp(float x, float lowerlimit, float upperlimit) {
if (x < lowerlimit) {
x = lowerlimit;
}
if (x > upperlimit) {
x = upperlimit;
}
return x;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.paneedah.weaponlib.animation.load;

import com.paneedah.weaponlib.vehicle.jimphysics.InterpolationKit;
import com.paneedah.mwc.utils.InterpolationUtil;
import lombok.NoArgsConstructor;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.opengl.GL11;

import java.util.LinkedList;

Expand Down Expand Up @@ -33,13 +32,13 @@ public class BasicStateAnimator {

public Vec3d getInterpolatedRotation() {
double mu = MC.getRenderPartialTicks();
return InterpolationKit.interpolateVector(prevRot, currentRot, mu);
return InterpolationUtil.interpolateVector(prevRot, currentRot, mu);

}

public Vec3d getInterpolatedPosition() {
double mu = MC.getRenderPartialTicks();
return InterpolationKit.interpolateVector(previousPosition, currentPosition, mu);
return InterpolationUtil.interpolateVector(previousPosition, currentPosition, mu);
}

public void applyGLTransforms() {
Expand Down Expand Up @@ -97,8 +96,8 @@ public void tick() {
} else {
double mu = time / goingTransition.time;

currentPosition = InterpolationKit.interpolateVector(currentTransition.pos, goingTransition.pos, mu);
currentRot = InterpolationKit.interpolateVector(currentTransition.rot, goingTransition.rot, mu);
currentPosition = InterpolationUtil.interpolateVector(currentTransition.pos, goingTransition.pos, mu);
currentRot = InterpolationUtil.interpolateVector(currentTransition.rot, goingTransition.rot, mu);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.paneedah.weaponlib.crafting.ammopress;

import com.paneedah.weaponlib.crafting.base.TESRStation;
import com.paneedah.weaponlib.vehicle.jimphysics.InterpolationKit;
import com.paneedah.mwc.utils.InterpolationUtil;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

import static com.paneedah.mwc.proxies.ClientProxy.MC;

Expand Down Expand Up @@ -73,7 +72,7 @@ public void render(TileEntityAmmoPress te, double x, double y, double z, float p
GlStateManager.scale(MODEL_RESCALE_VALUE, MODEL_RESCALE_VALUE, MODEL_RESCALE_VALUE);

// Render the actual model
double interp = InterpolationKit.interpolateValue(te.getPreviousWheelRotation(), te.getCurrentWheelRotation(), MC.getRenderPartialTicks());
double interp = InterpolationUtil.interpolateValue(te.getPreviousWheelRotation(), te.getCurrentWheelRotation(), MC.getRenderPartialTicks());
model.render(null, (float) interp, 0f, 0f, 0f, 0f, MODEL_RENDER_SCALE);

// Undo block state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.paneedah.weaponlib.crafting.workbench.GUIButtonCustom;
import com.paneedah.weaponlib.render.gui.GUIRenderHelper;
import com.paneedah.weaponlib.render.gui.GUIRenderHelper.StringAlignment;
import com.paneedah.weaponlib.vehicle.jimphysics.InterpolationKit;
import com.paneedah.mwc.utils.InterpolationUtil;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.gui.GuiButton;
Expand Down Expand Up @@ -488,7 +488,7 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
continue;
}

final double progress = InterpolationKit.interpolateValue(tileEntity.previousDismantleStatus[i], tileEntity.dismantleStatus[i], MC.getRenderPartialTicks()) / (double) tileEntity.dismantleDuration[i];
final double progress = InterpolationUtil.interpolateValue(tileEntity.previousDismantleStatus[i], tileEntity.dismantleStatus[i], MC.getRenderPartialTicks()) / (double) tileEntity.dismantleDuration[i];
drawModalRectWithCustomSizedTexture(this.guiLeft + 261 + i * 31, this.guiTop + 57, 81, 232, 29, 7, 480, 370);
drawModalRectWithCustomSizedTexture(this.guiLeft + 261 + i * 31, this.guiTop + 57, 81, 239, (int) (29 * progress), 7, 480, 370);
}
Expand All @@ -513,7 +513,7 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
// forty notches, therefore 1/40.0 = 0.025
final double prevProgress = (Math.max(tileEntity.prevCraftingTimer, 0)) / (double) tileEntity.craftingDuration;
final double currProgress = (Math.max(tileEntity.craftingTimer, 0)) / (double) tileEntity.craftingDuration;
final double intpProgress = InterpolationKit.interpolateValue(prevProgress, currProgress, MC.getRenderPartialTicks());
final double intpProgress = InterpolationUtil.interpolateValue(prevProgress, currProgress, MC.getRenderPartialTicks());
final double progress = (0.025) * (Math.round(intpProgress / (0.025)));

drawModalRectWithCustomSizedTexture(this.guiLeft + 304, this.guiTop + 185, 53f, 240f, 81, 11, 480, 370);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ private static void set(ModelBase key, ModelBase lock, ResourceLocation keyT, Re
VehicleCustomGUI.setLockAndKeyModels(key, lock, keyT, lockT);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.paneedah.weaponlib.particle.vehicle.VehicleExhaustFlameParticle;
import com.paneedah.weaponlib.state.ExtendedState;
import com.paneedah.weaponlib.vehicle.collisions.*;
import com.paneedah.weaponlib.vehicle.jimphysics.InterpolationKit;
import com.paneedah.mwc.utils.InterpolationUtil;
import com.paneedah.weaponlib.vehicle.jimphysics.Transmission;
import com.paneedah.weaponlib.vehicle.jimphysics.solver.VehiclePhysicsSolver;
import com.paneedah.weaponlib.vehicle.jimphysics.solver.WheelSolver;
Expand Down Expand Up @@ -266,7 +266,7 @@ public OreintedBB getOreintedBoundingBox() {
}

public float getInterpolatedWheelRotation() {
return (float) InterpolationKit.interpolateValue(prevWheelRotationAngle, wheelRotationAngle,
return (float) InterpolationUtil.interpolateValue(prevWheelRotationAngle, wheelRotationAngle,
MC.getRenderPartialTicks());
}

Expand All @@ -275,7 +275,7 @@ public float getWheelRotationAngle() {
}

public float getInterpolatedYawDelta() {
return (float) InterpolationKit.interpolateValue(prevLastYawDelta, lastYawDelta,
return (float) InterpolationUtil.interpolateValue(prevLastYawDelta, lastYawDelta,
MC.getRenderPartialTicks());
}

Expand Down Expand Up @@ -1472,7 +1472,7 @@ public void move(MoverType type, double x, double y, double z) {
}

public float getInterpolatedLiftOffset() {
return (float) InterpolationKit.interpolateValue(prevLiftOffset, liftOffset,
return (float) InterpolationUtil.interpolateValue(prevLiftOffset, liftOffset,
MC.getRenderPartialTicks());
}

Expand Down
Loading