Even better tele pos determination logic
This commit is contained in:
parent
5586404512
commit
6738921e8a
@ -48,10 +48,12 @@ import ru.dbotthepony.mc.otm.core.plus
|
|||||||
import ru.dbotthepony.mc.otm.core.set
|
import ru.dbotthepony.mc.otm.core.set
|
||||||
import ru.dbotthepony.mc.otm.core.shortestDistanceBetween
|
import ru.dbotthepony.mc.otm.core.shortestDistanceBetween
|
||||||
import ru.dbotthepony.mc.otm.core.times
|
import ru.dbotthepony.mc.otm.core.times
|
||||||
|
import ru.dbotthepony.mc.otm.core.toDoubleVector
|
||||||
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
||||||
import ru.dbotthepony.mc.otm.registry.MNames
|
import ru.dbotthepony.mc.otm.registry.MNames
|
||||||
import ru.dbotthepony.mc.otm.triggers.EnderTeleporterFallDeathTrigger
|
import ru.dbotthepony.mc.otm.triggers.EnderTeleporterFallDeathTrigger
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
|
import kotlin.math.roundToInt
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiveFeature(AndroidFeatures.ENDER_TELEPORTER, capability) {
|
class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiveFeature(AndroidFeatures.ENDER_TELEPORTER, capability) {
|
||||||
@ -122,8 +124,8 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryToPhaseThroughWall(blockPos: BlockPos, normal: Vec3i, phasedBlocks: MutableList<BlockPos>): TraceResult? {
|
private fun tryToPhaseThroughWall(blockPos: BlockPos, normal: Vec3i): TraceResult? {
|
||||||
phasedBlocks.clear()
|
val phasedBlocks = ArrayList<BlockPos>(ServerConfig.EnderTeleporter.MAX_PHASE_DISTANCE)
|
||||||
phasedBlocks.add(blockPos)
|
phasedBlocks.add(blockPos)
|
||||||
|
|
||||||
for (extend in 1 .. ServerConfig.EnderTeleporter.MAX_PHASE_DISTANCE) {
|
for (extend in 1 .. ServerConfig.EnderTeleporter.MAX_PHASE_DISTANCE) {
|
||||||
@ -175,21 +177,26 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
|
|||||||
|
|
||||||
val candidates = LinkedList<TraceResult>()
|
val candidates = LinkedList<TraceResult>()
|
||||||
|
|
||||||
if (result.direction != Direction.UP && result.direction != Direction.DOWN && !isAirGap(result.blockPos) && ply.xRot in -15f .. 15f) {
|
if (
|
||||||
|
result.direction != Direction.UP &&
|
||||||
|
result.direction != Direction.DOWN &&
|
||||||
|
!isAirGap(result.blockPos) &&
|
||||||
|
ply.xRot in -15f .. 15f &&
|
||||||
|
ply.eyePosition.distanceTo(result.blockPos.asVector()) <= 3.5
|
||||||
|
) {
|
||||||
val (vx, vy, vz) = ply.getViewVector(1f)
|
val (vx, vy, vz) = ply.getViewVector(1f)
|
||||||
val nearest = Direction.getNearest(vx, vy, vz)
|
val nearest = Direction.getNearest(vx, vy, vz)
|
||||||
|
|
||||||
if (nearest != Direction.UP && nearest != Direction.DOWN) {
|
if (nearest != Direction.UP && nearest != Direction.DOWN) {
|
||||||
// attempt one
|
// attempt one
|
||||||
val phasedBlocks = ArrayList<BlockPos>(ServerConfig.EnderTeleporter.MAX_PHASE_DISTANCE)
|
var phaseResult = tryToPhaseThroughWall(result.blockPos, nearest.normal)
|
||||||
var phaseResult = tryToPhaseThroughWall(result.blockPos, nearest.normal, phasedBlocks)
|
|
||||||
|
|
||||||
if (phaseResult != null) {
|
if (phaseResult != null) {
|
||||||
candidates.add(phaseResult)
|
candidates.add(phaseResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt two
|
// attempt two
|
||||||
phaseResult = tryToPhaseThroughWall(result.blockPos, result.direction.opposite.normal, phasedBlocks)
|
phaseResult = tryToPhaseThroughWall(result.blockPos, result.direction.opposite.normal)
|
||||||
|
|
||||||
if (phaseResult != null) {
|
if (phaseResult != null) {
|
||||||
candidates.add(phaseResult)
|
candidates.add(phaseResult)
|
||||||
@ -197,16 +204,34 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (y in (if (ply.level.getBlockState(result.blockPos).`is`(BlockTags.CLIMBABLE)) -1 else 0) .. ServerConfig.EnderTeleporter.MAX_PHASE_DISTANCE) {
|
var phasedBlocks = 0
|
||||||
val pos = BlockPos(result.blockPos.x, result.blockPos.y + y + 1, result.blockPos.z)
|
val phasedBlocksList = ArrayList<BlockPos>()
|
||||||
|
|
||||||
if (ply.level.getBlockState(pos).`is`(Blocks.BEDROCK)) {
|
for (y in (if (ply.level.getBlockState(result.blockPos).`is`(BlockTags.CLIMBABLE)) -1 else 0) .. ply.level.maxBuildHeight - ply.level.minBuildHeight) {
|
||||||
|
val pos = BlockPos(result.blockPos.x, result.blockPos.y + y + 1, result.blockPos.z)
|
||||||
|
val state = ply.level.getBlockState(pos)
|
||||||
|
|
||||||
|
if (state.`is`(Blocks.BEDROCK)) {
|
||||||
// Can't phase through bedrock
|
// Can't phase through bedrock
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidPosition(pos) && shortestDistanceBetween(testPositions, pos.asVector()) <= ServerConfig.EnderTeleporter.MAX_DISTANCE) {
|
if (!isAirGap(pos)) {
|
||||||
candidates.add(TraceResult(pos, if (y != 0) ImmutableList(y + 1) { result.blockPos + BlockPos(0, it, 0) } else listOf()))
|
phasedBlocks++
|
||||||
|
|
||||||
|
if (phasedBlocks >= ServerConfig.EnderTeleporter.MAX_PHASE_DISTANCE) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
phasedBlocksList.add(pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shortestDistanceBetween(testPositions, pos.asVector()) > ServerConfig.EnderTeleporter.MAX_DISTANCE) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isValidPosition(pos)) {
|
||||||
|
candidates.add(TraceResult(pos, phasedBlocksList))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,16 +258,34 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
|
|||||||
// no valid positions...
|
// no valid positions...
|
||||||
if (isAirGap(result.blockPos)) {
|
if (isAirGap(result.blockPos)) {
|
||||||
// try to find ground below...
|
// try to find ground below...
|
||||||
for (y in 0 downTo -ServerConfig.EnderTeleporter.MAX_PHASE_DISTANCE) {
|
phasedBlocks = 0
|
||||||
val pos = BlockPos(result.blockPos.x, result.blockPos.y + y, result.blockPos.z)
|
phasedBlocksList.clear()
|
||||||
|
|
||||||
if (ply.level.getBlockState(pos).`is`(Blocks.BEDROCK)) {
|
for (y in 0 downTo ply.level.maxBuildHeight - ply.level.minBuildHeight) {
|
||||||
|
val pos = BlockPos(result.blockPos.x, result.blockPos.y + y, result.blockPos.z)
|
||||||
|
val state = ply.level.getBlockState(pos)
|
||||||
|
|
||||||
|
if (state.`is`(Blocks.BEDROCK)) {
|
||||||
// Can't phase through bedrock
|
// Can't phase through bedrock
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidPosition(pos) && shortestDistanceBetween(testPositions, pos.asVector()) <= ServerConfig.EnderTeleporter.MAX_DISTANCE) {
|
if (!isAirGap(pos)) {
|
||||||
return TraceResult(pos, if (y != 0) ImmutableList(-y + 1) { result.blockPos - BlockPos(0, it, 0) } else listOf())
|
phasedBlocks++
|
||||||
|
|
||||||
|
if (phasedBlocks >= ServerConfig.EnderTeleporter.MAX_PHASE_DISTANCE) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
phasedBlocksList.add(pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shortestDistanceBetween(testPositions, pos.asVector()) > ServerConfig.EnderTeleporter.MAX_DISTANCE) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isValidPosition(pos)) {
|
||||||
|
return TraceResult(pos, phasedBlocksList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user