Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
compile
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJuri committed Sep 7, 2023
1 parent 70e61a5 commit 0956ac4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/main/kotlin/dev/macrohq/swiftslayer/SwiftSlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class SwiftSlayer {
MinecraftForge.EVENT_BUS.register(pathExecutor)
MinecraftForge.EVENT_BUS.register(mobKiller)
MinecraftForge.EVENT_BUS.register(autoBatphone)
MinecraftForge.EVENT_BUS.register(autoSlayer)
CommandManager.register(PathfindTest())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AStarPathfinder(startPos: BlockPos, endPos: BlockPos) {
private var startNode: Node
private var endNode: Node
private val openNodes = mutableListOf<Node>()
private val closedNodes= mutableListOf<Node>()
private val closedNodes = mutableListOf<Node>()

init {
startNode = Node(startPos, null)
Expand All @@ -25,7 +25,9 @@ class AStarPathfinder(startPos: BlockPos, endPos: BlockPos) {
startNode.calculateCost(endNode)
openNodes.add(startNode)
for (i in 0 until iterations) {
val currentNode = openNodes.stream().min(Comparator.comparingDouble { it.getFCost().toDouble() }).orElse(null) ?: return listOf()
val currentNode =
openNodes.stream().min(Comparator.comparingDouble { it.getFCost().toDouble() }).orElse(null)
?: return listOf()
if (currentNode.position == endNode.position) return reconstructPath(currentNode)
openNodes.remove(currentNode)
closedNodes.add(currentNode)
Expand All @@ -48,16 +50,16 @@ class AStarPathfinder(startPos: BlockPos, endPos: BlockPos) {
// return path

val smooth = mutableListOf<BlockPos>()
if(path.isNotEmpty()){
if (path.isNotEmpty()) {
smooth.add(path[0])
var currPoint = 0
var maxiters = 2000

while(currPoint+1 < path.size && maxiters-->0){
while (currPoint + 1 < path.size && maxiters-- > 0) {
var nextPos = currPoint + 1

for(i in (path.size-1) downTo nextPos){
if(BlockUtil.blocksBetweenValid(path[currPoint], path[i])){
for (i in (path.size - 1) downTo nextPos) {
if (BlockUtil.blocksBetweenValid(path[currPoint], path[i])) {
nextPos = i
break
}
Expand All @@ -83,12 +85,14 @@ class AStarPathfinder(startPos: BlockPos, endPos: BlockPos) {
}
return yaw
}

private fun angleCost(bp1: BlockPos, bp2: BlockPos): Float {
val dx = bp2.x - bp1.x
val dz = bp2.z - bp1.z
val yaw = -Math.toDegrees(atan2(dx.toDouble(), dz.toDouble())).toFloat()
return AngleUtil.yawTo360(yaw)
}

fun calculateCost(endNode: Node) {
var cost = 0f
if (this.parent != null) {
Expand All @@ -102,10 +106,10 @@ class AStarPathfinder(startPos: BlockPos, endPos: BlockPos) {
cost += 1.5f
}

if(BlockUtil.isStairSlab(this.position)) cost -= 1f
if (BlockUtil.isStairSlab(this.position)) cost -= 1f
}
BlockUtil.neighbourGenerator(this.position.up().up().up(), 1).forEach{
if(world.isBlockFullCube(it)) cost += 1.5f
BlockUtil.neighbourGenerator(this.position.up().up().up(), 1).forEach {
if (world.isBlockFullCube(it)) cost += 1.5f
}
this.gCost = if (this.parent != null) sqrt(this.parent.position.distanceSq(this.position)).toFloat()
else 0f
Expand All @@ -115,7 +119,7 @@ class AStarPathfinder(startPos: BlockPos, endPos: BlockPos) {

fun getFCost() = gCost + hCost

fun getNeighbours() : List<Node> {
fun getNeighbours(): List<Node> {
val neighbours = mutableListOf<Node>()
BlockUtil.neighbourGenerator(this.position, -1, 1, -3, 3, -1, 1).forEach {
val newNode = Node(it, this)
Expand All @@ -127,8 +131,8 @@ class AStarPathfinder(startPos: BlockPos, endPos: BlockPos) {
fun isWalkable(): Boolean {
var collision = false
var headhit = false
if(this.parent!=null && this.parent.position.y < this.position.y){
if(!allowedBlocks.contains(world.getBlockState(this.parent.position.add(0,3,0)).block)){
if (this.parent != null && this.parent.position.y < this.position.y) {
if (!allowedBlocks.contains(world.getBlockState(this.parent.position.add(0, 3, 0)).block)) {
headhit = true
}
}
Expand Down

0 comments on commit 0956ac4

Please sign in to comment.