Skip to content

Commit

Permalink
add option to disable feature for non-player boat
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Mar 26, 2024
1 parent a4afbe5 commit 3e2f915
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- add option to enable function only to players
15 changes: 8 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
```
</details>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/nyon/bbm/asm/BoatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -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);
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/dev/nyon/bbm/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/dev/nyon/bbm/config/ConfigScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,13 @@ private fun YetAnotherConfigLib.Builder.appendCategory() =
.controller(IntegerFieldControllerBuilder::create)
.build()
)
.option(
Option.createBuilder<Boolean>()
.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()
)
4 changes: 3 additions & 1 deletion src/main/resources/assets/bbm/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

0 comments on commit 3e2f915

Please sign in to comment.