Skip to content

Commit

Permalink
make connectors more willing to connect + bump version
Browse files Browse the repository at this point in the history
(cherry picked from commit e2ebbd3)
  • Loading branch information
alex-s168 committed May 22, 2024
1 parent 419e5db commit af35b38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntityTicker
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.Vec3
import org.joml.Vector3d
import org.joml.Vector3dc
import org.valkyrienskies.core.api.ships.ServerShip
import org.valkyrienskies.core.api.ships.properties.ShipId
import org.valkyrienskies.core.apigame.constraints.VSAttachmentConstraint
import org.valkyrienskies.mod.common.*
import org.valkyrienskies.mod.common.util.toJOMLD
import org.valkyrienskies.mod.common.util.toJOML
import org.valkyrienskies.mod.common.util.toMinecraft
import org.valkyrienskies.physics_api.ConstraintId
import org.valkyrienskies.tournament.TournamentBlockEntities
Expand All @@ -40,7 +41,7 @@ class ConnectorBlockEntity(pos: BlockPos, state: BlockState):
if (redstoneLevel == 0) {
println("restoring constraint")
constraint = level.shipObjectWorld.createNewConstraint(constraintData!!)
val other = constraintData!!.localPos1.sub(0.5, 0.5, 0.5, Vector3d()).toBlock()
val other = Vector3d(constraintData!!.localPos1).toBlock()
val otherBe = level.getBlockEntity(other) as ConnectorBlockEntity
assert(otherBe.constraintData == null)
otherBe.constraint = constraint
Expand All @@ -59,11 +60,12 @@ class ConnectorBlockEntity(pos: BlockPos, state: BlockState):

if (redstoneLevel == 0) {
val currentShip = level.getShipObjectManagingPos(blockPos)
val blockPosCentered = Vec3.atCenterOf(blockPos).toJOML()
val transform = currentShip
?.transform
?.shipToWorld
?.transformPosition(blockPos.toJOMLD())
?: blockPos.toJOMLD()
?.transformPosition(blockPosCentered)
?: blockPosCentered

val off = Vector3d(2.0)
val aabb = AABB(transform.sub(off).toMinecraft(), transform.add(off).toMinecraft())
Expand Down Expand Up @@ -99,15 +101,18 @@ class ConnectorBlockEntity(pos: BlockPos, state: BlockState):
private fun connect(other: BlockPos, otherBe: ConnectorBlockEntity): Boolean {
val level = level as ServerLevel

val (idA, posA) = transform(blockPos.toJOMLD())
val (idB, posB) = transform(other.toJOMLD())
val centerA = Vec3.atCenterOf(blockPos).toJOML()
val centerB = Vec3.atCenterOf(other).toJOML()

val (idA, posA) = transform(centerA)
val (idB, posB) = transform(centerB)

val cfg = VSAttachmentConstraint(
idA,
idB,
compliance,
blockPos.toJOMLD().add(0.5, 0.5, 0.5),
other.toJOMLD().add(0.5, 0.5, 0.5),
centerA,
centerB,
maxForce,
min(posA.distance(posB), 1.4),
)
Expand Down Expand Up @@ -144,9 +149,9 @@ class ConnectorBlockEntity(pos: BlockPos, state: BlockState):
}
if (!recursed) {
otherbesec?.let {
val otherBe = level.getBlockEntity(it) as ConnectorBlockEntity
val otherBe = level.getBlockEntity(it) as? ConnectorBlockEntity?
if (otherBe != this)
otherBe.disconnect(true)
otherBe?.disconnect(true)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx4096M

mod_name=Tournament
mod_id=vs_tournament
Tournament_version=1.1.0_beta-5.2
Tournament_version=1.1.0_beta-5.3
enabled_platforms=fabric,forge
archives_base_name=tournament
maven_group=org.valkyrienskies
Expand Down

0 comments on commit af35b38

Please sign in to comment.