-
-
Notifications
You must be signed in to change notification settings - Fork 216
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
RevengeLordOfMaj
wants to merge
21
commits into
hannibal002:beta
Choose a base branch
from
RevengeLordOfMaj:Berberis-Rework
base: beta
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−15
Open
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
40636dd
Initial Rework
RevengeLordOfMaj 09933a7
Detekt Fixes
RevengeLordOfMaj 739b8fd
Final Detekt Fixes Please
RevengeLordOfMaj c680061
Fallback System
RevengeLordOfMaj fcecd08
Detekt
RevengeLordOfMaj 12b8a4a
Detekt Once More
RevengeLordOfMaj 486350a
Merge branch 'refs/heads/beta' into fork/RevengeLordOfMaj/Berberis-Re…
hannibal002 3bf04aa
formatting
hannibal002 9558018
code cleanup
hannibal002 d4390aa
Cleanup and QOL
RevengeLordOfMaj 67bc299
Sorry mister detekt sir
RevengeLordOfMaj e31bcf5
Config Version
RevengeLordOfMaj 6e5d77d
Merge branch 'refs/heads/beta' into fork/RevengeLordOfMaj/Berberis-Re…
hannibal002 92c7f03
code cleanup
hannibal002 0ed8811
Merge branch 'beta' into Berberis-Rework
CalMWolfs 3f04b13
Merge branch 'beta' into Berberis-Rework
CalMWolfs af18940
Merge branch 'beta' into Berberis-Rework
CalMWolfs a35e02c
Merge branch 'beta' into Berberis-Rework
CalMWolfs a90fe07
Merge branch 'beta' into Berberis-Rework
CalMWolfs f320b52
Merge branch 'refs/heads/beta' into fork/RevengeLordOfMaj/Berberis-Re…
hannibal002 fc19acb
code cleanup
hannibal002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,48 +20,136 @@ 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.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 | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
@SkyHanniModule | ||
object RiftWiltedBerberisHelper { | ||
// not a great programmer, but it's better than nothing :p -maj | ||
|
||
private val config get() = RiftAPI.config.area.dreadfarm.wiltedBerberis | ||
private var isOnFarmland = false | ||
private var hasFarmingToolInHand = false | ||
|
||
// list of berberis in the current plot, in the order they appeared in | ||
private var berberisList = listOf<LorenzVec>() | ||
private var lastSpawn = SimpleTimeMark.now() | ||
private var lastSyncedAt = SimpleTimeMark.now() | ||
private var lastUpdated = SimpleTimeMark.now() | ||
|
||
// array of 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)), | ||
) | ||
|
||
// the closest plot to the player | ||
private var closestPlot = 0 | ||
|
||
// the closest plot to the player last tick | ||
private var oldClosest = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change those two variable sto be of type |
||
|
||
data class Plot(var c1: LorenzVec, var c2: LorenzVec) | ||
RevengeLordOfMaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private var fallback = false | ||
|
||
// original system stuff: | ||
private var list = listOf<WiltedBerberis>() | ||
|
||
data class WiltedBerberis(var currentParticles: LorenzVec) { | ||
|
||
var previous: LorenzVec? = null | ||
var moving = true | ||
var y = 0.0 | ||
var lastTime = SimpleTimeMark.now() | ||
} | ||
|
||
private fun nearestBerberis(location: LorenzVec): WiltedBerberis? = | ||
list.filter { it.currentParticles.distanceSq(location) < 8 } | ||
.minByOrNull { it.currentParticles.distanceSq(location) } | ||
|
||
private fun LorenzVec.fixLocation(wiltedBerberis: WiltedBerberis): LorenzVec { | ||
val x = x - 0.5 | ||
val y = wiltedBerberis.y | ||
val z = z - 0.5 | ||
return LorenzVec(x, y, z) | ||
} | ||
// end original system stuff | ||
|
||
@SubscribeEvent | ||
fun onTick(event: LorenzTickEvent) { | ||
RevengeLordOfMaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!isEnabled()) return | ||
if (!event.isMod(5)) return | ||
|
||
list = list.editCopy { removeIf { it.lastTime.passedSince() > 500.milliseconds } } | ||
// 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) plotDistances[i] = LocationUtils.playerLocation().distance(plots[i].c1.middle(plots[i].c2)) | ||
RevengeLordOfMaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (i in 0..5) if (plotDistances[i] < plotDistances[closestPlot]) closestPlot = i | ||
|
||
// 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 | ||
for (block in BlockPos.getAllInBox(plots[closestPlot].c1.toBlockPos(), plots[closestPlot].c2.toBlockPos())) { | ||
RevengeLordOfMaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (block.toLorenzVec().getBlockAt() == Blocks.deadbush && !berberisList.contains(block.toLorenzVec())) { | ||
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() | ||
} | ||
|
||
// 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 | ||
if (berberisList.isEmpty()) fallback = false | ||
|
||
// get if player holding farming wand | ||
RevengeLordOfMaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hasFarmingToolInHand = InventoryUtils.getItemInHand()?.getInternalName() == RiftAPI.farmingTool | ||
|
||
// get if player is on farmland | ||
if (Minecraft.getMinecraft().thePlayer.onGround) { | ||
val block = LorenzVec.getBlockBelowPlayer().getBlockAt() | ||
val currentY = LocationUtils.playerLocation().y | ||
isOnFarmland = block == Blocks.farmland && (currentY % 1 == 0.0) | ||
} | ||
} | ||
|
||
private fun nearestBerberis(location: LorenzVec): WiltedBerberis? = | ||
list.filter { it.currentParticles.distanceSq(location) < 8 } | ||
.minByOrNull { it.currentParticles.distanceSq(location) } | ||
// original system stuff: | ||
list = list.editCopy { removeIf { it.lastTime.passedSince() > 500.milliseconds } } | ||
|
||
} | ||
|
||
@SubscribeEvent | ||
fun onReceiveParticle(event: ReceiveParticleEvent) { | ||
|
@@ -71,17 +159,19 @@ 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 just get cancelled, but the below code runs on them | ||
if (config.hideParticles) { | ||
event.cancel() | ||
} | ||
|
||
// original system stuff: | ||
if (berberis == null) { | ||
list = list.editCopy { add(WiltedBerberis(location)) } | ||
return | ||
|
@@ -105,11 +195,13 @@ object RiftWiltedBerberisHelper { | |
moving = isMoving | ||
currentParticles = location | ||
lastTime = SimpleTimeMark.now() | ||
// end original system stuff | ||
} | ||
} | ||
|
||
@HandleEvent | ||
fun onPlaySound(event: PlaySoundEvent) { | ||
// mute sounds if setting on | ||
if (!isMuteOthersSoundsEnabled()) return | ||
val soundName = event.soundName | ||
|
||
|
@@ -122,26 +214,54 @@ object RiftWiltedBerberisHelper { | |
fun onRenderWorld(event: LorenzRenderWorldEvent) { | ||
if (!isEnabled()) return | ||
if (!hasFarmingToolInHand) return | ||
|
||
if (config.onlyOnFarmland && !isOnFarmland) return | ||
|
||
for (berberis in list) { | ||
with(berberis) { | ||
if (currentParticles.distanceToPlayer() > 20) continue | ||
if (y == 0.0) continue | ||
// original system: | ||
if (fallback) { | ||
RevengeLordOfMaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.drawDynamicText(location.up(), "§eWilted Berberis", 1.5, ignoreBlocks = false) | ||
} else { | ||
event.drawFilledBoundingBoxNea(axisAlignedBB(location), Color.WHITE, 0.5f) | ||
previous?.fixLocation(berberis)?.let { | ||
event.drawFilledBoundingBoxNea(axisAlignedBB(it), Color.LIGHT_GRAY, 0.2f) | ||
event.draw3DLine(it.add(0.5, 0.0, 0.5), location.add(0.5, 0.0, 0.5), Color.WHITE, 3, false) | ||
val location = currentParticles.fixLocation(berberis) | ||
if (!moving) { | ||
event.drawFilledBoundingBoxNea(axisAlignedBB(location), Color.YELLOW, 0.7f) | ||
event.drawDynamicText(location.up(), "§eWilted Berberis", 1.5, ignoreBlocks = false) | ||
} else { | ||
event.drawFilledBoundingBoxNea(axisAlignedBB(location), Color.WHITE, 0.5f) | ||
previous?.fixLocation(berberis)?.let { | ||
event.drawFilledBoundingBoxNea(axisAlignedBB(it), Color.LIGHT_GRAY, 0.2f) | ||
event.draw3DLine(it.add(0.5, 0.0, 0.5), location.add(0.5, 0.0, 0.5), Color.WHITE, 3, false) | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
// new system | ||
if (berberisList.isNotEmpty()) { | ||
|
||
var alpha = 0.8f | ||
var previousBerberis: LorenzVec? = null | ||
event.drawDynamicText(berberisList[0].up(), "§eWilted Berberis", 1.5, ignoreBlocks = false) | ||
|
||
// for the first 3 berberis | ||
for (i in 0..(berberisList.size - 1).coerceAtMost(2)) { | ||
// box it with half the opacity of the previous box, first in list is yellow | ||
if (i == 0) event.drawFilledBoundingBoxNea(axisAlignedBB(berberisList[i]), Color.YELLOW, alpha) | ||
else event.drawFilledBoundingBoxNea(axisAlignedBB(berberisList[i]), Color.WHITE, alpha) | ||
alpha /= 2f | ||
|
||
// if there's a previous berberis, draw a line to it. The line from the 2nd to the 1st should be yellow | ||
if (i == 1) previousBerberis?.let { | ||
event.draw3DLine(berberisList[i].add(0.5, 0.5, 0.5), it.add(0.5, 0.5, 0.5), Color.YELLOW, 4, false) | ||
} | ||
else previousBerberis?.let { | ||
event.draw3DLine(berberisList[i].add(0.5, 0.5, 0.5), it.add(0.5, 0.5, 0.5), Color.WHITE, 2, false) | ||
} | ||
|
||
previousBerberis = berberisList[i] | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -152,13 +272,6 @@ object RiftWiltedBerberisHelper { | |
|
||
private fun axisAlignedBB(loc: LorenzVec) = loc.add(0.1, -0.1, 0.1).boundingToOffset(0.8, 1.0, 0.8).expandBlock() | ||
|
||
private fun LorenzVec.fixLocation(wiltedBerberis: WiltedBerberis): LorenzVec { | ||
val x = x - 0.5 | ||
val y = wiltedBerberis.y | ||
val z = z - 0.5 | ||
return LorenzVec(x, y, z) | ||
} | ||
|
||
private fun isEnabled() = RiftAPI.inRift() && RiftAPI.inDreadfarm() && config.enabled | ||
|
||
private fun isMuteOthersSoundsEnabled() = RiftAPI.inRift() && | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
give this
list
below better names to differentiate