Skip to content

Commit

Permalink
added boatism speed handling
Browse files Browse the repository at this point in the history
Merge pull request #4 from JR1811/main
  • Loading branch information
SammyForReal authored Feb 7, 2024
2 parents 12399de + 804d188 commit 714f7f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import cc.tweaked_programs.partnership.main.compat.boatism.BoatismImpl
import net.fabricmc.loader.api.FabricLoader

object Compat {
const val MOD_ID_BOATISM = "boatism"

var boatism: BoatismCompat = BoatismCompat()

fun check() {
if (FabricLoader.getInstance().isModLoaded("boatism"))
if (FabricLoader.getInstance().isModLoaded(MOD_ID_BOATISM))
boatism = BoatismImpl()
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cc.tweaked_programs.partnership.main.compat.boatism

import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.vehicle.Boat


open class BoatismCompat {
open fun isEngine(entity: Entity): Boolean = false
open fun calculateThrust(boat: Boat): Float = 0.0f
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
package cc.tweaked_programs.partnership.main.compat.boatism

import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.vehicle.Boat
import net.shirojr.boatism.entity.custom.BoatEngineEntity
import net.shirojr.boatism.util.BoatEngineCoupler
import net.shirojr.boatism.util.EntityHandler
import java.util.*
import kotlin.jvm.optionals.getOrNull

class BoatismImpl : BoatismCompat() {
override fun isEngine(entity: Entity): Boolean = (entity is BoatEngineEntity)
override fun calculateThrust(boat: Boat): Float {
val coupler = boat as BoatEngineCoupler
var speed = 0.0f
coupler.`boatism$getBoatEngineEntityUuid`()?.let { uuid: Optional<UUID> ->
{
EntityHandler.getBoatEngineEntityFromUuid(uuid.getOrNull(), boat.level(), boat.position(), 10)?.also {
val thrust = it.get().engineHandler.calculateThrustModifier(boat)
val powerLevel = it.get().powerLevel * 0.008f
speed = powerLevel * thrust
}
}
}
return speed
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cc.tweaked_programs.partnership.main.entity

import cc.tweaked_programs.partnership.main.compat.Compat
import net.minecraft.util.Mth
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.vehicle.Boat
Expand Down Expand Up @@ -34,6 +35,8 @@ abstract class GenericBoat(type: EntityType<out Boat>, level: Level) : Boat(type
if (inputDown)
speed -= backwardsSpeed

speed += Compat.boatism.calculateThrust(this)

deltaMovement = deltaMovement.add(
(Mth.sin(-yRot * MAGIKK) * speed).toDouble(),
0.0,
Expand Down

0 comments on commit 714f7f4

Please sign in to comment.