Skip to content

Commit

Permalink
add 1.21.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Nov 21, 2024
1 parent 9922be2 commit 63d0cd4
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dependencies {
implementation(libs.mixinextras.forge)
} else
"neoForge"("net.neoforged:neoforge:${property("vers.deps.fml")}")
modImplementation("dev.nyon:KotlinLangForge:1.0.3-k${libs.versions.kotlin.orNull}-$mcVersion+${loader.name.lowercase()}")
modImplementation("dev.nyon:KotlinLangForge:1.2.0-k${libs.versions.kotlin.orNull}-$mcVersion+${loader.name.lowercase()}")
}

modImplementation(libs.konfig)
Expand Down
4 changes: 2 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- fix mod metadata resource insertion
- make yacl optional from now on
- require yacl again
- add support for 1.21.3
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
kotlin = "2.0.21"
mod-publish = "0.5.+"
architectury-loom = "1.7-SNAPSHOT"
fabric-loader = "0.16.7"
fabric-loader = "0.16.9"
fabric-language-kotlin = "1.12.3+kotlin."
vineflower = "1.10.1"
konfig = "2.0.2-1.20.4"
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extensions.configure<StonecutterSettings> {
vers("1.20.6-fabric", "1.20.6")
vers("1.21-neoforge", "1.21")
vers("1.21-fabric", "1.21")
vers("1.21.3-neoforge", "1.21.3")
vers("1.21.3-fabric", "1.21.3")
vcsVersion = "1.21-fabric"
}
create(rootProject)
Expand Down
153 changes: 153 additions & 0 deletions src/main/java/dev/nyon/bbm/asm/AbstractBoatMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package dev.nyon.bbm.asm;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import dev.nyon.bbm.BbmBoat;
import dev.nyon.bbm.config.Config;
import dev.nyon.bbm.config.ConfigKt;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
//? if >=1.21.3
/*import net.minecraft.world.entity.vehicle.AbstractBoat;*/
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("AddedMixinMembersNamePattern")
@Pseudo
@Mixin(targets = "net.minecraft.world.entity.vehicle.AbstractBoat")
public class AbstractBoatMixin implements BbmBoat {

@Unique
private boolean jumpCollision = false;

@Override
public void setJumpCollision(boolean b) {
jumpCollision = b;
}

@Override
public boolean getJumpCollision() {
return jumpCollision;
}

/*? if >=1.21.3 {*/
/*@Shadow
private AbstractBoat.Status status;
@Unique
private AbstractBoat instance = (AbstractBoat) (Object) this;
@SuppressWarnings("resource")
@Unique
private List<BlockState> getCarryingBlocks() {
List<BlockState> states = new ArrayList<>();
AABB aABB = this.instance.getBoundingBox();
AABB aABB2 = new AABB(aABB.minX, aABB.minY - 0.001, aABB.minZ, aABB.maxX, aABB.minY, aABB.maxZ);
int i = Mth.floor(aABB2.minX) - 1;
int j = Mth.ceil(aABB2.maxX) + 1;
int k = Mth.floor(aABB2.minY) - 1;
int l = Mth.ceil(aABB2.maxY) + 1;
int m = Mth.floor(aABB2.minZ) - 1;
int n = Mth.ceil(aABB2.maxZ) + 1;
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (int p = i; p < j; p++) {
for (int q = m; q < n; q++) {
int r = (p != i && p != j - 1 ? 0 : 1) + (q != m && q != n - 1 ? 0 : 1);
if (r != 2) {
for (int s = k; s < l; s++) {
if (r <= 0 || s != k && s != l - 1) {
mutableBlockPos.set(p, s, q);
BlockState blockState = instance.level().getBlockState(mutableBlockPos);
states.add(blockState);
}
}
}
}
}
return states;
}
@ModifyExpressionValue(
method = "floatBoat",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/vehicle/AbstractBoat;getDeltaMovement()Lnet/minecraft/world/phys/Vec3;",
ordinal = 1
)
)
private Vec3 changeMovement(Vec3 original) {
if (failsPlayerCondition()) return original;
switch (status) {
case ON_LAND -> {
if (!ConfigKt.getActiveConfig()
.getBoostOnBlocks() && !ConfigKt.getActiveConfig()
.getBoostOnIce()) return original;
if (ConfigKt.getActiveConfig()
.getBoostOnIce()) {
List<BlockState> carryingBlocks = getCarryingBlocks();
if (carryingBlocks.stream()
.noneMatch(state -> state.is(BlockTags.ICE))) return original;
}
if (!jumpCollision && !instance.horizontalCollision) return original;
}
case IN_WATER -> {
if (!ConfigKt.getActiveConfig()
.getBoostOnWater()) return original;
if (!jumpCollision && !instance.horizontalCollision) return original;
}
case UNDER_WATER, UNDER_FLOWING_WATER -> {
if (!ConfigKt.getActiveConfig()
.getBoostUnderwater()) return original;
}
case IN_AIR -> {
return original;
}
}
return new Vec3(
original.x,
ConfigKt.getActiveConfig()
.getStepHeight(),
original.z
);
}
@ModifyConstant(
method = "tick",
constant = @Constant(
floatValue = 60.0F,
ordinal = 0
)
)
private float changeEjectTime(float constant) {
Config config = ConfigKt.getActiveConfig();
if (config == null) return constant;
return config.getPlayerEjectTicks();
}
@Unique
private boolean failsPlayerCondition() {
Config config = ConfigKt.getActiveConfig();
if (config == null) return true;
if (!config.getOnlyForPlayers()) return false;
return instance.getPassengers().stream()
.noneMatch(entity -> entity instanceof Player);
}
*//*?}*/
}
34 changes: 18 additions & 16 deletions src/main/java/dev/nyon/bbm/asm/BoatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,30 @@
@SuppressWarnings("AddedMixinMembersNamePattern")
@Mixin(Boat.class)
abstract class BoatMixin extends Entity implements BbmBoat {
@Shadow
private Boat.Status status;

@Unique
private boolean jumpCollision = false;

public BoatMixin(
EntityType<?> entityType,
Level level
) {
super(entityType, level);
}

@Unique
private boolean jumpCollision = false;

@Override
public void setJumpCollision(boolean b) {
jumpCollision = b;
}

@Override
public boolean getJumpCollision() {
return jumpCollision;
}

/*? if <1.21.3 {*/
@Shadow
private Boat.Status status;

@Unique
private Level bbm$getLevel() {
//? if >1.19.4
Expand Down Expand Up @@ -152,14 +163,5 @@ private boolean failsPlayerCondition() {
return getPassengers().stream()
.noneMatch(entity -> entity instanceof Player);
}

@Override
public void setJumpCollision(boolean b) {
jumpCollision = b;
}

@Override
public boolean getJumpCollision() {
return jumpCollision;
}
/*?}*/
}
6 changes: 4 additions & 2 deletions src/main/java/dev/nyon/bbm/asm/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
//? if >=1.21.3
/*import net.minecraft.world.entity.vehicle.AbstractBoat;*/
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
Expand Down Expand Up @@ -48,7 +50,7 @@ private AABB changeBoatBox(
List<VoxelShape> shapes
) {
if (!expandCollision) return box;
if (!(entity instanceof Boat boat)) return box;
if (!(entity instanceof /*? if >=1.21.3 {*/ /*AbstractBoat boat *//*?} else {*/ Boat boat /*?}*/)) return box;
Config config = ConfigKt.getActiveConfig();
if (config == null) return box;

Expand All @@ -73,7 +75,7 @@ private Vec3 setBoatCollision(Vec3 movement) {
Config config = ConfigKt.getActiveConfig();
if (config == null) return original;
if (config.getExtraCollisionDetectionRange() == 0.0) return original;
if (!(instance instanceof Boat boat && instance instanceof BbmBoat bbmBoat)) return original;
if (!(instance instanceof /*? if >=1.21.3 {*/ /*AbstractBoat boat *//*?} else {*/ Boat boat /*?}*/ && instance instanceof BbmBoat bbmBoat)) return original;
if (!boat.hasControllingPassenger()) return original;

expandCollision = true;
Expand Down
27 changes: 14 additions & 13 deletions src/main/resources/bbm.mixins.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"required": true,
"minVersion": "0.8",
"package": "dev.nyon.bbm.asm",
"compatibilityLevel": "JAVA_17",
"mixins": [
"BoatMixin",
"EntityMixin"
],
"client": [
"MinecraftMixin"
],
"injectors": {
"defaultRequire": 1
"required": true,
"minVersion": "0.8",
"package": "dev.nyon.bbm.asm",
"compatibilityLevel": "JAVA_17",
"mixins": [
"AbstractBoatMixin",
"BoatMixin",
"EntityMixin"
],
"client": [
"MinecraftMixin"
],
"injectors": {
"defaultRequire": 1
}
}
10 changes: 10 additions & 0 deletions versions/1.21.3-fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
vers.mcVersion=1.21.3
vers.mcVersionRange=>=1.21.2
vers.supportedMcVersions=1.21.2,1.21.3

vers.deps.quiltmappings=1.21.3+build.6
vers.deps.fapi=0.109.0+1.21.3
vers.deps.yacl=3.6.1+1.21.2-fabric
vers.deps.modMenu=12.0.0-beta.1

loom.platform=fabric
8 changes: 8 additions & 0 deletions versions/1.21.3-neoforge/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
vers.mcVersion=1.21.3
vers.mcVersionRange=>=1.21.2
vers.supportedMcVersions=1.21.2,1.21.3

vers.deps.quiltmappings=1.21.3+build.6
vers.deps.fml=21.3.30-beta

loom.platform=neoforge

0 comments on commit 63d0cd4

Please sign in to comment.