Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Berberis Helper Rework #3147

Open
wants to merge 28 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
40636dd
Initial Rework
RevengeLordOfMaj Jan 2, 2025
09933a7
Detekt Fixes
RevengeLordOfMaj Jan 2, 2025
739b8fd
Final Detekt Fixes Please
RevengeLordOfMaj Jan 2, 2025
c680061
Fallback System
RevengeLordOfMaj Jan 3, 2025
fcecd08
Detekt
RevengeLordOfMaj Jan 3, 2025
12b8a4a
Detekt Once More
RevengeLordOfMaj Jan 3, 2025
486350a
Merge branch 'refs/heads/beta' into fork/RevengeLordOfMaj/Berberis-Re…
hannibal002 Jan 4, 2025
3bf04aa
formatting
hannibal002 Jan 4, 2025
9558018
code cleanup
hannibal002 Jan 4, 2025
d4390aa
Cleanup and QOL
RevengeLordOfMaj Jan 5, 2025
67bc299
Sorry mister detekt sir
RevengeLordOfMaj Jan 5, 2025
e31bcf5
Config Version
RevengeLordOfMaj Jan 6, 2025
6e5d77d
Merge branch 'refs/heads/beta' into fork/RevengeLordOfMaj/Berberis-Re…
hannibal002 Jan 7, 2025
92c7f03
code cleanup
hannibal002 Jan 7, 2025
0ed8811
Merge branch 'beta' into Berberis-Rework
CalMWolfs Jan 8, 2025
3f04b13
Merge branch 'beta' into Berberis-Rework
CalMWolfs Jan 10, 2025
af18940
Merge branch 'beta' into Berberis-Rework
CalMWolfs Jan 12, 2025
a35e02c
Merge branch 'beta' into Berberis-Rework
CalMWolfs Jan 16, 2025
a90fe07
Merge branch 'beta' into Berberis-Rework
CalMWolfs Jan 16, 2025
f320b52
Merge branch 'refs/heads/beta' into fork/RevengeLordOfMaj/Berberis-Re…
hannibal002 Jan 25, 2025
fc19acb
code cleanup
hannibal002 Jan 25, 2025
c552785
Code Cleanup
RevengeLordOfMaj Jan 27, 2025
214c9b3
Hope this works
RevengeLordOfMaj Jan 27, 2025
833ff52
Hope this works x2
RevengeLordOfMaj Jan 27, 2025
c6fc8cc
Code Cleanup
RevengeLordOfMaj Jan 30, 2025
971b32d
Oops left the debugging stuff in
RevengeLordOfMaj Jan 30, 2025
cbf8989
Removed Redundant Variable
RevengeLordOfMaj Jan 30, 2025
d4c4a43
Removed Unnecessary Import (forgor)
RevengeLordOfMaj Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {

val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 70
const val CONFIG_VERSION = 71
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorColour;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

import java.awt.Color;

public class WiltedBerberisConfig {

@Expose
Expand All @@ -27,4 +31,14 @@ public class WiltedBerberisConfig {
@ConfigOption(name = "Mute Others Sounds", desc = "Mute nearby Wilted Berberis sounds while not holding a Wand of Farming or not standing on Farmland blocks.")
@ConfigEditorBoolean
public boolean muteOthersSounds = true;

@Expose
@ConfigOption(name = "Future Preview Count", desc = "How many future Wilted Berberis locations to preview.")
@ConfigEditorSlider(minValue = 0, maxValue = 8, minStep = 1)
public int previewCount = 2;

@Expose
@ConfigOption(name = "Highlight Color", desc = "What color to highlight the next Wilted Berberis to break.")
@ConfigEditorColour
public String highlightColor = "0:255:255:255:0";
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.drawFilledBoundingBoxNea
import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import at.hannibal2.skyhanni.utils.toLorenzVec
import net.minecraft.client.Minecraft
import net.minecraft.init.Blocks
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumParticleTypes
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
Expand All @@ -33,10 +36,30 @@ object RiftWiltedBerberisHelper {
private val config get() = RiftAPI.config.area.dreadfarm.wiltedBerberis
private var isOnFarmland = false
private var hasFarmingToolInHand = false
private var berberisList = listOf<LorenzVec>()
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
private var lastSpawn = SimpleTimeMark.now()
private var lastSyncedAt = SimpleTimeMark.now()
private var lastUpdated = SimpleTimeMark.now()

// the bounds of each berberis plot
private val plots = arrayOf(
Plot(LorenzVec(-54, 71, -128), LorenzVec(-41, 70, -117)),
Plot(LorenzVec(-77, 72, -143), LorenzVec(-59, 71, -125)),
Plot(LorenzVec(-87, 73, -169), LorenzVec(-69, 72, -152)),
Plot(LorenzVec(-72, 73, -191), LorenzVec(-57, 72, -175)),
Plot(LorenzVec(-35, 72, -185), LorenzVec(-22, 71, -171)),
Plot(LorenzVec(-42, 72, -155), LorenzVec(-22, 70, -126)),
)

private var closestPlot = 0
private var oldClosest = 0
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
private var fallback = false

data class Plot(var a: LorenzVec, var b: LorenzVec)

private var list = listOf<WiltedBerberis>()

data class WiltedBerberis(var currentParticles: LorenzVec) {

var previous: LorenzVec? = null
var moving = true
var y = 0.0
Expand All @@ -48,7 +71,9 @@ object RiftWiltedBerberisHelper {
if (!isEnabled()) return
if (!event.isMod(5)) return

list = list.editCopy { removeIf { it.lastTime.passedSince() > 500.milliseconds } }
getClosestPlot()
updateBerberisList()
sync()

hasFarmingToolInHand = InventoryUtils.getItemInHand()?.getInternalName() == RiftAPI.farmingTool

Expand All @@ -59,10 +84,6 @@ object RiftWiltedBerberisHelper {
}
}

private fun nearestBerberis(location: LorenzVec): WiltedBerberis? =
list.filter { it.currentParticles.distanceSq(location) < 8 }
.minByOrNull { it.currentParticles.distanceSq(location) }

@SubscribeEvent
fun onReceiveParticle(event: ReceiveParticleEvent) {
if (!isEnabled()) return
Expand All @@ -71,13 +92,14 @@ object RiftWiltedBerberisHelper {
val location = event.location
val berberis = nearestBerberis(location)

// the purple particles on the edges dont get touched, just cancel them if the setting is on
if (event.type != EnumParticleTypes.FIREWORKS_SPARK) {
if (config.hideParticles && berberis != null) {
event.cancel()
}
return
}

// the firework sparks in the center may get cancelled, but the below code runs on them
if (config.hideParticles) {
event.cancel()
}
Expand Down Expand Up @@ -110,6 +132,7 @@ object RiftWiltedBerberisHelper {

@HandleEvent
fun onPlaySound(event: PlaySoundEvent) {
// mute sounds if setting on
if (!isMuteOthersSoundsEnabled()) return
val soundName = event.soundName

Expand All @@ -122,17 +145,86 @@ object RiftWiltedBerberisHelper {
fun onRenderWorld(event: LorenzRenderWorldEvent) {
if (!isEnabled()) return
if (!hasFarmingToolInHand) return

if (config.onlyOnFarmland && !isOnFarmland) return

if (fallback) fallbackRender(event)
else primaryRender(event)
}

@HandleEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(71, "rift.area.dreadfarm.wiltedBerberis.hideparticles", "rift.area.dreadfarm.wiltedBerberis.hideParticles")
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
}

private fun getClosestPlot() {
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
// calculates the player's distance to the center of each plot, then sets closestPlot to the smallest
val plotDistances = arrayListOf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
for (i in 0..5) {
val plotCenter = plots[i].a.middle(plots[i].b)
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
plotDistances[i] = LocationUtils.playerLocation().distance(plotCenter)
}
for (i in 0..5) if (plotDistances[i] < plotDistances[closestPlot]) closestPlot = i
}

private fun updateBerberisList() {
// if the player enters a new plot, clear the list of berberis locations
if (closestPlot != oldClosest) berberisList = berberisList.editCopy { clear() }
oldClosest = closestPlot

// when a berberis grows in the current plot, add its location to the end of the list
val plotCornerA = plots[closestPlot].a.toBlockPos()
val plotCornerB = plots[closestPlot].b.toBlockPos()
for (block in BlockPos.getAllInBox(plotCornerA, plotCornerB)) {
if (block.toLorenzVec().getBlockAt() == Blocks.deadbush && !berberisList.contains(block.toLorenzVec())) {
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
berberisList = berberisList.editCopy { add(block.toLorenzVec()) }
lastSpawn = SimpleTimeMark.now()
lastUpdated = SimpleTimeMark.now()
}
}

// remove first berberis from list if broken and no berberis have grown in the last 1/4 seccond
// (to stop you from breaking it before they all spawn in)
while (berberisList.isNotEmpty() && berberisList[0].getBlockAt() != Blocks.deadbush && lastSpawn.passedSince() > 250.milliseconds) {
berberisList = berberisList.editCopy { removeFirst() }
lastUpdated = SimpleTimeMark.now()
}

// update the berberis list for the original system
list = list.editCopy { removeIf { it.lastTime.passedSince() > 500.milliseconds } }
}

private fun sync() {
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
// check if the new system is right about which bush to break. If the particle is still moving, assume it's right for now
for (berberis in list) {
with(berberis) {
// if there is a particle in the same place as where the new helper thinks the next bush is,
if (berberisList.isNotEmpty() && (currentParticles.distance(berberisList[0])) < 1.3 &&
currentParticles.distanceToPlayer() <= 20 && y != 0.0
) {
lastSyncedAt = SimpleTimeMark.now()
}
// or if there is a moving particle
if (moving) {
lastSyncedAt = SimpleTimeMark.now()
}
}
}

// if we've been desynced (new system wrong) for more than 2 secconds and the list hasn't updated in that time,
// switch to fallback mode. switch off of fallback once the plot is cleared
if (lastSyncedAt.passedSince() > 1000.milliseconds && lastUpdated.passedSince() > 1000.milliseconds) fallback = true
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
if (berberisList.isEmpty()) fallback = false
}

private fun fallbackRender(event: LorenzRenderWorldEvent) {
for (berberis in list) {
with(berberis) {
if (currentParticles.distanceToPlayer() > 20) continue
if (y == 0.0) continue

val location = currentParticles.fixLocation(berberis)
if (!moving) {
event.drawFilledBoundingBoxNea(axisAlignedBB(location), Color.YELLOW, 0.7f)
event.drawFilledBoundingBoxNea(axisAlignedBB(location), config.highlightColor.toSpecialColor(), 0.7f)
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
event.drawDynamicText(location.up(), "§eWilted Berberis", 1.5, ignoreBlocks = false)
} else {
event.drawFilledBoundingBoxNea(axisAlignedBB(location), Color.WHITE, 0.5f)
Expand All @@ -145,12 +237,36 @@ object RiftWiltedBerberisHelper {
}
}

@HandleEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(60, "rift.area.dreadfarm.wiltedBerberis.hideparticles", "rift.area.dreadfarm.wiltedBerberis.hideParticles")
private fun primaryRender(event: LorenzRenderWorldEvent) {
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
if (berberisList.isEmpty()) return
var alpha = 0.8f
var previousBerberis: LorenzVec? = null
event.drawDynamicText(berberisList[0].up(), "§eWilted Berberis", 1.5, ignoreBlocks = false)

berberisList.take(config.previewCount + 1).forEachIndexed { i, loc ->
// box it with half the opacity of the previous box, first in list is highlighted
if (i == 0) event.drawFilledBoundingBoxNea(axisAlignedBB(loc), config.highlightColor.toSpecialColor(), alpha)
else event.drawFilledBoundingBoxNea(axisAlignedBB(loc), Color.WHITE, alpha)
alpha *= 0.6f

// if there's a previous berberis, draw a line to it. The line from the 2nd to the 1st should be highlighted
if (i == 1) {
previousBerberis?.let {
event.draw3DLine(loc.add(0.5, 0.5, 0.5), it.add(0.5, 0.5, 0.5), config.highlightColor.toSpecialColor(), 4, false)
}
} else {
previousBerberis?.let {
event.draw3DLine(loc.add(0.5, 0.5, 0.5), it.add(0.5, 0.5, 0.5), Color.WHITE, 2, false)
}
}

previousBerberis = loc
}
}

private fun axisAlignedBB(loc: LorenzVec) = loc.add(0.1, -0.1, 0.1).boundingToOffset(0.8, 1.0, 0.8).expandBlock()
private fun nearestBerberis(location: LorenzVec): WiltedBerberis? =
RevengeLordOfMaj marked this conversation as resolved.
Show resolved Hide resolved
list.filter { it.currentParticles.distanceSq(location) < 8 }
.minByOrNull { it.currentParticles.distanceSq(location) }

private fun LorenzVec.fixLocation(wiltedBerberis: WiltedBerberis): LorenzVec {
val x = x - 0.5
Expand All @@ -159,6 +275,8 @@ object RiftWiltedBerberisHelper {
return LorenzVec(x, y, z)
}

private fun axisAlignedBB(loc: LorenzVec) = loc.add(0.1, -0.1, 0.1).boundingToOffset(0.8, 1.0, 0.8).expandBlock()

private fun isEnabled() = RiftAPI.inRift() && RiftAPI.inDreadfarm() && config.enabled

private fun isMuteOthersSoundsEnabled() = RiftAPI.inRift() &&
Expand Down
Loading