Skip to content

Commit

Permalink
Fix cannon shooting position
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Jul 12, 2024
1 parent 33e802e commit 7265e7c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.parzivail.pswg.Resources;
import com.parzivail.pswg.entity.ship.RZ1Awing;
import com.parzivail.util.entity.TrackedAnimationValue;
import com.parzivail.util.generics.Make;
import com.parzivail.util.math.Ease;
import com.parzivail.util.math.MathUtil;
import org.joml.Matrix4f;

import java.util.HashSet;
Expand All @@ -17,6 +20,18 @@ public class RigRZ1 extends ModelRig<RZ1Awing>
public static final String ENGINE_LEFT = "EngineLeft";
public static final String ENGINE_MIDDLE = "EngineMiddle";
public static final HashSet<String> ENGINES = Make.hashSet(ENGINE_LEFT, ENGINE_RIGHT, ENGINE_MIDDLE);
public static final String LEG_FRONT_TOP = "FrontLegTop";
public static final String LEG_RIGHT_TOP = "RightLegTop";
public static final String LEG_LEFT_TOP = "LeftLegTop";
public static final HashSet<String> LEG_TOP = Make.hashSet(LEG_FRONT_TOP, LEG_RIGHT_TOP, LEG_LEFT_TOP);
public static final String LEG_FRONT_MID = "FrontLegMid";
public static final String LEG_RIGHT_MID = "RightLegMid";
public static final String LEG_LEFT_MID = "LeftLegMid";
public static final HashSet<String> LEG_MID = Make.hashSet(LEG_FRONT_MID, LEG_RIGHT_MID, LEG_LEFT_MID);
public static final String LEG_FRONT_BOTTOM = "FrontLegBottom";
public static final String LEG_RIGHT_BOTTOM = "RightLegBottom";
public static final String LEG_LEFT_BOTTOM = "LeftLegBottom";
public static final HashSet<String> LEG_BOTTOM = Make.hashSet(LEG_FRONT_BOTTOM, LEG_RIGHT_BOTTOM, LEG_LEFT_BOTTOM, LEG_FRONT_MID, LEG_RIGHT_MID, LEG_LEFT_MID, LEG_FRONT_TOP, LEG_RIGHT_TOP, LEG_LEFT_TOP);

protected RigRZ1()
{
Expand All @@ -27,6 +42,27 @@ protected RigRZ1()
public Matrix4f getPartTransformation(RZ1Awing target, String part, float tickDelta)
{
Matrix4f matrix4f = new Matrix4f();
if (LEG_BOTTOM.contains(part))
{
var gearAnim = target.getGearAnim();
var gearTimer = TrackedAnimationValue.getTimer(gearAnim, target.prevGearAnim, tickDelta);

var timer = Ease.inOutCubic(Math.abs(gearTimer) / RZ1Awing.GEAR_ANIM_LENGTH);

if (TrackedAnimationValue.isPositiveDirection(gearAnim))
timer = 1 - timer;

var legAngle = 1 * timer;

switch (part)
{
case LEG_FRONT_MID, LEG_RIGHT_MID, LEG_LEFT_MID, LEG_FRONT_TOP, LEG_FRONT_BOTTOM, LEG_RIGHT_BOTTOM, LEG_LEFT_BOTTOM ->
matrix4f.rotateX(MathUtil.toRadians(-legAngle));
case LEG_LEFT_TOP, LEG_RIGHT_TOP -> matrix4f.rotateX(MathUtil.toRadians(legAngle));
default -> throw new IndexOutOfBoundsException();
}
}

return matrix4f;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.parzivail.pswg.entity.ship;

import com.parzivail.pswg.client.input.ShipControls;
import com.parzivail.pswg.container.SwgParticleTypes;
import com.parzivail.pswg.container.SwgSounds;
import com.parzivail.pswg.entity.rigs.RigRZ1;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class RZ1Awing extends ShipEntity implements IComplexEntityHitbox
private static final int CANNON_STATE_MASK = 0b00000001;
private static final String[] CANNON_ORDER = { RigRZ1.CANNON_LEFT, RigRZ1.CANNON_RIGHT };
private static final TrackedData<Byte> LANDING_GEAR_ANIM = DataTracker.registerData(RZ1Awing.class, TrackedDataHandlerRegistry.BYTE);
public static final int GEAR_ANIM_LENGTH = 30;
public byte prevGearAnim;

public RZ1Awing(EntityType<?> type, World world)
{
Expand All @@ -75,13 +78,16 @@ protected void initDataTracker()
{
super.initDataTracker();
getDataTracker().startTracking(CANNON_BITS, (byte)0);
getDataTracker().startTracking(LANDING_GEAR_ANIM, (byte)0);
}

@Override
protected void readCustomDataFromNbt(NbtCompound tag)
{
super.readCustomDataFromNbt(tag);

dataTracker.set(LANDING_GEAR_ANIM, tag.getByte("wingAnim"));

setCannonState(tag.getByte("cannonState"));
}

Expand All @@ -90,9 +96,16 @@ protected void writeCustomDataToNbt(NbtCompound tag)
{
super.writeCustomDataToNbt(tag);

tag.putByte("gearAnim", dataTracker.get(LANDING_GEAR_ANIM));

tag.putByte("cannonState", getCannonState());
}

public byte getGearAnim()
{
return dataTracker.get(LANDING_GEAR_ANIM);
}

@Override
protected float getEyeHeight(EntityPose pose, EntityDimensions dimensions)
{
Expand All @@ -104,7 +117,13 @@ public void tick()
{
super.tick();

if (getWorld().isClient)
if (!getWorld().isClient)
{
var controls = getControls();

tickControlledAnim(LANDING_GEAR_ANIM, (byte)GEAR_ANIM_LENGTH, controls.contains(ShipControls.SPECIAL1));
}
else
{
var stack = new Transform();

Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 7265e7c

Please sign in to comment.