Skip to content

Commit

Permalink
0.2 update
Browse files Browse the repository at this point in the history
- renamed to FBorder-Addon
- fixed vertical lines not being affected by the performance setting
- particle count is now reduced logarithmically by the amount of shapes drawn
  • Loading branch information
Braffolk committed Oct 25, 2020
1 parent 165169e commit 77e8d57
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project exclude paths
/target/
dependency-reduced-pom.xml
FBorderVisualiser-Addon.iml
FBorder.iml
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FBorderVisualiser-Addon
# FBorder-Addon
Minecraft plugin [FactionsX](https://www.spigotmc.org/resources/factionsx.83459/) addon that visualises faction borders using particles and colours them according to faction relations.

![faction with borders visualised](https://i.imgur.com/5i72ii2.png "Example faction")
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>FBorderVisualiser-Addon</artifactId>
<version>v0.1-1.0.8-RC</version>
<artifactId>FBorder-Addon</artifactId>
<version>v0.2-1.0.8-RC</version>

<properties>
<kotlin.version>1.4.10</kotlin.version>
Expand Down
57 changes: 32 additions & 25 deletions src/main/kotlin/VisualisationHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,14 @@ class VisualisationHandler {

val eyeY = player.eyeLocation.y.toLong()
val verticalRange = max(0, (eyeY - 32) / 64 * 64)..min((eyeY + 64) / 64 * 64, 256)
val maxRenderDistance = (player.clientViewDistance * 16).toDouble().pow(2).toLong()
val maxRenderDistance = (Bukkit.getViewDistance() * 16).toDouble().pow(2).toLong()

val performanceNumber = when (playerPerformanceMap[player.uniqueId]) {
val playerPerformanceF = when (playerPerformanceMap[player.uniqueId]) {
VisualisationPerformance.Fast -> 4.0
VisualisationPerformance.Normal -> 2.0
VisualisationPerformance.Fancy -> 1.0
else -> 2.0
}
val calculateStep = { diff: Double -> max(performanceNumber, abs(diff) / (10 - performanceNumber)) }

val bottomStep = calculateStep((eyeY - verticalRange.first).toDouble())
val topStep = calculateStep((eyeY - verticalRange.last).toDouble())

FactionManager.getFactions().forEach { faction ->
if (!faction.isSystemFaction()) {
Expand All @@ -103,28 +99,42 @@ class VisualisationHandler {
(factionColor.blue - 48).coerceAtLeast(0)
)

// get all lines and planes to be rendered
val outerCorners = shapeCache.getFactionOuterCorners(faction, worldName)
val innerCorners = shapeCache.getFactionInnerCorners(faction, worldName)

val zLines = shapeCache.getFactionZLines(faction, worldName)
val xLines = shapeCache.getFactionXLines(faction, worldName)

val horisontalPlanes = shapeCache.getFactionChunks(faction, worldName)

val shapeCount = outerCorners.size + innerCorners.size + xLines.size + zLines.size + horisontalPlanes.size
val dynamicPerformanceF = (log(shapeCount.toDouble(), 8.0 - playerPerformanceF) - 2.0).coerceAtLeast(0.0)
val performanceF = playerPerformanceF + dynamicPerformanceF

// dusts for top and bottom planes
val calculateStep = { diff: Double -> max(performanceF, abs(diff) / (10 - performanceF)) }
val bottomStep = calculateStep((eyeY - verticalRange.first).toDouble())
val topStep = calculateStep((eyeY - verticalRange.last).toDouble())

val bottomDust = Particle.DustOptions(factionColor, bottomStep.toFloat())
val topDust = Particle.DustOptions(factionColor, topStep.toFloat())

// visualise vertical corner lines
listOf(
shapeCache.getFactionOuterCorners(faction, worldName),
shapeCache.getFactionInnerCorners(faction, worldName)
).zip(listOf(factionColor, factionColorDark))
.forEach { (lines, color) ->
listOf(outerCorners, innerCorners).zip(listOf(factionColor, factionColorDark))
.forEach { (lines, wantedColor) ->
lines.zip(lines.map {
val loc = Location(player.world, it.x.toDouble(), eyeY.toDouble(), it.z.toDouble())
player.location.distanceSquared(loc)
})
.filter { it.second < maxRenderDistance }
.forEach { (line, distance) ->
var y = verticalRange.first.toDouble()
val step = (distance / (maxRenderDistance * (dynamicPerformanceF + 1.0)) * 16 + performanceF).coerceAtLeast(1.0)
while (true) {
val step = (distance / maxRenderDistance * 16).coerceAtLeast(1.0)
y += step
if (y > verticalRange.last) {
break
}
if (y > verticalRange.last) { break }
val color = if(Math.random() < 0.2) { Color.BLACK } else { wantedColor }

val dust = Particle.DustOptions(color, step.coerceAtLeast(2.0).toFloat())

player.spawnParticle(
Expand All @@ -133,15 +143,13 @@ class VisualisationHandler {
0,
dust
)
y += step
}
}
}

// horisontal line at eye height
listOf(
shapeCache.getFactionZLines(faction, worldName),
shapeCache.getFactionXLines(faction, worldName)
).forEach { lines ->
listOf(zLines, xLines).forEach { lines ->
lines
.zip(lines.map {
val loc = Location(player.world,
Expand All @@ -154,26 +162,25 @@ class VisualisationHandler {
.forEach { (line, distance) ->
val size = (distance / maxRenderDistance * 16).coerceAtLeast(2.0)
val eyeDust = Particle.DustOptions(factionColor, size.toFloat())
val step = (distance / (maxRenderDistance * (dynamicPerformanceF + 1.0)) * 16 + performanceF).coerceAtLeast(1.0)

for (x in line.p1.x..line.p2.x step (1 + performanceNumber).toLong()) {
for (z in line.p1.z..line.p2.z step (1 + performanceNumber).toLong()) {
for (x in line.p1.x..line.p2.x step step.toLong()) {
for (z in line.p1.z..line.p2.z step step.toLong()) {
createParticle(player, x, eyeY + 1, z, eyeDust)
}
}
}
}

// bottom and top plane
val horisontalPlanes = shapeCache.getFactionChunks(faction, worldName)

horisontalPlanes
.zip(horisontalPlanes.map {
val loc = Location(player.world, (it.x * 16 + 8).toDouble(), eyeY.toDouble(), (it.z * 16 + 8).toDouble())
player.location.distanceSquared(loc)
})
.filter { (loc, distance) -> distance < maxRenderDistance }
.forEach { (loc, distance) ->
var step = floor(5.0 - performanceNumber / 2)
var step = floor(5.0 - performanceF / 2 - dynamicPerformanceF * distance/maxRenderDistance).coerceAtLeast(2.0)
repeat(step.toInt()) { x ->
repeat(step.toInt()) { z ->
val px = loc.x * 16 + (x / (step - 1) * 16.0)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/addon.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Name of the addon, basically like a spigot plugin name.
name=FBorderVisualiser-Addon
name=FBorder-Addon
# Main class of the addon, like a spigot plugin main class.
main=ee.braffolk.factionsx.BorderVisualiser

0 comments on commit 77e8d57

Please sign in to comment.