Skip to content

Commit e0bc8cc

Browse files
feat: add new Griffin Burrow guess method based on spade
1 parent 26ed9bb commit e0bc8cc

File tree

3 files changed

+146
-45
lines changed

3 files changed

+146
-45
lines changed

src/main/kotlin/gg/skytils/skytilsmod/commands/impl/SkytilsCommand.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ object SkytilsCommand : BaseCommand("skytils", listOf("st")) {
110110
"refresh" -> {
111111
GriffinBurrows.particleBurrows.clear()
112112
}
113+
"clearguess" -> {
114+
GriffinBurrows.BurrowEstimation.guesses.clear()
115+
}
113116

114117
else -> UChat.chat("$prefix §b/skytils griffin <refresh>")
115118
}

src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,13 @@ object Config : Vigilant(
15771577
)
15781578
var burrowEstimation = false
15791579

1580+
@Property(
1581+
type = PropertyType.SWITCH, name = "Griffin Burrow Estimation (MEOW)",
1582+
description = "Estimates griffin burrow position after using spade ANYWHERE. Use of this mode will disable the other mode.",
1583+
category = "Events", subcategory = "Mythological"
1584+
)
1585+
var experimentBurrowEstimation = false
1586+
15801587
@Property(
15811588
type = PropertyType.SWITCH, name = "Broadcast Rare Drop Notifications",
15821589
description = "Sends rare drop notification when you obtain a rare drop from a Mythological Creature.",
@@ -4385,7 +4392,8 @@ object Config : Vigilant(
43854392
"mobBurrowColor",
43864393
"treasureBurrowColor",
43874394
"burrowEstimation",
4388-
"pingNearbyBurrow"
4395+
"pingNearbyBurrow",
4396+
"experimentBurrowEstimation"
43894397
).forEach { propertyName -> addDependency(propertyName, "showGriffinBurrows") }
43904398

43914399
addDependency("activePetColor", "highlightActivePet")

src/main/kotlin/gg/skytils/skytilsmod/features/impl/events/GriffinBurrows.kt

Lines changed: 134 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,23 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
4646
import java.awt.Color
4747
import java.time.Duration
4848
import java.time.Instant
49-
import kotlin.math.PI
50-
import kotlin.math.cos
51-
import kotlin.math.sin
49+
import kotlin.math.*
5250

5351
object GriffinBurrows {
5452
val particleBurrows = hashMapOf<BlockPos, ParticleBurrow>()
5553
var lastDugParticleBurrow: BlockPos? = null
5654
val recentlyDugParticleBurrows = EvictingQueue.create<BlockPos>(5)
5755

5856
var hasSpadeInHotbar = false
57+
var lastSpadeUse = -1L
5958

6059
object BurrowEstimation {
6160
val arrows = mutableMapOf<Arrow, Instant>()
6261
val guesses = mutableMapOf<BurrowGuess, Instant>()
62+
val lastTrail = mutableListOf<Vec3>()
63+
var lastTrailCreated = -1L
64+
var firstDistanceGuess = 0.0
65+
6366
fun getDistanceFromPitch(pitch: Double) =
6467
2805 * pitch - 1375
6568

@@ -70,7 +73,6 @@ object GriffinBurrows {
7073
class Arrow(val directionVector: Vec3, val pos: Vec3)
7174
}
7275

73-
7476
@SubscribeEvent
7577
fun onTick(event: ClientTickEvent) {
7678
if (event.phase != TickEvent.Phase.START) return
@@ -84,6 +86,69 @@ object GriffinBurrows {
8486
BurrowEstimation.arrows.entries.removeIf { (_, instant) ->
8587
Duration.between(instant, Instant.now()).toMillis() > 30_000L
8688
}
89+
if (!Skytils.config.experimentBurrowEstimation) return
90+
if (BurrowEstimation.firstDistanceGuess != -1.0 && BurrowEstimation.lastTrail.size >= 2 && System.currentTimeMillis() - BurrowEstimation.lastTrailCreated > 1000) {
91+
printDevMessage("Trail found ${BurrowEstimation.lastTrail}", "griffinguess")
92+
printDevMessage("Pitch ${BurrowEstimation.firstDistanceGuess}", "griffinguess")
93+
94+
val pitch = BurrowEstimation.firstDistanceGuess
95+
96+
fun cubicFunc(x: Double): Double {
97+
return -355504.3762671333 * x.pow(3) + 573210.5260410917 * x.pow(2) - 304839.7095941929 * x + 53581.7430868503
98+
}
99+
100+
fun logFunc(x: Double): Double {
101+
return 1018.3988994912 + 3301.6178248206 * log10(x)
102+
}
103+
104+
fun linearFunc(x: Double): Double {
105+
return 2760.6568614981 * x - 1355.0749724848
106+
}
107+
108+
val distanceGuessLog = logFunc(pitch)
109+
val distanceGuessC = cubicFunc(pitch)
110+
val distanceGuessL = linearFunc(pitch)
111+
112+
val distanceGuess = if (pitch < 0.5) distanceGuessC else if (pitch > .6) (distanceGuessLog + .1 * distanceGuessL) else {
113+
.45 * distanceGuessC + .5 * distanceGuessLog + (if (pitch > .53) .1 else .05) * distanceGuessL
114+
}
115+
116+
printDevMessage("Distance guess cubic $distanceGuessC log $distanceGuessLog, weighted $distanceGuess", "griffinguess")
117+
118+
val trail = BurrowEstimation.lastTrail.asReversed()
119+
120+
val directionVector = trail[0].subtract(trail[1]).normalize()
121+
printDevMessage("Direction vector $directionVector", "griffinguess")
122+
123+
val guessPos = trail.last().add(
124+
directionVector * distanceGuess
125+
)
126+
printDevMessage("Guess pos $guessPos", "griffinguess")
127+
128+
println("Pitch ${pitch}, Distance: ${
129+
particleBurrows.keys.minOfOrNull {
130+
trail.last().distanceTo(it.toVec3())
131+
}
132+
}")
133+
134+
var y: Int
135+
var x = guessPos.x.toInt()
136+
var z = guessPos.z.toInt()
137+
// offset of 300 blocks for both x and z
138+
// x ranges from 195 to -281
139+
// z ranges from 207 to -233
140+
141+
// TODO: this y thing is wrong and puts them in the air sometimes
142+
do {
143+
y = BurrowEstimation.grassData.getOrNull((x++ % 507) * 507 + (z++ % 495))?.toInt() ?: 0
144+
} while (y < 2)
145+
val guess = BurrowGuess(guessPos.x.toInt(), y, guessPos.z.toInt())
146+
BurrowEstimation.guesses[guess] = Instant.now()
147+
148+
BurrowEstimation.lastTrail.clear()
149+
BurrowEstimation.lastTrailCreated = -1
150+
BurrowEstimation.firstDistanceGuess = -1.0
151+
}
87152
}
88153

89154
@SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGHEST)
@@ -110,24 +175,38 @@ object GriffinBurrows {
110175
lastDugParticleBurrow = null
111176
BurrowEstimation.guesses.clear()
112177
BurrowEstimation.arrows.clear()
178+
BurrowEstimation.lastTrail.clear()
179+
BurrowEstimation.lastTrailCreated = -1
180+
lastSpadeUse = -1
181+
BurrowEstimation.firstDistanceGuess = -1.0
113182
}
114183
}
115184

116185
@SubscribeEvent
117186
fun onSendPacket(event: PacketEvent.SendEvent) {
118-
if (!Utils.inSkyblock || !Skytils.config.showGriffinBurrows || mc.theWorld == null || mc.thePlayer == null) return
119-
val pos =
120-
when {
121-
event.packet is C07PacketPlayerDigging && event.packet.status == C07PacketPlayerDigging.Action.START_DESTROY_BLOCK -> {
122-
event.packet.position
187+
if (!Utils.inSkyblock || !Skytils.config.showGriffinBurrows || mc.thePlayer == null || SBInfo.mode != SkyblockIsland.Hub.mode) return
188+
if (mc.thePlayer.heldItem?.isSpade != true) return
189+
190+
if (event.packet is C08PacketPlayerBlockPlacement && event.packet.position.y == -1) {
191+
lastSpadeUse = System.currentTimeMillis()
192+
BurrowEstimation.lastTrail.clear()
193+
BurrowEstimation.lastTrailCreated = -1
194+
BurrowEstimation.firstDistanceGuess = -1.0
195+
printDevMessage("Spade used", "griffinguess")
196+
} else {
197+
val pos =
198+
when {
199+
event.packet is C07PacketPlayerDigging && event.packet.status == C07PacketPlayerDigging.Action.START_DESTROY_BLOCK -> {
200+
event.packet.position
201+
}
202+
event.packet is C08PacketPlayerBlockPlacement && event.packet.stack != null -> event.packet.position
203+
else -> return
123204
}
124-
event.packet is C08PacketPlayerBlockPlacement && event.packet.stack != null -> event.packet.position
125-
else -> return
205+
if (mc.theWorld.getBlockState(pos).block !== Blocks.grass) return
206+
particleBurrows[pos]?.blockPos?.let {
207+
printDevMessage("Clicked on $it", "griffin")
208+
lastDugParticleBurrow = it
126209
}
127-
if (mc.thePlayer.heldItem?.isSpade != true || mc.theWorld.getBlockState(pos).block !== Blocks.grass) return
128-
particleBurrows[pos]?.blockPos?.let {
129-
printDevMessage("Clicked on $it", "griffin")
130-
lastDugParticleBurrow = it
131210
}
132211
}
133212

@@ -176,41 +255,47 @@ object GriffinBurrows {
176255
if (Skytils.config.showGriffinBurrows && hasSpadeInHotbar) {
177256
if (SBInfo.mode != SkyblockIsland.Hub.mode) return
178257
event.packet.apply {
179-
val type = ParticleType.getParticleType(this) ?: return
180-
val pos = BlockPos(x, y, z).down()
181-
if (recentlyDugParticleBurrows.contains(pos)) return
182-
BurrowEstimation.guesses.keys.associateWith { guess ->
183-
pos.distanceSq(
184-
guess.x.toDouble(),
185-
guess.y.toDouble(),
186-
guess.z.toDouble()
187-
)
188-
}.minByOrNull { it.value }?.let { (guess, distance) ->
189-
printDevMessage("Nearest guess is $distance blocks away", "griffin", "griffinguess")
190-
if (distance <= 625) {
191-
BurrowEstimation.guesses.remove(guess)
258+
if (type == EnumParticleTypes.DRIP_LAVA && count == 2 && speed == -.5f && xOffset == 0f && yOffset == 0f && zOffset == 0f && isLongDistance) {
259+
BurrowEstimation.lastTrail.add(vec3)
260+
BurrowEstimation.lastTrailCreated = System.currentTimeMillis()
261+
printDevMessage("Found trail point $x $y $z", "griffinguess")
262+
} else {
263+
val type = ParticleType.getParticleType(this) ?: return
264+
val pos = BlockPos(x, y, z).down()
265+
if (recentlyDugParticleBurrows.contains(pos)) return
266+
BurrowEstimation.guesses.keys.associateWith { guess ->
267+
pos.distanceSq(
268+
guess.x.toDouble(),
269+
guess.y.toDouble(),
270+
guess.z.toDouble()
271+
)
272+
}.minByOrNull { it.value }?.let { (guess, distance) ->
273+
// printDevMessage("Nearest guess is $distance blocks^2 away", "griffin", "griffinguess")
274+
if (distance <= 625) {
275+
BurrowEstimation.guesses.remove(guess)
276+
}
192277
}
193-
}
194-
val burrow = particleBurrows.getOrPut(pos) {
195-
ParticleBurrow(pos, hasFootstep = false, hasEnchant = false)
196-
}
197-
if (burrow.type == -1 && type.isBurrowType) {
198-
if (Skytils.config.pingNearbyBurrow) {
199-
SoundQueue.addToQueue("random.orb", 0.8f, 1f, 0, true)
278+
val burrow = particleBurrows.getOrPut(pos) {
279+
ParticleBurrow(pos, hasFootstep = false, hasEnchant = false)
280+
}
281+
if (burrow.type == -1 && type.isBurrowType) {
282+
if (Skytils.config.pingNearbyBurrow) {
283+
SoundQueue.addToQueue("random.orb", 0.8f, 1f, 0, true)
284+
}
285+
}
286+
when (type) {
287+
ParticleType.FOOTSTEP -> burrow.hasFootstep = true
288+
ParticleType.ENCHANT -> burrow.hasEnchant = true
289+
ParticleType.EMPTY -> burrow.type = 0
290+
ParticleType.MOB -> burrow.type = 1
291+
ParticleType.TREASURE -> burrow.type = 2
200292
}
201-
}
202-
when (type) {
203-
ParticleType.FOOTSTEP -> burrow.hasFootstep = true
204-
ParticleType.ENCHANT -> burrow.hasEnchant = true
205-
ParticleType.EMPTY -> burrow.type = 0
206-
ParticleType.MOB -> burrow.type = 1
207-
ParticleType.TREASURE -> burrow.type = 2
208293
}
209294
}
210295
}
211296
}
212297
is S04PacketEntityEquipment -> {
213-
if (!Skytils.config.burrowEstimation || SBInfo.mode != SkyblockIsland.Hub.mode) return
298+
if (!Skytils.config.burrowEstimation || SBInfo.mode != SkyblockIsland.Hub.mode || Skytils.config.experimentBurrowEstimation) return
214299
val entity = mc.theWorld?.getEntityByID(event.packet.entityID)
215300
(entity as? EntityArmorStand)?.let { armorStand ->
216301
if (event.packet.itemStack?.item != Items.arrow) return
@@ -229,7 +314,12 @@ object GriffinBurrows {
229314
}
230315
is S29PacketSoundEffect -> {
231316
if (!Skytils.config.burrowEstimation || SBInfo.mode != SkyblockIsland.Hub.mode) return
232-
if (event.packet.soundName != "note.harp") return
317+
if (event.packet.soundName != "note.harp" || event.packet.volume != 1f) return
318+
printDevMessage("Found note harp sound ${event.packet.pitch} ${event.packet.volume} ${event.packet.x} ${event.packet.y} ${event.packet.z}", "griffinguess")
319+
if (BurrowEstimation.firstDistanceGuess == -1.0 && lastSpadeUse != -1L && System.currentTimeMillis() - lastSpadeUse < 1000) {
320+
BurrowEstimation.firstDistanceGuess = event.packet.pitch.toDouble()
321+
}
322+
if (Skytils.config.experimentBurrowEstimation) return
233323
val (arrow, distance) = BurrowEstimation.arrows.keys
234324
.associateWith { arrow ->
235325
arrow.pos.squareDistanceTo(event.packet.x, event.packet.y, event.packet.z)

0 commit comments

Comments
 (0)