Skip to content

Commit

Permalink
Fixed ShipAssembler.assembleToShip()
Browse files Browse the repository at this point in the history
  • Loading branch information
StewStrong committed Oct 28, 2024
1 parent ed0ef81 commit a0517ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ private void shipChangeDimension(@NotNull final ServerLevel srcLevel, @NotNull f
new Vector3d(),
new Vector3d(),
VSGameUtilsKt.getDimensionId(destLevel),
null,
null
);
shipWorld.teleportShip(shipObject, shipTeleportData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package org.valkyrienskies.mod.common.assembly
import net.minecraft.core.BlockPos
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.state.BlockState
import org.joml.Vector3d
import org.joml.Vector3dc
import org.joml.Vector3i
import org.joml.Vector3ic
import org.valkyrienskies.core.api.ships.ServerShip
Expand All @@ -18,8 +16,6 @@ import org.valkyrienskies.mod.common.dimensionId
import org.valkyrienskies.mod.common.getShipObjectManagingPos
import org.valkyrienskies.mod.common.shipObjectWorld
import org.valkyrienskies.mod.common.util.SplittingDisablerAttachment
import org.valkyrienskies.mod.common.util.toJOMLD
import org.valkyrienskies.mod.util.logger

object ShipAssembler {

Expand All @@ -45,20 +41,25 @@ object ShipAssembler {

val existingShip = sLevel.getShipObjectManagingPos(blocks.find { !sLevel.getBlockState(it).isAir } ?: throw IllegalArgumentException())

var structureCornerMin: BlockPos = blocks[0]
var structureCornerMax: BlockPos = blocks[0]
var structureCornerMin: BlockPos? = null
var structureCornerMax: BlockPos? = null
var hasSolids = false

// Calculate bounds of the area containing all blocks adn check for solids and invalid blocks
for (itPos in blocks) {
if (isValidShipBlock(level.getBlockState(itPos))) {
structureCornerMin = AssemblyUtil.getMinCorner(structureCornerMin, itPos)
structureCornerMax = AssemblyUtil.getMaxCorner(structureCornerMax, itPos)
if (structureCornerMin == null) {
structureCornerMin = itPos
structureCornerMax = itPos
} else {
structureCornerMin = AssemblyUtil.getMinCorner(structureCornerMin!!, itPos)
structureCornerMax = AssemblyUtil.getMaxCorner(structureCornerMax!!, itPos)
}
hasSolids = true
}
}
if (!hasSolids) throw IllegalArgumentException("No solid blocks found in the structure")
val contraptionOGPos: Vector3ic = AssemblyUtil.getMiddle(structureCornerMin, structureCornerMax)
val contraptionOGPos: Vector3ic = AssemblyUtil.getMiddle(structureCornerMin!!, structureCornerMax!!)
// Create new contraption at center of bounds
val contraptionWorldPos: Vector3i = if (existingShip != null) {
val doubleVer = existingShip.shipToWorld.transformPosition(Vector3d(contraptionOGPos)).floor()
Expand Down Expand Up @@ -112,15 +113,16 @@ object ShipAssembler {
AssemblyUtil.updateBlock(level,itPos,shipPos,level.getBlockState(shipPos))
}

val spawnWorldPos: Vector3dc = AssemblyUtil.getMiddle(structureCornerMin.toJOMLD(), structureCornerMax.toJOMLD()).add(0.5, 0.5, 0.5)

val shipCenterPos = ((newShip as ServerShip).inertiaData.centerOfMassInShip).add(0.5, 0.5, 0.5, Vector3d())
// This is giga sus, but whatever
val shipPos = Vector3d(contraptionOGPos).add(0.5, 0.5, 0.5)
if (existingShip != null) {
sLevel.server.shipObjectWorld
.teleportShip(newShip as ServerShip, ShipTeleportDataImpl(existingShip.shipToWorld.transformPosition(spawnWorldPos, Vector3d()), existingShip.transform.shipToWorldRotation, existingShip.velocity, existingShip.omega, existingShip.chunkClaimDimension))
.teleportShip(newShip as ServerShip, ShipTeleportDataImpl(existingShip.shipToWorld.transformPosition(shipPos, Vector3d()), existingShip.transform.shipToWorldRotation, existingShip.velocity, existingShip.omega, existingShip.chunkClaimDimension, newScale = existingShip.transform.shipToWorldScaling.x(), newPosInShip = shipCenterPos))

} else {
sLevel.server.shipObjectWorld
.teleportShip(newShip as ServerShip, ShipTeleportDataImpl(spawnWorldPos))
.teleportShip(newShip as ServerShip, ShipTeleportDataImpl(newPos = shipPos, newPosInShip = shipCenterPos))
}
if (shouldDisableSplitting) {
level.shipObjectWorld.loadedShips.getById(newShip.id)?.getAttachment<SplittingDisablerAttachment>()?.enableSplitting()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ forge_version=1.18.2-40.2.4
create_fabric_version=0.5.1-f-build.1333+mc1.18.2
flywheel_version_fabric=0.6.9-38
createbigcannons_version= 0.5.2-nightly-e815ca4
vs_core_version=1.1.0+13b73ea871
vs_core_version=1.1.0+2a62e6a823
# Prevent kotlin from autoincluding stdlib as a dependency, which breaks
# gradle's composite builds (includeBuild) for some reason. We'll add it manually
kotlin.stdlib.default.dependency=false
Expand Down

0 comments on commit a0517ba

Please sign in to comment.