Skip to content

Commit

Permalink
Moa movement changes
Browse files Browse the repository at this point in the history
Disabled AI for this one, will re-do, need to think for a bit lol
  • Loading branch information
MrXBlade committed Nov 3, 2024
1 parent 9c09e18 commit 5dbc62e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public enum MoaAttributes {
GROUND_SPEED(0.24F, 0.8F, 0.1F),
GLIDING_SPEED(0.07F, 0.25F, 0.03F),
GLIDING_DECAY(0.5F, 0.9F, 0.06F),
GLIDING_DECAY(0.5F, 0.8F, 0.06F),
JUMPING_STRENGTH(0.18F, 0.28F, 0.02F),
DROP_MULTIPLIER(1, 6, 1),
MAX_HEALTH(10, 40, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static DefaultAttributeContainer.Builder createMoaAttributes() {

@Override
protected void initGoals() {

/*
this.goalSelector.add(0, new MoaEscapeDangerGoal(this, 0.8));
this.goalSelector.add(1, new EatFromBowlGoal(0.4, 24, 16));
Expand Down Expand Up @@ -123,6 +123,8 @@ protected void initGoals() {
this.goalSelector.add(12, new SwimGoal(this));
this.goalSelector.add(12, new FollowParentGoal(this, 0.11D));
this.goalSelector.add(12, new FlyGoal(this, 0.1f));
*/


}

Expand Down Expand Up @@ -224,7 +226,7 @@ protected void dropInventory() {
public float getWingRoll() {

//Gliding flapping system
if (dataTracker.get(AIR_TICKS) >= 4) {
if (dataTracker.get(AIR_TICKS) >= 3) {
curWingRoll = MathHelper.sin(age / wingFlapSpeed) * 0.73F + 0.1F;
atWingBottom = false; // Reset peak for landing
} else {
Expand Down Expand Up @@ -308,10 +310,10 @@ public void attemptMoaSound()
}
} else {
if (isSaddled()) {
moaSoundCallCooldown = 120 + random.nextInt(80);
moaSoundCallCooldown = 150 + random.nextInt(150);
soundChance += getRandomFloat(0.04f, 0.13f);
} else {
moaSoundCallCooldown = 50 + random.nextInt(160);
moaSoundCallCooldown = 100 + random.nextInt(250);
soundChance += getRandomFloat(0.04f, 0.16f);
}
}
Expand Down Expand Up @@ -340,6 +342,7 @@ protected void playHurtSound(DamageSource source) {
@Override
public void tick() {
super.tick();
this.fall();

isInAir = !isOnGround();

Expand All @@ -364,12 +367,9 @@ public void tick() {
}

if (this.jumping) {
this.setVelocity(this.getVelocity().add(0.0D, 0.03D, 0.0D));
this.setVelocity(this.getVelocity().add(0.0D, 0.03D, 0.0D)); //Smooths it out
this.setVelocity(this.getVelocity().add(0.0D, 0.05D, 0.0D));
}

this.fall();

if (hasPassengers()) {
streamPassengersAndSelf().forEach(entity -> entity.fallDistance = 0);
}
Expand Down Expand Up @@ -470,6 +470,11 @@ protected void tickControlled(PlayerEntity controllingPlayer, Vec3d movementInpu
this.headYaw = this.bodyYaw;
var movement = getControlledMovementInput(controllingPlayer, movementInput);

final float groundAcceleration = 0.006F;
final float flyingAcceleration = 0.001F;
final float maxGroundSpeed = 0.5F;
final float maxFlyingSpeed = 0.7F;

if (this.jumpStrength > 0.0F && !this.isInAir && this.isOnGround()) {
double d = 0.1F * (double) this.jumpStrength * (double) this.getJumpVelocityMultiplier();
double h;
Expand All @@ -481,31 +486,42 @@ protected void tickControlled(PlayerEntity controllingPlayer, Vec3d movementInpu

Vec3d vec3d = this.getVelocity();
this.setVelocity(vec3d.x, h, vec3d.z);

/*
this.velocityDirty = true;
if (movement.z > 0.0F) {
float adjVel = jumpStrength / 2F;
float i = MathHelper.sin(this.getYaw() * 0.017453292F);
float j = MathHelper.cos(this.getYaw() * 0.017453292F);
float adjVel = 0.02f;
float i = MathHelper.sin(this.getYaw() * 0.01745F);
float j = MathHelper.cos(this.getYaw() * 0.01745F);
this.setVelocity(this.getVelocity().add(-0.4F * i * adjVel, 0.0D, 0.4F * j * adjVel));
}

*/
this.jumpStrength = 0.0F;
}

// Reset jump when grounded
if (jumpStrength <= 0.01F && isOnGround()) {
this.jumpStrength = 0.0F;
this.jumping = false;
isInAir = false;
}

// acceleration
if (this.isLogicalSideForUpdatingMovement()) {
this.setMovementSpeed(getMovementSpeed());
super.travel(new Vec3d(movement.x, movementInput.y, movement.z));
//this.rise();
float currentSpeed = 0;
if (!this.isGliding()) {
currentSpeed = getMovementSpeed();
currentSpeed = Math.min(currentSpeed + groundAcceleration, maxGroundSpeed);
} else {
currentSpeed = getMovementSpeed();
currentSpeed = Math.min(currentSpeed + flyingAcceleration, maxFlyingSpeed);
}
//System.out.println(currentSpeed);
this.setMovementSpeed(currentSpeed);
super.travel(new Vec3d(movement.x * currentSpeed, movementInput.y, movement.z * currentSpeed));
} else {
this.setVelocity(Vec3d.ZERO);
}

//System.out.println(getVelocity());
this.updateLimbs(false);
} else {
super.travel(movementInput);
Expand Down Expand Up @@ -547,7 +563,7 @@ public ActionResult interactMob(PlayerEntity player, Hand hand) {
}

var item = heldStack.getItem();
if (heldStack.isIn(ConventionalItemTags.RAW_MEATS_FOODS)) {
if (heldStack.isIn(ConventionalItemTags.RAW_MEAT_FOODS)) {
feedMob(heldStack);
return ActionResult.success(getWorld().isClient());
} else if (!hasChest() && item instanceof BlockItem blockItem && blockItem.getBlock() instanceof AbstractChestBlock) {
Expand Down Expand Up @@ -653,7 +669,15 @@ protected void playStepSound(BlockPos posIn, BlockState stateIn) {

public void fall() {
if (this.getVelocity().y < 0.0D && !this.isSneaking()) {
this.setVelocity(this.getVelocity().multiply(1.0D, isGliding() ? getGenes().getAttribute(MoaAttributes.GLIDING_DECAY) : 1D, 1.0D));
this.setVelocity(this.getVelocity().multiply(1D, isGliding() ? getGenes().getAttribute(MoaAttributes.GLIDING_DECAY) : 0.9D, 1.0D));
}
}

public void rise() {
if ((this.getVelocity().y > 0.005f && this.getVelocity().y < 1f)&& !this.isSneaking() && hasPassengers()) {
this.setVelocity(this.getVelocity().add(0, 0.15f, 0));
//This is janky, but makes moa fall less fast, has a bug that makes it infinite fly lol
//System.out.println(getVelocity().getY());
}
}

Expand Down Expand Up @@ -865,9 +889,8 @@ public void start() {
if (isOnGround()){
isInAir = false;
}
moaSoundCallCooldown = 20 + random.nextInt(350);
songChance = MathHelper.clamp(random.nextFloat(), 0f, 0.5f);

moaSoundCallCooldown = 150 + random.nextInt(350);
songChance = MathHelper.clamp(random.nextFloat(), 0f, 0.3f);

this.timer = 0;
super.start();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5dbc62e

Please sign in to comment.