1818package gg.skytils.skytilsmod.features.impl.events
1919
2020import com.google.common.collect.EvictingQueue
21+ import gg.essential.elementa.state.BasicState
22+ import gg.essential.elementa.state.State
2123import gg.essential.universal.UMatrixStack
2224import gg.essential.universal.UMinecraft
2325import gg.essential.universal.wrappers.UPlayer
@@ -36,11 +38,7 @@ import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement
3638import net.minecraft.network.play.server.S04PacketEntityEquipment
3739import net.minecraft.network.play.server.S29PacketSoundEffect
3840import net.minecraft.network.play.server.S2APacketParticles
39- import net.minecraft.util.AxisAlignedBB
40- import net.minecraft.util.BlockPos
41- import net.minecraft.util.EnumParticleTypes
42- import net.minecraft.util.Vec3
43- import net.minecraft.util.Vec3i
41+ import net.minecraft.util.*
4442import net.minecraftforge.client.event.ClientChatReceivedEvent
4543import net.minecraftforge.client.event.RenderWorldLastEvent
4644import net.minecraftforge.event.world.WorldEvent
@@ -133,7 +131,7 @@ object GriffinBurrows {
133131 if (Skytils .config.showGriffinBurrows) {
134132 val matrixStack = UMatrixStack ()
135133 for (pb in particleBurrows.values) {
136- if (pb.hasEnchant && pb.hasFootstep && pb.type != - 1 ) {
134+ if (pb.hasEnchant && pb.hasFootstep && pb.type.get() != - 1 ) {
137135 pb.drawWaypoint(event.partialTicks, matrixStack)
138136 }
139137 }
@@ -187,14 +185,14 @@ object GriffinBurrows {
187185 }
188186 }
189187 val burrow = particleBurrows.getOrPut(pos) {
190- ParticleBurrow (pos, hasFootstep = false , hasEnchant = false , type = - 1 )
188+ ParticleBurrow (pos, hasFootstep = false , hasEnchant = false )
191189 }
192190 when (type) {
193191 ParticleType .FOOTSTEP -> burrow.hasFootstep = true
194192 ParticleType .ENCHANT -> burrow.hasEnchant = true
195- ParticleType .EMPTY -> burrow.type = 0
196- ParticleType .MOB -> burrow.type = 1
197- ParticleType .TREASURE -> burrow.type = 2
193+ ParticleType .EMPTY -> burrow.type.set( 0 )
194+ ParticleType .MOB -> burrow.type.set( 1 )
195+ ParticleType .TREASURE -> burrow.type.set( 2 )
198196 }
199197 }
200198 }
@@ -235,7 +233,7 @@ object GriffinBurrows {
235233 // x ranges from 195 to -281
236234 // z ranges from 207 to -233
237235 do {
238- y = BurrowEstimation .grassData.get(( x++ % 507 ) * 507 + (z++ % 495 )) .toInt()
236+ y = BurrowEstimation .grassData[( x++ % 507 ) * 507 + (z++ % 495 )] .toInt()
239237 } while (y < 2 )
240238 val guess = BurrowGuess (guessPos.x.toInt(), y, guessPos.z.toInt())
241239 BurrowEstimation .arrows.remove(arrow)
@@ -248,35 +246,33 @@ object GriffinBurrows {
248246 abstract val x: Int
249247 abstract val y: Int
250248 abstract val z: Int
251- abstract var type: Int
252249 val blockPos: BlockPos by lazy {
253250 BlockPos (x, y, z)
254251 }
255252
256- protected abstract val waypointText: String
257- protected abstract val color: Color
253+ protected abstract val waypointText: State < String >
254+ protected abstract val color: State < Color >
258255 fun drawWaypoint (partialTicks : Float , matrixStack : UMatrixStack ) {
259256 val (viewerX, viewerY, viewerZ) = RenderUtil .getViewerPos(partialTicks)
260- val pos = blockPos
261- val x = pos.x - viewerX
262- val y = pos.y - viewerY
263- val z = pos.z - viewerZ
264- val distSq = x * x + y * y + z * z
257+ val renderX = this .x - viewerX
258+ val renderY = this .y - viewerY
259+ val renderZ = this .z - viewerZ
260+ val distSq = renderX * renderX + renderY * renderY + renderZ * renderZ
265261 GlStateManager .disableDepth()
266262 GlStateManager .disableCull()
267263 RenderUtil .drawFilledBoundingBox(
268264 matrixStack,
269- AxisAlignedBB (x, y, z, x + 1 , y + 1 , z + 1 ).expandBlock(),
270- this .color,
265+ AxisAlignedBB (renderX, renderY, renderZ, renderX + 1 , renderY + 1 , renderZ + 1 ).expandBlock(),
266+ this .color.get() ,
271267 (0.1f + 0.005f * distSq.toFloat()).coerceAtLeast(0.2f )
272268 )
273269 GlStateManager .disableTexture2D()
274- if (distSq > 5 * 5 ) RenderUtil .renderBeaconBeam(x, y + 1 , z , this .color.rgb, 1.0f , partialTicks)
270+ if (distSq > 5 * 5 ) RenderUtil .renderBeaconBeam(renderX, renderY + 1 , renderZ , this .color.get() .rgb, 1.0f , partialTicks)
275271 RenderUtil .renderWaypointText(
276- waypointText,
277- blockPos. x + 0.5 ,
278- blockPos. y + 5.0 ,
279- blockPos. z + 0.5 ,
272+ waypointText.get() ,
273+ x + 0.5 ,
274+ y + 5.0 ,
275+ z + 0.5 ,
280276 partialTicks,
281277 matrixStack
282278 )
@@ -292,47 +288,45 @@ object GriffinBurrows {
292288 override val y : Int ,
293289 override val z : Int
294290 ) : Diggable() {
295- override var type = 0
296- override val waypointText = " §aBurrow §6(Guess)"
297- override val color = Color .ORANGE
291+ override val waypointText = BasicState (" §aBurrow §6(Guess)" )
292+ override val color = BasicState (Color .ORANGE )
298293 }
299294
300295 data class ParticleBurrow (
301296 override val x : Int ,
302297 override val y : Int ,
303298 override val z : Int ,
304299 var hasFootstep : Boolean ,
305- var hasEnchant : Boolean ,
306- override var type : Int
300+ var hasEnchant : Boolean
307301 ) : Diggable() {
308- constructor (vec3: Vec3i , hasFootstep: Boolean , hasEnchant: Boolean , type : Int ) : this (
302+ constructor (vec3: Vec3i , hasFootstep: Boolean , hasEnchant: Boolean ) : this (
309303 vec3.x,
310304 vec3.y,
311305 vec3.z,
312306 hasFootstep,
313- hasEnchant,
314- type
307+ hasEnchant
315308 )
316309
317- override val waypointText: String
318- get() {
319- var type = " Burrow"
320- when (this .type) {
321- 0 -> type = " §aStart"
322- 1 -> type = " §cMob"
323- 2 -> type = " §6Treasure"
324- }
325- return " $type §a(Particle)"
326- }
327- override val color: Color
328- get() {
329- return when (this .type) {
330- 0 -> Skytils .config.emptyBurrowColor
331- 1 -> Skytils .config.mobBurrowColor
332- 2 -> Skytils .config.treasureBurrowColor
333- else -> Color .WHITE
310+ val type = BasicState (- 1 )
311+
312+ override val waypointText = type.map {
313+ " ${
314+ when (it) {
315+ 0 -> " §aStart"
316+ 1 -> " §cMob"
317+ 2 -> " §6Treasure"
318+ else -> " §7Unknown"
334319 }
320+ } §a(Particle)"
321+ }
322+ override val color = type.map {
323+ when (it) {
324+ 0 -> Skytils .config.emptyBurrowColor
325+ 1 -> Skytils .config.mobBurrowColor
326+ 2 -> Skytils .config.treasureBurrowColor
327+ else -> Color .WHITE
335328 }
329+ }
336330 }
337331
338332 private val ItemStack ?.isSpade
@@ -359,12 +353,9 @@ object GriffinBurrows {
359353 companion object {
360354 fun getParticleType (packet : S2APacketParticles ): ParticleType ? {
361355 if (! packet.isLongDistance) return null
362- for (type in entries) {
363- if (type.check(packet)) {
364- return type
365- }
356+ return entries.find {
357+ it.check(packet)
366358 }
367- return null
368359 }
369360 }
370361 }
0 commit comments