Skip to content

Commit

Permalink
fixed sensor beeing offset
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-s168 committed May 21, 2024
1 parent 97b50f0 commit fa7088d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class RopeHookBlockEntity(pos: BlockPos, state: BlockState):
fun setRopeID(rope: ConstraintId, mainIn: Vector3d?, otherIn: Vector3d?, level: Level) {
println("Block>> $rope")

val main = Helper3d.convertShipToWorldSpace(level, mainIn!!).add(Vector3d(0.5, 0.5, 0.5))
val other = Helper3d.convertShipToWorldSpace(level, otherIn!!).add(Vector3d(0.5, 0.5, 0.5))
val main = Helper3d.convertShipToWorldSpace(level, mainIn!!.add(0.5, 0.5, 0.5, Vector3d()))
val other = Helper3d.convertShipToWorldSpace(level, otherIn!!.add(0.5, 0.5, 0.5, Vector3d()))

ropeId = rope
otherPos = other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.properties.BlockStateProperties
import net.minecraft.world.phys.HitResult
import org.joml.Vector3d
import net.minecraft.world.phys.Vec3
import org.valkyrienskies.mod.common.util.toJOML
import org.valkyrienskies.mod.common.util.toJOMLD
import org.valkyrienskies.mod.common.util.toMinecraft
import org.valkyrienskies.mod.common.world.clipIncludeShips
import org.valkyrienskies.tournament.TournamentBlockEntities
Expand All @@ -26,21 +25,22 @@ class SensorBlockEntity(pos: BlockPos, state: BlockState):
var lastVal = 0

fun getResult(level: ServerLevel): Int {
val lookingTowards = blockState
val facing = blockState
.getValue(BlockStateProperties.FACING)
.normal
.toJOMLD()

val start = Helper3d.convertShipToWorldSpace(level, blockPos)
.add(0.5, 0.5,0.5)
.add(lookingTowards.mul(0.5, Vector3d()))
val start = Helper3d.convertShipToWorldSpace(
level,
Vec3.atCenterOf(blockPos)
.add(Vec3.atLowerCornerOf(facing)
.scale(0.5))
)

val end = Helper3d.convertShipToWorldSpace(
level,
blockPos
.toJOMLD()
.add(0.5, 0.5,0.5)
.add(lookingTowards.mul(TournamentConfig.SERVER.sensorDistance))
Vec3.atCenterOf(blockPos)
.add(Vec3.atLowerCornerOf(facing)
.scale(TournamentConfig.SERVER.sensorDistance + 0.5))
)

val clipResult = level.clipIncludeShips(
Expand All @@ -58,9 +58,6 @@ class SensorBlockEntity(pos: BlockPos, state: BlockState):
.location
.toJOML()

println("start to end distance: ${start.distance(end)}")
println("start to hit distance: ${start.distance(hit)}")

return if (clipResult.type != HitResult.Type.MISS) {
ceil(lerp(15.0, 1.0, start.distance(hit) / TournamentConfig.SERVER.sensorDistance)).toInt()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import net.minecraft.core.BlockPos
import net.minecraft.core.particles.ParticleOptions
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.level.Level
import net.minecraft.world.phys.Vec3
import org.joml.Vector3d
import org.joml.Vector3dc
import org.valkyrienskies.mod.common.getShipManagingPos
import org.valkyrienskies.mod.common.getShipObjectManagingPos
import org.valkyrienskies.mod.common.util.toJOML
import org.valkyrienskies.mod.common.util.toJOMLD
import org.valkyrienskies.mod.common.util.toMinecraft
import org.valkyrienskies.tournament.util.extension.toBlock
Expand All @@ -26,13 +29,15 @@ object Helper3d {
else -> pos
}

fun convertShipToWorldSpace(level: Level, pos: Vector3d): Vector3d =
level.getShipObjectManagingPos(pos) ?.shipToWorld ?.transformPosition(pos)
?: pos

fun convertShipToWorldSpace(level: Level, pos: BlockPos): Vector3d =
level.getShipObjectManagingPos(pos) ?.shipToWorld ?.transformPosition(pos.toJOMLD())
?: pos.toJOMLD()
convertShipToWorldSpace(level, pos.toJOMLD())

fun convertShipToWorldSpace(level: Level, vec: Vector3d) : Vector3d {
return convertShipToWorldSpace(level, vec.toBlock())
}
fun convertShipToWorldSpace(level: Level, pos: Vec3): Vector3d =
convertShipToWorldSpace(level, pos.toJOML())

fun drawParticleLine(a: Vector3d, b: Vector3d, level: Level, particle: ParticleOptions) {
val le = a.distance(b) * 3
Expand Down

0 comments on commit fa7088d

Please sign in to comment.