From 3e2f91591c0413718686789a26cdc48bd50cf807 Mon Sep 17 00:00:00 2001 From: btwonion Date: Tue, 26 Mar 2024 18:57:00 +0100 Subject: [PATCH] add option to disable feature for non-player boat --- build.gradle.kts | 2 +- changelog.md | 1 + readme.md | 15 ++++++++------- src/main/java/dev/nyon/bbm/asm/BoatMixin.java | 10 ++++++++++ src/main/kotlin/dev/nyon/bbm/config/Config.kt | 3 ++- .../kotlin/dev/nyon/bbm/config/ConfigScreen.kt | 8 ++++++++ src/main/resources/assets/bbm/lang/en_us.json | 4 +++- 7 files changed, 33 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7d0210f..a2bcf60 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ plugins { } group = "dev.nyon" -val majorVersion = "1.0.0" +val majorVersion = "1.1.0" val mcVersion = "1.20.4" version = "$majorVersion-$mcVersion" val authors = listOf("btwonion") diff --git a/changelog.md b/changelog.md index e69de29..3766d5c 100644 --- a/changelog.md +++ b/changelog.md @@ -0,0 +1 @@ +- add option to enable function only to players diff --git a/readme.md b/readme.md index 63d5760..016d77c 100644 --- a/readme.md +++ b/readme.md @@ -13,13 +13,14 @@ ```json5 { - "version": 1, // just ignore that, only for migrations - "config": { - "stepHeight": 0.3, // the height the boat should travel upwards - "playerEjectTicks": 200.0, // defines the ticks that should pass before ejecting a player, when the player lost control over the boat - "boostUnderwater": true, // toggles, whether a boat, which is underwater should be boosted upwards with half of the step height - "wallHitCooldownTicks": 5 // defines the ticks that should pass before moving the boat up a block - } + "version": 1, // just ignore that, only for migrations + "config": { + "stepHeight": 0.3, // the height the boat should travel upwards + "playerEjectTicks": 200.0, // defines the ticks that should pass before ejecting a player, when the player lost control over the boat + "boostUnderwater": true, // toggles, whether a boat, which is underwater should be boosted upwards with half of the step height + "wallHitCooldownTicks": 5, // defines the ticks that should pass before moving the boat up a block + "onlyForPlayers": true // toggles, whether the boosts configured below should only work if the boat carries a player. + } } ``` diff --git a/src/main/java/dev/nyon/bbm/asm/BoatMixin.java b/src/main/java/dev/nyon/bbm/asm/BoatMixin.java index 413c79b..d23ce32 100644 --- a/src/main/java/dev/nyon/bbm/asm/BoatMixin.java +++ b/src/main/java/dev/nyon/bbm/asm/BoatMixin.java @@ -37,6 +37,7 @@ private void initStepHeight( at = @At("HEAD") ) private void checkWall(CallbackInfo ci) { + if (failsPlayerCondition()) return; if (wallHitCooldown > 0) wallHitCooldown--; else if (instance.horizontalCollision) { wallHitCooldown = ConfigKt.config.getWallHitCooldownTicks(); @@ -51,6 +52,7 @@ else if (instance.horizontalCollision) { ) private void boostUnderwater(CallbackInfo ci) { if (!instance.isUnderWater()) return; + if (failsPlayerCondition()) return; if (!ConfigKt.config.getBoostUnderwater()) return; instance.setDeltaMovement(instance.getDeltaMovement() .add(0, ConfigKt.config.getStepHeight() / 2, 0)); @@ -66,4 +68,12 @@ private void boostUnderwater(CallbackInfo ci) { private float changeEjectTime(float constant) { return ConfigKt.config.getPlayerEjectTicks(); } + + @Unique + private boolean failsPlayerCondition() { + if (!ConfigKt.config.getOnlyForPlayers()) return false; + return instance.getPassengers() + .stream() + .noneMatch(entity -> entity.getType() == EntityType.PLAYER); + } } diff --git a/src/main/kotlin/dev/nyon/bbm/config/Config.kt b/src/main/kotlin/dev/nyon/bbm/config/Config.kt index e31cff7..dca9822 100644 --- a/src/main/kotlin/dev/nyon/bbm/config/Config.kt +++ b/src/main/kotlin/dev/nyon/bbm/config/Config.kt @@ -14,7 +14,8 @@ data class Config( var stepHeight: Float = 0.3f, var playerEjectTicks: Float = 20f * 10f, var boostUnderwater: Boolean = true, - var wallHitCooldownTicks: Int = 5 + var wallHitCooldownTicks: Int = 5, + var onlyForPlayers: Boolean = true ) : FabricPacket { companion object { diff --git a/src/main/kotlin/dev/nyon/bbm/config/ConfigScreen.kt b/src/main/kotlin/dev/nyon/bbm/config/ConfigScreen.kt index 79300a3..7deade3 100644 --- a/src/main/kotlin/dev/nyon/bbm/config/ConfigScreen.kt +++ b/src/main/kotlin/dev/nyon/bbm/config/ConfigScreen.kt @@ -60,5 +60,13 @@ private fun YetAnotherConfigLib.Builder.appendCategory() = .controller(IntegerFieldControllerBuilder::create) .build() ) + .option( + Option.createBuilder() + .name(Component.translatable("menu.bbm.config.category.only_for_players.title")) + .description(OptionDescription.of(Component.translatable("menu.bbm.config.category.only_for_players.description"))) + .binding(config.onlyForPlayers, { config.onlyForPlayers }, { config.onlyForPlayers = it }) + .controller(TickBoxControllerBuilder::create) + .build() + ) .build() ) diff --git a/src/main/resources/assets/bbm/lang/en_us.json b/src/main/resources/assets/bbm/lang/en_us.json index 475f850..257345c 100644 --- a/src/main/resources/assets/bbm/lang/en_us.json +++ b/src/main/resources/assets/bbm/lang/en_us.json @@ -8,5 +8,7 @@ "menu.bbm.config.category.boost_underwater.title": "Boost underwater", "menu.bbm.config.category.boost_underwater.description": "Toggles, whether a boat, which is underwater should be boosted upwards with half of the step height.", "menu.bbm.config.category.wall_hit_cooldown_ticks.title": "Wall hit cooldown ticks", - "menu.bbm.config.category.wall_hit_cooldown_ticks.description": "Defines the ticks that should pass before moving the boat up a block." + "menu.bbm.config.category.wall_hit_cooldown_ticks.description": "Defines the ticks that should pass before moving the boat up a block.", + "menu.bbm.config.category.only_for_players.title": "Only for players", + "menu.bbm.config.category.only_for_players.description": "Toggles, whether the boosts configured below should only work if the boat carries a player." }