Skip to content

Commit

Permalink
Use vscore kinematics
Browse files Browse the repository at this point in the history
  • Loading branch information
StewStrong committed Jan 6, 2025
1 parent 03def21 commit 3d9cedc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import net.minecraft.server.level.ServerLevel
import net.minecraft.world.Clearable
import net.minecraft.world.level.ChunkPos
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate
import org.joml.Vector3d
import org.valkyrienskies.core.api.VsBeta
import org.valkyrienskies.core.api.ships.ServerShip
import org.valkyrienskies.core.api.ships.properties.ShipTransformVelocity
import org.valkyrienskies.core.apigame.ShipTeleportData
import org.valkyrienskies.core.impl.game.ShipTeleportDataImpl
import org.valkyrienskies.core.impl.game.ships.ShipData
import org.valkyrienskies.core.impl.game.ships.ShipDataCommon
import org.valkyrienskies.core.impl.game.ships.ShipTransformImpl
import org.valkyrienskies.core.util.datastructures.DenseBlockPosSet
import org.valkyrienskies.mod.api.vsApi
import org.valkyrienskies.mod.common.dimensionId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import org.joml.Quaterniond
import org.joml.Quaterniondc
import org.joml.Vector3d
import org.joml.Vector3dc
import org.valkyrienskies.core.api.VsBeta
import org.valkyrienskies.core.apigame.joints.VSJointMaxForceTorque
import org.valkyrienskies.core.apigame.joints.VSJointPose
import org.valkyrienskies.core.apigame.joints.VSRevoluteJoint
import org.valkyrienskies.core.impl.bodies.properties.BodyTransformVelocityImpl
import org.valkyrienskies.core.impl.bodies.properties.BodyKinematicsFactory
import org.valkyrienskies.core.impl.game.ships.ShipDataCommon
import org.valkyrienskies.mod.common.ValkyrienSkiesMod
import org.valkyrienskies.mod.common.blockentity.TestHingeBlockEntity
Expand Down Expand Up @@ -100,6 +101,7 @@ object TestHingeBlock :
}
}

@OptIn(VsBeta::class)
@Deprecated("Deprecated in Java")
override fun use(
state: BlockState,
Expand Down Expand Up @@ -173,29 +175,29 @@ object TestHingeBlock :
// Put the new ship where the old ship is
val newPos = shipThisIsIn.transform.shipToWorld.transformPosition(attachmentLocalPos0, Vector3d())
newPos.sub(shipThisIsIn.transform.shipToWorldRotation.transform(attachmentOffset1, Vector3d()))
val newTransform = BodyTransformVelocityImpl(
val newKinematics = BodyKinematicsFactory.create(
shipThisIsIn.velocity,
shipThisIsIn.angularVelocity,
newPos,
ship.transform.positionInShip,
shipThisIsIn.transform.shipToWorldRotation, // Copy source ship rotation
ship.transform.shipToWorldScaling,
velocity = shipThisIsIn.velocity,
angularVelocity = shipThisIsIn.angularVelocity
ship.transform.positionInShip,
)
// Update the ship transform
(ship as ShipDataCommon).transform = newTransform
(ship as ShipDataCommon).kinematics = newKinematics
} else {
val newPos = Vector3d(attachmentLocalPos0)
newPos.sub(attachmentOffset1)
val newTransform = BodyTransformVelocityImpl(
val newKinematics = BodyKinematicsFactory.create(
ship.velocity,
ship.angularVelocity,
newPos,
ship.transform.positionInShip,
ship.transform.shipToWorldRotation,
ship.transform.shipToWorldScaling,
velocity = ship.velocity,
angularVelocity = ship.angularVelocity
ship.transform.positionInShip,
)
// Update the ship transform
(ship as ShipDataCommon).transform = newTransform
(ship as ShipDataCommon).kinematics = newKinematics
}

level.setBlockAndUpdate(shipCenterPos, Blocks.IRON_BLOCK.defaultBlockState())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import net.minecraft.world.item.context.UseOnContext
import net.minecraft.world.level.block.Rotation.NONE
import net.minecraft.world.level.block.state.BlockState
import org.joml.Vector3d
import org.valkyrienskies.core.api.ships.properties.ShipTransformVelocity
import org.valkyrienskies.core.impl.bodies.properties.BodyTransformImpl
import org.valkyrienskies.core.impl.bodies.properties.BodyTransformVelocityImpl
import org.valkyrienskies.core.api.VsBeta
import org.valkyrienskies.core.impl.bodies.properties.BodyKinematicsFactory
import org.valkyrienskies.core.impl.game.ships.ShipDataCommon
import org.valkyrienskies.core.impl.game.ships.ShipTransformImpl
import org.valkyrienskies.mod.common.dimensionId
import org.valkyrienskies.mod.common.getShipManagingPos
import org.valkyrienskies.mod.common.shipObjectWorld
Expand All @@ -33,6 +31,7 @@ class ShipCreatorItem(
return true
}

@OptIn(VsBeta::class)
override fun useOn(ctx: UseOnContext): InteractionResult {
val level = ctx.level as? ServerLevel ?: return super.useOn(ctx)
val blockPos = ctx.clickedPos
Expand Down Expand Up @@ -67,9 +66,15 @@ class ShipCreatorItem(
// Do not allow scaling to go below minScaling
newShipScaling = Vector3d(minScaling, minScaling, minScaling)
}
val shipTransform =
BodyTransformVelocityImpl(newShipPosInWorld, newShipPosInShipyard, newShipRotation, newShipScaling, Vector3d(), Vector3d())
(serverShip as ShipDataCommon).transform = shipTransform
val newKinematics = BodyKinematicsFactory.create(
Vector3d(),
Vector3d(),
newShipPosInWorld,
newShipRotation,
newShipScaling,
newShipPosInShipyard,
)
(serverShip as ShipDataCommon).kinematics = newKinematics
}
}
}
Expand Down

0 comments on commit 3d9cedc

Please sign in to comment.