Skip to content

Commit

Permalink
Fix FakeEntity Tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
noonmaru committed Sep 30, 2020
1 parent 1aa3858 commit 6e7df8b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ class FakeEntityImpl internal constructor(
}

internal fun offerComputeQueue(tracker: FakeTracker) {
if (tracker in trackers) {
computeTracker(tracker)
}

if (updateTrackers)
return

Expand Down Expand Up @@ -375,16 +379,16 @@ class FakeEntityImpl internal constructor(
if (!tracker.valid) return

if (isVisible && tracker.player !in exclusion) {
val spawnDistance = 240.0 * 240.0
val despawnDistance = 256.0 * 256.0
val entityLocation = currentLocation
val spawnDistanceSquared = 240.0 * 240.0
val despawnDistanceSquared = 256.0 * 256.0
val entityLocation = deltaLocation
val trackerLocation = tracker.location

if (entityLocation.world === trackerLocation.world) {
val distance = entityLocation.distance(trackerLocation)
val distanceSquared = entityLocation.distanceSquared(trackerLocation)

if (distance < despawnDistance) {
if (distance < spawnDistance && trackers.add(tracker)) {
if (distanceSquared < despawnDistanceSquared) {
if (distanceSquared < spawnDistanceSquared && trackers.add(tracker)) {
tracker.addEntity(this)
spawnTo(tracker.player)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

kotlin.code.style=official
group=com.github.noonmaru
version=3.1.6
version=3.1.7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,60 @@ class TapPlugin : JavaPlugin() {
)
}
}

// val server = FakeEntityServer.create(this)
// val test = Test(server)
// this.server.pluginManager.registerEvents(test, this)
// this.server.scheduler.runTaskTimer(this, test, 0L, 1L)
}
}
}

//class Test(
// private val server: FakeEntityServer
//): Runnable, Listener {
//
// private val map = HashMap<Player, FakeEntity>()
//
// init {
// Bukkit.getOnlinePlayers().forEach { register(it)}
// }
//
// private fun register(player: Player) {
// val loc = player.location
// val armorStand = server.spawnEntity(loc, ArmorStand::class.java).apply {
// updateMetadata<ArmorStand> {
// isMarker = true
// }
// }
// val item = server.spawnEntity(loc, Item::class.java).apply {
// updateMetadata<Item> {
// setItemStack(ItemStack(Material.STONE))
// }
// }
// armorStand.addPassenger(item)
//
// map[player] = armorStand
// server.addPlayer(player)
// }
//
// @EventHandler
// fun onJoin(event: PlayerJoinEvent) {
// register(event.player)
// }
//
// @EventHandler
// fun onQuit(event: PlayerQuitEvent) {
// map.remove(event.player)?.let { it ->
// it.passengers.forEach { it.remove() }
// it.remove()
// }
// }
//
// override fun run() {
// for ((player, entity) in map) {
// entity.moveTo(player.eyeLocation.add(0.0, 1.0, 0.0))
// }
//
// server.update()
// }
//}

0 comments on commit 6e7df8b

Please sign in to comment.