Use NMS to get the block type much faster and update/fix dependencies #7

Merged
SKBotNL merged 7 commits from main into main 2026-01-22 08:27:58 -05:00
3 changed files with 22 additions and 11 deletions

No files matched your search

+8 -2
View File
@@ -2,7 +2,8 @@ import java.io.BufferedReader
plugins {
eclipse
kotlin("jvm") version "2.1.21"
kotlin("jvm") version "2.2.20"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.18"
id("com.diffplug.spotless") version "8.1.0"
id("com.gradleup.shadow") version "8.3.9"
}
@@ -32,12 +33,17 @@ repositories {
}
dependencies {
paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
implementation("com.github.retrooper:packetevents-spigot:2.9.5")
implementation("com.github.retrooper:packetevents-spigot:2.11.1")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}
paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION
tasks {
assemble { dependsOn(reobfJar) }
build {
dependsOn(spotlessApply)
dependsOn(shadowJar)
@@ -113,13 +113,5 @@ class AntiPieRay : JavaPlugin() {
override fun onDisable() {
Bukkit.getScheduler().cancelTasks(this)
PacketEvents.getAPI().terminate()
while (getActiveTasks() > 0) {
Thread.sleep(25)
}
}
fun getActiveTasks(): Int {
return Bukkit.getScheduler().activeWorkers.count { it.owner == this }
}
}
@@ -5,10 +5,14 @@ import java.util.concurrent.ConcurrentHashMap
import kotlin.math.abs
import kotlin.math.ceil
import kotlin.math.min
import net.minecraft.core.BlockPos
import net.minecraft.server.level.ServerLevel
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.World
import org.bukkit.block.Block
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld
import org.bukkit.entity.Player
import org.bukkit.util.BlockIterator
import org.bukkit.util.Vector
@@ -85,6 +89,15 @@ class BlockEntityHider {
Vector(-0.49, -0.49, -0.49),
)
val Block.typeFast: Material
get() {
val craftWorld = (world as CraftWorld).handle
val serverChunkCache = (craftWorld as ServerLevel).getChunkSource()
val chunk = serverChunkCache.getChunkAtIfLoadedMainThread(this.x shr 4, this.z shr 4)
val blockState = chunk.getBlockState(BlockPos(this.x, this.y, this.z))
return blockState.bukkitMaterial
}
fun canSee(eye: Location, loc: Location): Set<BlockPosition>? {
// Get the center
val blockCenterLoc = loc.clone().add(0.5, 0.5, 0.5)
@@ -125,7 +138,7 @@ class BlockEntityHider {
if (hitBlock == loc.block) {
break
}
val hitBlockType = hitBlock.type
val hitBlockType = hitBlock.typeFast
if (!isAir(hitBlockType) && !isLiquid(hitBlockType) && !isTransparent(hitBlockType)) {
if (eyeOffset == Vector(0, 0, 0)) {
blockingBlocks += hitBlock.location.toBlockPosition()