Skip to content

Commit 0c021c6

Browse files
committed
added break renders, currently only static however, so render at 20 fps
1 parent 95fbfcc commit 0c021c6

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

common/src/main/kotlin/com/lambda/config/groups/BreakSettings.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.lambda.event.events.TickEvent
2222
import com.lambda.interaction.request.Priority
2323
import com.lambda.interaction.request.breaking.BreakConfig
2424
import com.lambda.util.BlockUtils.allSigns
25+
import java.awt.Color
2526

2627
class BreakSettings(
2728
c: Configurable,
@@ -52,4 +53,20 @@ class BreakSettings(
5253
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks", visibility = vis)
5354
override val forceFortunePickaxe by c.setting("Force Fortune Pickaxe", false, "Force fortune pickaxe when breaking blocks", visibility = vis)
5455
override val minFortuneLevel by c.setting("Min Fortune Level", 1, 1..3, 1, "The minimum fortune level to use") { vis() && forceFortunePickaxe }
56+
57+
override val renders by c.setting("Renders", true, "Enables the render settings for breaking progress", visibility = vis)
58+
override val fill by c.setting("Fill", true, "Renders the sides of the box to display break progress") { vis() && renders }
59+
override val outline by c.setting("Outline", true, "Renders the lines of the box to display break progress") { vis() && renders }
60+
override val outlineWidth by c.setting("Outline Width", 2, 0..5, 1, "The width of the outline") { vis() && renders && outline }
61+
override val animation by c.setting("Animation", AnimationMode.Out, "The style of animation used for the box") { vis() && renders }
62+
63+
override val dynamicFillColor by c.setting("Dynamic Colour", true, "Enables fill color interpolation from start to finish for fill when breaking a block") { vis() && renders && fill }
64+
override val staticFillColor by c.setting("Fill Color", Color(255, 0, 0, 60), "The color of the fill") { vis() && renders && !dynamicFillColor && fill }
65+
override val startFillColor by c.setting("Start Fill Color", Color(255, 0, 0, 60), "The color of the fill at the start of breaking") { vis() && renders && dynamicFillColor && fill }
66+
override val endFillColor by c.setting("End Fill Color", Color(0, 255, 0, 60), "The color of the fill at the end of breaking") { vis() && renders && dynamicFillColor && fill }
67+
68+
override val dynamicOutlineColor by c.setting("Dynamic Outline Color", true, "Enables color interpolation from start to finish for the outline when breaking a block") { vis() && renders && outline }
69+
override val staticOutlineColor by c.setting("Outline Color", Color(255, 0, 0, 255), "The Color of the outline at the start of breaking") { vis() && renders && !dynamicOutlineColor && outline }
70+
override val startOutlineColor by c.setting("Start Outline Color", Color(255, 0, 0, 255), "The color of the outline at the start of breaking") { vis() && renders && dynamicOutlineColor && outline }
71+
override val endOutlineColor by c.setting("End Outline Color", Color(0, 255, 0, 255), "The color of the outline at the end of breaking") { vis() && renders && dynamicOutlineColor && outline }
5572
}

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakConfig.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.lambda.event.Event
2222
import com.lambda.interaction.request.Priority
2323
import com.lambda.interaction.request.RequestConfig
2424
import net.minecraft.block.Block
25+
import java.awt.Color
2526

2627
abstract class BreakConfig(
2728
priority: Priority = 0
@@ -51,6 +52,22 @@ abstract class BreakConfig(
5152
abstract val minFortuneLevel: Int
5253
abstract val ignoredBlocks: Set<Block>
5354

55+
abstract val renders: Boolean
56+
abstract val fill: Boolean
57+
abstract val outline: Boolean
58+
abstract val outlineWidth: Int
59+
abstract val animation: AnimationMode
60+
61+
abstract val dynamicFillColor: Boolean
62+
abstract val staticFillColor: Color
63+
abstract val startFillColor: Color
64+
abstract val endFillColor: Color
65+
66+
abstract val dynamicOutlineColor: Boolean
67+
abstract val staticOutlineColor: Color
68+
abstract val startOutlineColor: Color
69+
abstract val endOutlineColor: Color
70+
5471
override fun requestInternal(request: BreakRequest, queueIfClosed: Boolean) {
5572
BreakManager.request(request, queueIfClosed)
5673
}
@@ -75,4 +92,12 @@ abstract class BreakConfig(
7592
BreakThenAwait,
7693
AwaitThenBreak
7794
}
95+
96+
enum class AnimationMode {
97+
None,
98+
Out,
99+
In,
100+
OutIn,
101+
InOut,
102+
}
78103
}

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ import com.lambda.event.Event
2222
import com.lambda.event.EventFlow.post
2323
import com.lambda.event.events.ConnectionEvent
2424
import com.lambda.event.events.EntityEvent
25+
import com.lambda.event.events.RenderEvent
2526
import com.lambda.event.events.TickEvent
2627
import com.lambda.event.events.UpdateManagerEvent
2728
import com.lambda.event.events.WorldEvent
2829
import com.lambda.event.listener.SafeListener.Companion.listen
2930
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
31+
import com.lambda.graphics.renderer.esp.builders.buildFilled
32+
import com.lambda.graphics.renderer.esp.builders.buildOutline
3033
import com.lambda.interaction.construction.context.BreakContext
3134
import com.lambda.interaction.request.PositionBlocking
3235
import com.lambda.interaction.request.Priority
@@ -51,6 +54,7 @@ import com.lambda.util.BlockUtils.isBroken
5154
import com.lambda.util.BlockUtils.isEmpty
5255
import com.lambda.util.Communication.warn
5356
import com.lambda.util.item.ItemUtils.block
57+
import com.lambda.util.math.lerp
5458
import com.lambda.util.player.gamemode
5559
import com.lambda.util.player.swingHand
5660
import net.minecraft.client.sound.PositionedSoundInstance
@@ -59,6 +63,7 @@ import net.minecraft.entity.ItemEntity
5963
import net.minecraft.sound.SoundCategory
6064
import net.minecraft.util.Hand
6165
import net.minecraft.util.math.BlockPos
66+
import net.minecraft.util.math.Box
6267

6368
object BreakManager : RequestHandler<BreakRequest>(
6469
0,
@@ -169,6 +174,40 @@ object BreakManager : RequestHandler<BreakRequest>(
169174
?.internalOnItemDrop(it.entity)
170175
}
171176

177+
listen<RenderEvent.StaticESP> { event ->
178+
breakInfos
179+
.filterNotNull()
180+
.forEach { info ->
181+
val config = info.breakConfig
182+
if (!config.renders) return@listen
183+
val breakDelta = info.context.checkedState.calcItemBlockBreakingDelta(
184+
player,
185+
world,
186+
info.context.expectedPos,
187+
player.inventory.getStack(info.context.hotbarIndex)
188+
)
189+
val progress = (info.breakingTicks * breakDelta).let {
190+
if (info.isPrimary) it * (2 - info.breakConfig.breakThreshold)
191+
else it
192+
}.toDouble()
193+
val state = info.context.checkedState
194+
val boxes = state.getOutlineShape(world, info.context.expectedPos).boundingBoxes.map {
195+
it.offset(info.context.expectedPos)
196+
}
197+
198+
val fillColor = if (config.dynamicFillColor) lerp(progress, config.startFillColor, config.endFillColor)
199+
else config.staticFillColor
200+
val outlineColor = if (config.dynamicOutlineColor) lerp(progress, config.startOutlineColor, config.endOutlineColor)
201+
else config.staticOutlineColor
202+
203+
boxes.forEach boxes@ { box ->
204+
val interpolated = interpolateBox(box, progress, info.breakConfig)
205+
if (config.fill) event.renderer.buildFilled(interpolated, fillColor)
206+
if (config.outline) event.renderer.buildOutline(interpolated, outlineColor)
207+
}
208+
}
209+
}
210+
172211
listenUnsafe<ConnectionEvent.Connect.Pre>(priority = Int.MIN_VALUE) {
173212
breakInfos.forEach { it?.nullify() }
174213
breakCooldown = 0
@@ -689,5 +728,20 @@ object BreakManager : RequestHandler<BreakRequest>(
689728
return inRange && correctMaterial
690729
}
691730

731+
private fun interpolateBox(box: Box, progress: Double, config: BreakConfig): Box {
732+
val boxCenter = Box(box.center, box.center)
733+
return when (config.animation) {
734+
BreakConfig.AnimationMode.Out -> lerp(progress, boxCenter, box)
735+
BreakConfig.AnimationMode.In -> lerp(progress, box, boxCenter)
736+
BreakConfig.AnimationMode.InOut ->
737+
if (progress >= 0.5f) lerp((progress - 0.5) * 2, boxCenter, box)
738+
else lerp(progress * 2, box, boxCenter)
739+
BreakConfig.AnimationMode.OutIn ->
740+
if (progress >= 0.5f) lerp((progress - 0.5) * 2, box, boxCenter)
741+
else lerp(progress * 2, boxCenter, box)
742+
else -> box
743+
}
744+
}
745+
692746
override fun preEvent(): Event = UpdateManagerEvent.Break.post()
693747
}

common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ import com.lambda.config.groups.InventorySettings
2424
import com.lambda.config.groups.RotationSettings
2525
import com.lambda.context.SafeContext
2626
import com.lambda.event.events.PlayerEvent
27+
import com.lambda.event.events.RenderEvent
2728
import com.lambda.event.events.TickEvent
2829
import com.lambda.event.listener.SafeListener.Companion.listen
30+
import com.lambda.graphics.renderer.esp.builders.buildFilled
31+
import com.lambda.graphics.renderer.esp.builders.buildOutline
32+
import com.lambda.graphics.renderer.esp.impl.StaticESPRenderer
2933
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
3034
import com.lambda.interaction.construction.context.BreakContext
3135
import com.lambda.interaction.construction.context.BuildContext
@@ -37,8 +41,12 @@ import com.lambda.module.Module
3741
import com.lambda.module.tag.ModuleTag
3842
import com.lambda.util.BlockUtils.blockState
3943
import com.lambda.util.math.distSq
44+
import com.lambda.util.math.lerp
45+
import com.lambda.util.math.setAlpha
4046
import com.lambda.util.world.raycast.InteractionMask
4147
import net.minecraft.util.math.BlockPos
48+
import net.minecraft.util.math.Box
49+
import java.awt.Color
4250
import java.util.*
4351
import java.util.concurrent.ConcurrentLinkedQueue
4452

@@ -62,6 +70,14 @@ object PacketMine : Module(
6270
private val queue by setting("Queue", false, "Queues blocks to break so you can select multiple at once")
6371
.onValueChange { _, to -> if (!to) queuePositions.clear() }
6472
private val queueOrder by setting("Queue Order", QueueOrder.Standard, "Which end of the queue to break blocks from") { queue }
73+
private val renderQueue by setting("Render Queue", true, "Adds renders to signify what block positions are queued") { queue }
74+
private val renderSize by setting("Render Size", 0.3f, 0.01f..1f, 0.01f, "The scale of the queue renders") { queue && renderQueue }
75+
private val renderMode by setting("Render Mode", RenderMode.State, "The style of the queue renders") { queue && renderQueue }
76+
private val dynamicColor by setting("Dynamic Color", true, "Interpolates the color between start and end") { queue && renderQueue }
77+
private val staticColor by setting("Color", Color(255, 0, 0, 60)) { queue && renderQueue && !dynamicColor }
78+
private val startColor by setting("Start Color", Color(255, 255, 0, 60), "The color of the start (closest to breaking) of the queue") { queue && renderQueue && dynamicColor }
79+
private val endColor by setting("End Color", Color(255, 0, 0, 60), "The color of the end (farthest from breaking) of the queue") { queue && renderQueue && dynamicColor }
80+
6581

6682
private val pendingInteractionsList = ConcurrentLinkedQueue<BuildContext>()
6783

@@ -125,6 +141,25 @@ object PacketMine : Module(
125141
}
126142
}
127143

144+
listen<RenderEvent.StaticESP> { event ->
145+
if (!renderQueue) return@listen
146+
queuePositions.forEachIndexed { index, positions ->
147+
positions.forEach { pos ->
148+
val color = if (dynamicColor) lerp(index / queuePositions.size.toDouble(), startColor, endColor)
149+
else staticColor
150+
val boxes = when (renderMode) {
151+
RenderMode.State -> blockState(pos).getOutlineShape(world, pos).boundingBoxes
152+
RenderMode.Box -> listOf(Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0))
153+
}.map { lerp(renderSize.toDouble(), Box(it.center, it.center), it).offset(pos) }
154+
155+
boxes.forEach { box ->
156+
event.renderer.buildFilled(box, color)
157+
event.renderer.buildOutline(box, Color(color.rgb).setAlpha(1.0))
158+
}
159+
}
160+
}
161+
}
162+
128163
onDisable {
129164
breakPositions[0] = null
130165
breakPositions[1] = null
@@ -222,4 +257,9 @@ object PacketMine : Module(
222257
Standard,
223258
Reversed
224259
}
260+
261+
private enum class RenderMode {
262+
State,
263+
Box
264+
}
225265
}

0 commit comments

Comments
 (0)