Skip to content

Commit

Permalink
Merge pull request #17 from fleefie/log-and-adjustable-scaling
Browse files Browse the repository at this point in the history
Adjustable scaling, and experimental logarithmic scaling.
  • Loading branch information
IoIxD authored May 21, 2024
2 parents b72f645 + 00970ff commit 777ddf7
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 37 deletions.
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
rm build/libs/cobblemounts-*.jar
./gradlew build
cp build/libs/cobblemounts-*.jar /home/gavin/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/instances/1.20.1/.minecraft/mods/
93 changes: 76 additions & 17 deletions src/main/java/net/ioixd/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@

public class Config implements FabricPacket {

public boolean cappedSpeed = true;
public double speedCap = 0.15;
public double flyingSpeedCap = 0.15;
public double legendaryModifier = 0.05;
public boolean groundCappedSpeed = true;
public boolean groundUseLogScaling = true;
public double groundSpeedScalar = 150.0d;
public double groundSpeedCap = 3.0d;

public boolean flightCappedSpeed = true;
public boolean flightUseLogScaling = true;
public double flightSpeedScalar = 300.0d;
public double flightSpeedCap = 2.0d;

public boolean swimCappedSpeed = true;
public boolean swimUseLogScaling = true;
public double swimSpeedScalar = 75.0d;
public double swimSpeedCap = 4.0d;

public double legendaryModifier = 0.5d;
public boolean legendaryModifierCapBreak = true;

public boolean allowFlying = true;
public boolean allowSwimming = true;
Expand All @@ -29,10 +42,25 @@ public class Config implements FabricPacket {

@Override
public void write(PacketByteBuf p) {
p.writeBoolean(cappedSpeed);
p.writeDouble(speedCap);

p.writeBoolean(groundCappedSpeed);
p.writeBoolean(groundUseLogScaling);
p.writeDouble(groundSpeedScalar);
p.writeDouble(groundSpeedCap);

p.writeBoolean(flightCappedSpeed);
p.writeBoolean(flightUseLogScaling);
p.writeDouble(flightSpeedScalar);
p.writeDouble(flightSpeedCap);

p.writeBoolean(swimCappedSpeed);
p.writeBoolean(swimUseLogScaling);
p.writeDouble(swimSpeedScalar);
p.writeDouble(swimSpeedCap);

p.writeDouble(legendaryModifier);
p.writeDouble(flyingSpeedCap);
p.writeBoolean(legendaryModifierCapBreak);

p.writeBoolean(allowFlying);
p.writeBoolean(allowSwimming);
p.writeEnumConstant(listUse);
Expand Down Expand Up @@ -109,12 +137,27 @@ public void update() throws Exception {
throw new RuntimeException(ex);
}

this.cappedSpeed = toml.getBoolean("cappedSpeed", true);
this.speedCap = toml.getDouble("speedCap", 0.15);
this.legendaryModifier = toml.getDouble("legenedaryModifier", 0.05);
this.flyingSpeedCap = toml.getDouble("flyingSpeedCap", 0.15);
this.allowFlying = toml.getBoolean("allowFlying", true);
this.allowSwimming = toml.getBoolean("allowSwimming", true);
this.groundCappedSpeed = toml.getBoolean("groundCappedSpeed", true);
this.groundUseLogScaling = toml.getBoolean("groundUseLogScaling", false);
this.groundSpeedScalar = toml.getDouble("groundSpeedScalar", 150.0d);
this.groundSpeedCap = toml.getDouble("groundSpeedCap", 3.0d);

this.flightCappedSpeed = toml.getBoolean("flightCappedSpeed", true);
this.flightUseLogScaling = toml.getBoolean("flightUseLogScaling", true);
this.flightSpeedScalar = toml.getDouble("flightSpeedScalar", 300.0d);
this.flightSpeedCap = toml.getDouble("flightSpeedCap", 2.0d);

this.swimCappedSpeed = toml.getBoolean("swimCappedSpeed", true);
this.swimUseLogScaling = toml.getBoolean("swimUseLogScaling", true);
this.swimSpeedScalar = toml.getDouble("swimSpeedScalar", 75.0d);
this.swimSpeedCap = toml.getDouble("swimSpeedCap", 4.0d);

this.legendaryModifier = toml.getDouble("legenedaryModifier", 0.5d);
this.legendaryModifierCapBreak = toml.getBoolean("legenedaryModifierCapBreak", true);

this.allowFlying = true;
this.allowSwimming = true;

String listUse = toml.getString("listUse", "").toLowerCase();
switch (listUse) {
case "blacklist":
Expand All @@ -137,12 +180,28 @@ public void update() throws Exception {

public static Config read(PacketByteBuf p) {
var config = new Config();
config.cappedSpeed = p.readBoolean();
config.speedCap = p.readDouble();
config.legendaryModifier = p.readDouble();
config.flyingSpeedCap = p.readDouble();

config.groundCappedSpeed = p.readBoolean();
config.groundUseLogScaling = p.readBoolean();
config.groundSpeedScalar = p.readDouble();
config.groundSpeedCap = p.readDouble();

config.flightCappedSpeed = p.readBoolean();
config.flightUseLogScaling = p.readBoolean();
config.flightSpeedScalar = p.readDouble();
config.flightSpeedCap = p.readDouble();

config.swimCappedSpeed = p.readBoolean();
config.swimUseLogScaling = p.readBoolean();
config.swimSpeedScalar = p.readDouble();
config.swimSpeedCap = p.readDouble();

config.swimSpeedCap = p.readDouble();
config.legendaryModifierCapBreak = p.readBoolean();

config.allowFlying = p.readBoolean();
config.allowSwimming = p.readBoolean();

config.listUse = p.readEnumConstant(ListUse.class);
int s = p.readInt();
config.list = new ArrayList<>(s);
Expand Down
98 changes: 90 additions & 8 deletions src/main/java/net/ioixd/client/mixin/PokemonMovementHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ protected void tickControlled(PlayerEntity player, Vec3d movement) {
Block water = pokemon.getBlockStateAtPos().getBlock();
boolean inLiquid = water instanceof FluidBlock;

float speedModifier = pokemonData.isLegendary() ? 0.0f
: (float) CobblemountsClient.SYNCED_CONFIG.legendaryModifier;

AtomicBoolean isFlying = new AtomicBoolean(false);
Vec3d moveXZ = movement;// movement.rotateY((float) Math.toRadians(-player.getYaw()));
Vec3d forward = player.getRotationVector().normalize().multiply(movement.z);
Expand Down Expand Up @@ -99,14 +98,97 @@ protected void tickControlled(PlayerEntity player, Vec3d movement) {
flying = false;
break;
}
;

if (condition) {
// Let the spaghetti begin. Now may be time to say that I have NEVER coded Java before :s
// First, decide between swimming or flying scalars
float speedScalar = (float) CobblemountsClient.SYNCED_CONFIG.swimSpeedScalar;
float speedCap = (float) CobblemountsClient.SYNCED_CONFIG.swimSpeedCap;
boolean isSpeedCapped = CobblemountsClient.SYNCED_CONFIG.swimCappedSpeed;
boolean useLogScaling = CobblemountsClient.SYNCED_CONFIG.swimUseLogScaling;

if (flying) {
speedScalar = (float) CobblemountsClient.SYNCED_CONFIG.flightSpeedScalar;
speedCap = (float) CobblemountsClient.SYNCED_CONFIG.flightSpeedCap;
isSpeedCapped = CobblemountsClient.SYNCED_CONFIG.flightCappedSpeed;
useLogScaling = CobblemountsClient.SYNCED_CONFIG.flightUseLogScaling;
}
// Then, do some additional checks for legendaries
float legendaryModifier = pokemonData.isLegendary() ? 0.0f
: (float) CobblemountsClient.SYNCED_CONFIG.legendaryModifier;
boolean isLegendary = pokemonData.isLegendary();

// Fun fact, in a previous itteration, I repeated this code twice with a check to see if we
// were opperating in swim mode or flight mode. I need coffee.
// elifelifelifelifelifelifelifelifelifelifelif...
float flyingSpeed = 0.0f;
if (flyMove.z != 0.0) {
double flyingSpeed = ((pokemonData.getSpeed() / 64.0f) + speedModifier) * 8.0;
if (CobblemountsClient.SYNCED_CONFIG.cappedSpeed) {
if (flyingSpeed >= CobblemountsClient.SYNCED_CONFIG.flyingSpeedCap) {
flyingSpeed = CobblemountsClient.SYNCED_CONFIG.flyingSpeedCap;
// Step 1 : check if using log or lin scaling
if (!useLogScaling) {
// Step 2 : compute the base flight speed
flyingSpeed = ((pokemonData.getSpeed() / 256.0f) * (speedScalar / 2.0f));
// Step 3 : check if the cobblemon is legendary
if (isLegendary) {
// Step 3.1 : check if speed cap is applied
if (isSpeedCapped) {
// Step 3.2 : check if speed cap breaking is allowed
if (CobblemountsClient.SYNCED_CONFIG.legendaryModifierCapBreak) {
// Step 3.3 : compute final speed based on broken cap
if (flyingSpeed >= speedCap) {
flyingSpeed = (speedCap + ((legendaryModifier * speedScalar) / 2.0f));
} else {
flyingSpeed = (flyingSpeed + ((legendaryModifier * speedScalar) / 2.0f));
}
} else {
flyingSpeed = (flyingSpeed + ((legendaryModifier * speedScalar) / 2.0f));
if (flyingSpeed >= speedCap) {
flyingSpeed = speedCap;
}
}
} else {
flyingSpeed = (flyingSpeed + ((legendaryModifier * speedScalar) / 2.0f));
}
} else {
// If the cobblemon isn't legendary, at least there's no cap-breaking shenanigans.
if (isSpeedCapped) {
if (flyingSpeed >= speedCap) {
flyingSpeed = speedCap;
}
}
}
} else {
// We're not done yet ! We still need to do the SAME EXACT THING but for LOGARITHMIC SCALING !!!!!!
// Step 2
flyingSpeed = 2.5f * (float)Math.log((pokemonData.getSpeed() + speedScalar) / speedScalar);
// Step 3
if (isLegendary) {
// Step 3.1
if (isSpeedCapped) {
// Step 3.2
if (CobblemountsClient.SYNCED_CONFIG.legendaryModifierCapBreak) {
// Step 3.3
if (flyingSpeed >= speedCap) {
flyingSpeed = (speedCap + legendaryModifier);
} else {
flyingSpeed = (flyingSpeed + legendaryModifier);
}
} else {
flyingSpeed = (flyingSpeed + legendaryModifier);
if (flyingSpeed >= speedCap) {
flyingSpeed = speedCap;
}
}
} else {
flyingSpeed = (flyingSpeed + legendaryModifier);
}
} else {
if (isSpeedCapped) {
if (flyingSpeed >= speedCap) {
flyingSpeed = speedCap;
}
}
}

}
pokemon.move(MovementType.SELF, flyMove.multiply(flyingSpeed));
isFlying.set(true);
Expand All @@ -119,7 +201,7 @@ protected void tickControlled(PlayerEntity player, Vec3d movement) {
pokemon.setPose(EntityPose.STANDING);
}
break;
}
}
});
if (!isFlying.get()) {
if (!(player instanceof ServerPlayerEntity) && MinecraftClient.getInstance().options.jumpKey.isPressed()
Expand Down
68 changes: 62 additions & 6 deletions src/main/java/net/ioixd/client/mixin/PokemonUpdateTick.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,71 @@ private void tickMovement(Vec3d movement, CallbackInfo info) {
Pokemon pokemonData = pokemonEntity.getPokemon();
Entity firstPassenger = pokemonEntity.getFirstPassenger();
if (firstPassenger instanceof PlayerEntity player) {

// Make the Pokemon's position match the player's and set their position
// accordingly.
float speedModifier = pokemonData.isLegendary() ? 0.0f
: (float) CobblemountsClient.SYNCED_CONFIG.legendaryModifier;
float movementSpeed = player.getMovementSpeed() * (pokemonData.getSpeed() / 12.0f) + speedModifier;
if (CobblemountsClient.SYNCED_CONFIG.cappedSpeed) {
if (movementSpeed >= CobblemountsClient.SYNCED_CONFIG.speedCap) {
movementSpeed = (float) CobblemountsClient.SYNCED_CONFIG.speedCap;
float legendaryModifier = pokemonData.isLegendary() ? 0.0f
: (float) CobblemountsClient.SYNCED_CONFIG.legendaryModifier;
boolean isLegendary = pokemonData.isLegendary();
//float movementSpeed = player.getMovementSpeed() * (pokemonData.getSpeed() / 12.0f) + speedModifier;
float speedScalar = (float) CobblemountsClient.SYNCED_CONFIG.groundSpeedScalar;
float speedCap = (float) CobblemountsClient.SYNCED_CONFIG.groundSpeedCap;
boolean isSpeedCapped = CobblemountsClient.SYNCED_CONFIG.groundCappedSpeed;
boolean useLogScaling = CobblemountsClient.SYNCED_CONFIG.groundUseLogScaling;
float movementSpeed = 0.0f;
if (!useLogScaling) {
movementSpeed = player.getMovementSpeed() * ((pokemonData.getSpeed() / 12.0f) * (speedScalar / 2.0f));
if (isLegendary) {
if (isSpeedCapped) {
if (CobblemountsClient.SYNCED_CONFIG.legendaryModifierCapBreak) {
if (movementSpeed >= speedCap) {
movementSpeed = (speedCap + ((legendaryModifier * speedScalar) / 2.0f));
} else {
movementSpeed = (movementSpeed + ((legendaryModifier * speedScalar) / 2.0f));
}
} else {
movementSpeed = (movementSpeed + ((legendaryModifier * speedScalar) / 2.0f));
if (movementSpeed >= speedCap) {
movementSpeed = speedCap;
}
}
} else {
movementSpeed = (movementSpeed + ((legendaryModifier * speedScalar) / 2.0f));
}
} else {
if (isSpeedCapped) {
if (movementSpeed >= speedCap) {
movementSpeed = speedCap;
}
}
}
} else {
movementSpeed = (player.getMovementSpeed() * 10.0f * (2.5f*(float)Math.log((pokemonData.getSpeed() + speedScalar) / speedScalar)));
if (isLegendary) {
if (isSpeedCapped) {
if (CobblemountsClient.SYNCED_CONFIG.legendaryModifierCapBreak) {
if (movementSpeed >= speedCap) {
movementSpeed = (speedCap + legendaryModifier);
} else {
movementSpeed = (movementSpeed + legendaryModifier);
}
} else {
movementSpeed = (movementSpeed + legendaryModifier);
if (movementSpeed >= speedCap) {
movementSpeed = speedCap;
}
}
} else {
movementSpeed = (movementSpeed + legendaryModifier);
}
} else {
if (isSpeedCapped) {
if (movementSpeed >= speedCap) {
movementSpeed = speedCap;
}
}
}

}
pokemonEntity.limbAnimator.setSpeed(pokemonEntity.getMovementSpeed() / 1.3f);

Expand Down
Loading

0 comments on commit 777ddf7

Please sign in to comment.