Skip to content

Commit

Permalink
1.18.x/feature/update latest vs2 (#256)
Browse files Browse the repository at this point in the history
* Initial work to update vs2

* It builds, but it also crashes

* Ships can move again!

* Forge almost works

* Forge works :D
  • Loading branch information
StewStrong authored Oct 1, 2023
1 parent 25f6aa1 commit ff45ea3
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 87 deletions.
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
// Needed for Forge+Fabric
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
id "architectury-plugin" version "3.4.146"
id "dev.architectury.loom" version "1.3.355" apply false
// Kotlin
id "org.jetbrains.kotlin.jvm" version "1.7.21" apply false
id "org.jetbrains.kotlin.jvm" version "1.9.10" apply false
// Kotlin linter
id "org.jlleitschuh.gradle.ktlint" version "10.3.0"
// Java linter
Expand Down Expand Up @@ -52,6 +52,9 @@ subprojects {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.18.2:2022.09.04@zip")
})

implementation("org.joml:joml:1.10.4") { transitive = false }
implementation("org.joml:joml-primitives:1.10.0") { transitive = false }
}

checkstyle {
Expand All @@ -68,9 +71,9 @@ subprojects {
tasks.withType(Checkstyle) {
reports {
// Do not output html reports
html.enabled = false
html.required = false
// Output xml reports
xml.enabled = true
xml.required = true
}
}

Expand Down
10 changes: 7 additions & 3 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ dependencies {
// Remove the next line if you don't want to depend on the API
// modApi "me.shedaniel:architectury:${rootProject.architectury_version}"
modApi("org.valkyrienskies:valkyrienskies-118-common:${rootProject.vs2_version}")
implementation("org.valkyrienskies.core:api:1.1.0+c92814e9b7") { transitive = false }

api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.21"
api "org.jetbrains.kotlin:kotlin-reflect:1.7.21"
compileOnly("org.valkyrienskies.core:api:${rootProject.vs_core_version}")
compileOnly("org.valkyrienskies.core:api-game:${rootProject.vs_core_version}")
compileOnly("org.valkyrienskies.core:util:${rootProject.vs_core_version}")
compileOnly("org.valkyrienskies.core:impl:${rootProject.vs_core_version}")

api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10"
api "org.jetbrains.kotlin:kotlin-reflect:1.9.10"
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import net.minecraft.world.level.block.state.BlockState
import org.joml.Math.lerp
import org.joml.Math.min
import org.valkyrienskies.core.api.ships.ServerShip
import org.valkyrienskies.core.impl.api.ServerShipProvider
import org.valkyrienskies.core.impl.api.shipValue
import org.valkyrienskies.eureka.EurekaBlockEntities
import org.valkyrienskies.eureka.EurekaConfig
import org.valkyrienskies.eureka.EurekaProperties.HEAT
Expand All @@ -34,13 +32,10 @@ import kotlin.math.ceil
import kotlin.math.max

class EngineBlockEntity(pos: BlockPos, state: BlockState) :
BaseContainerBlockEntity(EurekaBlockEntities.ENGINE.get(), pos, state),
ServerShipProvider,
StackedContentsCompatible,
BaseContainerBlockEntity(EurekaBlockEntities.ENGINE.get(), pos, state), StackedContentsCompatible,
WorldlyContainer {

override val ship: ServerShip? get() = (this.level as ServerLevel).getShipManagingPos(this.blockPos)
private val eurekaShipControl by shipValue<EurekaShipControl>()
private val ship: ServerShip? get() = (this.level as ServerLevel).getShipManagingPos(this.blockPos)
val data = KtContainerData()
private var heatLevel by data
private var fuelLeft by data
Expand Down Expand Up @@ -91,25 +86,24 @@ class EngineBlockEntity(pos: BlockPos, state: BlockState) :
}

if (heat > 0) {
val eurekaShipControl = ship?.getAttachment(EurekaShipControl::class.java)
if (ship != null && eurekaShipControl != null) {
// Avoid fluctuations in speed
var effectiveHeat = 1f
if (heat < maxEffectiveFuel) {
effectiveHeat = heat / 100f;
}

if (ship != null && eurekaShipControl != null) {

// Avoid fluctuations in speed
var effectiveHeat = 1f
if (heat < maxEffectiveFuel) {
effectiveHeat = heat / 100f;
}

eurekaShipControl!!.power += lerp(
EurekaConfig.SERVER.minEnginePower,
EurekaConfig.SERVER.enginePower,
effectiveHeat,
)
eurekaShipControl.power += lerp(
EurekaConfig.SERVER.minEnginePower,
EurekaConfig.SERVER.enginePower,
effectiveHeat,
)

heat -= eurekaShipControl!!.consumed;
}
heat -= eurekaShipControl.consumed
}

heat = max(heat - scaleEngineCooling(EurekaConfig.SERVER.engineHeatLoss),0f)
heat = max(heat - scaleEngineCooling(EurekaConfig.SERVER.engineHeatLoss), 0f)
}
}
}
Expand All @@ -121,7 +115,8 @@ class EngineBlockEntity(pos: BlockPos, state: BlockState) :
*
* @return scaled fuel ticks.
*/
private fun getScaledFuel(): Int = ((FurnaceBlockEntity.getFuel()[fuel.item] ?: 0) * EurekaConfig.SERVER.engineFuelMultiplier).toInt()
private fun getScaledFuel(): Int =
((FurnaceBlockEntity.getFuel()[fuel.item] ?: 0) * EurekaConfig.SERVER.engineFuelMultiplier).toInt()

/**
* Absorb one fuel item into the engine.
Expand Down Expand Up @@ -153,15 +148,16 @@ class EngineBlockEntity(pos: BlockPos, state: BlockState) :
*
* @return the scaled value.
*/
private fun scaleEngineHeating(value: Float): Float = (100 * EurekaConfig.SERVER.engineHeatChangeExponent -
this.heat * EurekaConfig.SERVER.engineHeatChangeExponent + 1f) * value
private fun scaleEngineHeating(value: Float): Float =
(100 * EurekaConfig.SERVER.engineHeatChangeExponent - this.heat * EurekaConfig.SERVER.engineHeatChangeExponent + 1f) * value

/**
* Scale given cooling [value] based on current heat.
*
* @return the scaled value.
*/
private fun scaleEngineCooling(value: Float): Float = (this.heat * EurekaConfig.SERVER.engineHeatChangeExponent + 1f) * value
private fun scaleEngineCooling(value: Float): Float =
(this.heat * EurekaConfig.SERVER.engineHeatChangeExponent + 1f) * value

override fun saveAdditional(tag: CompoundTag) {
tag.put("FuelSlot", fuel.save(CompoundTag()))
Expand All @@ -188,8 +184,7 @@ class EngineBlockEntity(pos: BlockPos, state: BlockState) :

override fun isEmpty(): Boolean = fuel.isEmpty

override fun getItem(slot: Int): ItemStack =
if (slot == 0) fuel else ItemStack.EMPTY
override fun getItem(slot: Int): ItemStack = if (slot == 0) fuel else ItemStack.EMPTY

override fun removeItem(slot: Int, amount: Int): ItemStack {
return ContainerHelper.removeItem(listOf(fuel), slot, amount)
Expand All @@ -208,9 +203,7 @@ class EngineBlockEntity(pos: BlockPos, state: BlockState) :
return if (level!!.getBlockEntity(worldPosition) !== this) {
false
} else player.distanceToSqr(
worldPosition.x.toDouble() + 0.5,
worldPosition.y.toDouble() + 0.5,
worldPosition.z.toDouble() + 0.5
worldPosition.x.toDouble() + 0.5, worldPosition.y.toDouble() + 0.5, worldPosition.z.toDouble() + 0.5
) <= 64.0
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import net.minecraft.network.chat.TextComponent
import net.minecraft.network.chat.TranslatableComponent
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.MenuProvider
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.AbstractContainerMenu
Expand All @@ -24,8 +23,6 @@ import org.joml.Vector3d
import org.joml.Vector3dc
import org.valkyrienskies.core.api.ships.ServerShip
import org.valkyrienskies.core.api.ships.getAttachment
import org.valkyrienskies.core.impl.api.ServerShipProvider
import org.valkyrienskies.core.impl.api.shipValue
import org.valkyrienskies.core.impl.util.logger
import org.valkyrienskies.eureka.EurekaBlockEntities
import org.valkyrienskies.eureka.EurekaConfig
Expand All @@ -40,15 +37,14 @@ import org.valkyrienskies.mod.common.util.toDoubles
import org.valkyrienskies.mod.common.util.toJOMLD

class ShipHelmBlockEntity(pos: BlockPos, state: BlockState) :
BlockEntity(EurekaBlockEntities.SHIP_HELM.get(), pos, state), MenuProvider, ServerShipProvider {
BlockEntity(EurekaBlockEntities.SHIP_HELM.get(), pos, state), MenuProvider {

override var ship: ServerShip? = null // TODO ship is not being set in vs2?
get() = field ?: (level as ServerLevel).getShipObjectManagingPos(this.blockPos)
val control by shipValue<EurekaShipControl>()
val seats = mutableListOf<ShipMountingEntity>()
private val ship: ServerShip? get() = (level as ServerLevel).getShipObjectManagingPos(this.blockPos)
private val control: EurekaShipControl? get() = ship?.getAttachment(EurekaShipControl::class.java)
private val seats = mutableListOf<ShipMountingEntity>()
val assembled get() = ship != null
val aligning get() = control?.aligning ?: false
var shouldDisassembleWhenPossible = false
private var shouldDisassembleWhenPossible = false

override fun createMenu(id: Int, playerInventory: Inventory, player: Player): AbstractContainerMenu {
return ShipHelmScreenMenu(id, playerInventory, this)
Expand Down Expand Up @@ -109,13 +105,14 @@ class ShipHelmBlockEntity(pos: BlockPos, state: BlockState) :
seats.add(seat)
}

return ride;
return ride
}

fun tick() {
if (shouldDisassembleWhenPossible && ship?.getAttachment<EurekaShipControl>()?.canDisassemble == true) {
this.disassemble()
}
control?.ship = ship
}

// Needs to get called server-side
Expand Down Expand Up @@ -184,8 +181,8 @@ class ShipHelmBlockEntity(pos: BlockPos, state: BlockState) :
// If player is already controlling the ship, open the helm menu
if (!force && player.vehicle?.type == ValkyrienSkiesMod.SHIP_MOUNTING_ENTITY_TYPE && seats.contains(player.vehicle as ShipMountingEntity))
{
player.openMenu(this);
return true;
player.openMenu(this)
return true
}

//val seat = spawnSeat(blockPos, blockState, level as ServerLevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import org.valkyrienskies.core.api.ships.ServerShip
import org.valkyrienskies.core.api.ships.ShipForcesInducer
import org.valkyrienskies.core.api.ships.getAttachment
import org.valkyrienskies.core.api.ships.saveAttachment
import org.valkyrienskies.core.impl.api.ServerShipUser
import org.valkyrienskies.core.impl.api.Ticked
import org.valkyrienskies.core.impl.api.shipValue
import org.valkyrienskies.core.impl.game.ships.PhysShipImpl
import org.valkyrienskies.eureka.EurekaConfig
import org.valkyrienskies.mod.api.SeatedControllingPlayer
import org.valkyrienskies.mod.common.util.toJOMLD
import kotlin.math.*
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.floor
import kotlin.math.max
import kotlin.math.min

@JsonAutoDetect(
fieldVisibility = JsonAutoDetect.Visibility.ANY,
Expand All @@ -33,13 +34,10 @@ import kotlin.math.*
setterVisibility = JsonAutoDetect.Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
class EurekaShipControl : ShipForcesInducer, ServerShipUser, Ticked {
class EurekaShipControl : ShipForcesInducer {

@JsonIgnore
override var ship: ServerShip? = null

@delegate:JsonIgnore
private val controllingPlayer by shipValue<SeatedControllingPlayer>()
internal var ship: ServerShip? = null

private var extraForce = 0.0
var aligning = false
Expand Down Expand Up @@ -133,7 +131,7 @@ class EurekaShipControl : ShipForcesInducer, ServerShipUser, Ticked {
val invRotationAxisAngle = AxisAngle4d(invRotation)
// Floor makes a number 0 to 3, which corresponds to direction
alignTarget = floor((invRotationAxisAngle.angle / (PI * 0.5)) + 4.5).toInt() % 4
angleUntilAligned = (alignTarget.toDouble() * (0.5 * Math.PI)) - invRotationAxisAngle.angle
angleUntilAligned = (alignTarget.toDouble() * (0.5 * PI)) - invRotationAxisAngle.angle
if (disassembling) {
val pos = ship.transform.positionInWorld
positionUntilAligned = pos.floor(Vector3d())
Expand All @@ -154,6 +152,7 @@ class EurekaShipControl : ShipForcesInducer, ServerShipUser, Ticked {
}
// endregion

val controllingPlayer = ship.getAttachment(SeatedControllingPlayer::class.java)
stabilize(
physShip,
omega,
Expand Down Expand Up @@ -343,13 +342,6 @@ class EurekaShipControl : ShipForcesInducer, ServerShipUser, Ticked {
field = v; deleteIfEmpty()
}

override fun tick() {
extraForce = power
power = 0.0
consumed = physConsumption * /* should be phyics ticks based*/ 0.1f
physConsumption = 0.0f
}

private fun deleteIfEmpty() {
if (helms <= 0 && floaters <= 0 && anchors <= 0 && balloons <= 0) {
ship?.saveAttachment<EurekaShipControl>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import org.joml.AxisAngle4d
import org.joml.Matrix4d
import org.joml.Vector3d
import org.valkyrienskies.core.api.ships.ServerShip
import org.valkyrienskies.core.impl.datastructures.DenseBlockPosSet
import org.valkyrienskies.core.impl.game.ships.ShipObjectServer
import org.valkyrienskies.core.impl.networking.simple.sendToClient
import org.valkyrienskies.core.impl.util.logger
import org.valkyrienskies.core.util.datastructures.DenseBlockPosSet
import org.valkyrienskies.eureka.EurekaConfig
import org.valkyrienskies.mod.common.assembly.createNewShipWithBlocks
import org.valkyrienskies.mod.common.executeIf
Expand All @@ -24,6 +22,7 @@ import org.valkyrienskies.mod.common.networking.PacketRestartChunkUpdates
import org.valkyrienskies.mod.common.networking.PacketStopChunkUpdates
import org.valkyrienskies.mod.common.playerWrapper
import org.valkyrienskies.mod.common.util.toJOML
import org.valkyrienskies.mod.util.logger
import org.valkyrienskies.mod.util.relocateBlock
import org.valkyrienskies.mod.util.updateBlock
import kotlin.collections.set
Expand Down Expand Up @@ -64,8 +63,7 @@ object ShipAssembler {
}

fun unfillShip(level: ServerLevel, ship: ServerShip, direction: Direction, shipCenter: BlockPos, center: BlockPos) {
ship as ShipObjectServer
ship.shipData.isStatic = true
ship.isStatic = true

// ship's rotation rounded to nearest 90*
val shipToWorld = ship.transform.run {
Expand Down
8 changes: 4 additions & 4 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ configurations {
dependencies {
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
modImplementation("net.fabricmc:fabric-language-kotlin:1.8.5+kotlin.1.7.20")
include(modImplementation("net.fabricmc:fabric-language-kotlin:1.10.10+kotlin.1.9.10"))

// Mod menu
modImplementation("com.terraformersmc:modmenu:3.2.3")
Expand All @@ -51,18 +51,18 @@ shadowJar {
exclude "architectury.common.json"

configurations = [project.configurations.shadowCommon]
classifier "dev-shadow"
archiveClassifier.set "dev-shadow"
}

remapJar {
injectAccessWidener = true
input.set shadowJar.archiveFile
dependsOn shadowJar
classifier null
archiveClassifier.set null
}

jar {
classifier "dev"
archiveClassifier.set "dev"
}

sourcesJar {
Expand Down
Loading

0 comments on commit ff45ea3

Please sign in to comment.