@@ -31,8 +31,7 @@ import com.lambda.module.Module
3131import com.lambda.module.tag.ModuleTag
3232import com.lambda.threading.runSafe
3333import com.lambda.util.extension.blockColor
34- import com.lambda.util.extension.blockFilledMesh
35- import com.lambda.util.extension.blockOutlineMesh
34+ import com.lambda.util.extension.outlineShape
3635import com.lambda.util.math.setAlpha
3736import com.lambda.util.world.blockEntitySearch
3837import com.lambda.util.world.entitySearch
@@ -50,6 +49,7 @@ import net.minecraft.block.entity.SmokerBlockEntity
5049import net.minecraft.entity.Entity
5150import net.minecraft.entity.decoration.ItemFrameEntity
5251import net.minecraft.entity.vehicle.AbstractMinecartEntity
52+ import net.minecraft.entity.vehicle.MinecartEntity
5353import net.minecraft.util.math.BlockPos
5454import java.awt.Color
5555
@@ -67,14 +67,13 @@ object StorageESP : Module(
6767 private var drawFaces: Boolean by setting(" Draw Faces" , true , " Draw faces of blocks" ) { page == Page .Render }.apply { onValueSet { _, to -> if (! to) drawOutlines = true } }
6868 private var drawOutlines: Boolean by setting(" Draw Outlines" , true , " Draw outlines of blocks" ) { page == Page .Render }.apply { onValueSet { _, to -> if (! to) drawFaces = true } }
6969 private val outlineMode by setting(" Outline Mode" , DirectionMask .OutlineMode .AND , " Outline mode" ) { page == Page .Render }
70- private val mesh by setting(" Mesh" , true , " Connect similar adjacent blocks" )
70+ private val mesh by setting(" Mesh" , true , " Connect similar adjacent blocks" ) { page == Page . Render }
7171
7272 /* Color settings */
7373 private val useBlockColor by setting(" Use Block Color" , true , " Use the color of the block instead" ) { page == Page .Color }
7474 private val alpha by setting(" Alpha" , 0.3 , 0.1 .. 1.0 , 0.05 ) { page == Page .Color }
7575
7676 // TODO:
77- // Once we have map setting we can do this:
7877 // val blockColors by setting("Block Colors", mapOf<String, Color>()) { page == Page.Color && !useBlockColor }
7978 // val renders by setting("Render Blocks", mapOf<String, Boolean>()) { page == Page.General }
8079 //
@@ -98,39 +97,63 @@ object StorageESP : Module(
9897 private val smokerColor by setting(" Smoker Color" , Color (112 , 112 , 112 )) { page == Page .Color && ! useBlockColor }
9998 private val shulkerColor by setting(" Shulker Color" , Color (178 , 76 , 216 )) { page == Page .Color && ! useBlockColor }
10099 private val itemFrameColor by setting(" Item Frame Color" , Color (216 , 127 , 51 )) { page == Page .Color && ! useBlockColor }
101- private val cartColor by setting(" Cart Color" , Color (102 , 127 , 51 )) { page == Page .Color && ! useBlockColor }
100+ private val cartColor by setting(" Minecart Color" , Color (102 , 127 , 51 )) { page == Page .Color && ! useBlockColor }
101+
102+ private val entities = setOf (
103+ BarrelBlockEntity ::class ,
104+ BlastFurnaceBlockEntity ::class ,
105+ BrewingStandBlockEntity ::class ,
106+ ChestBlockEntity ::class ,
107+ DispenserBlockEntity ::class ,
108+ EnderChestBlockEntity ::class ,
109+ FurnaceBlockEntity ::class ,
110+ HopperBlockEntity ::class ,
111+ SmokerBlockEntity ::class ,
112+ ShulkerBoxBlockEntity ::class ,
113+ AbstractMinecartEntity ::class ,
114+ ItemFrameEntity ::class ,
115+ MinecartEntity ::class ,
116+ )
102117
103118 init {
104119 listen<RenderEvent .StaticESP > { event ->
105- blockEntitySearch<BlockEntity >(range = distance)
106- .forEach { event.renderer.build(it, it.pos, buildMesh(it.pos)) }
107-
108- (entitySearch<AbstractMinecartEntity >(range = distance) +
109- entitySearch<ItemFrameEntity >(range = distance))
110- .forEach { event.renderer.build(it, DirectionMask .ALL ) } // I didn't add block entity meshing because I'm not sure how to handle blocks that aren't full
120+ blockEntitySearch<BlockEntity >(distance)
121+ .filter { it::class in entities }
122+ .forEach { event.renderer.build(it, it.pos, excludedSides(it)) }
123+
124+ val mineCarts = entitySearch<AbstractMinecartEntity >(distance)
125+ val itemFrames = entitySearch<ItemFrameEntity >(distance)
126+ (mineCarts + itemFrames)
127+ .forEach { event.renderer.build(it, DirectionMask .ALL ) }
111128 }
112129 }
113130
114- private fun SafeContext.buildMesh (position : BlockPos ) =
115- if (mesh) buildSideMesh(position) {
116- val block = world.getBlockEntity(it) ? : return @buildSideMesh false
117-
118- getBlockEntityColor(block) != null &&
119- block.cachedState.isFullCube(world, it)
120- }
121- else DirectionMask .ALL
131+ private fun SafeContext.excludedSides (blockEntity : BlockEntity ): Int {
132+ val isFullCube = blockEntity.cachedState.isFullCube(world, blockEntity.pos)
133+ return if (mesh && isFullCube) {
134+ buildSideMesh(blockEntity.pos) { neighbor ->
135+ val other = world.getBlockEntity(neighbor) ? : return @buildSideMesh false
136+ val otherFullCube = other.cachedState.isFullCube(world, other.pos)
137+ val sameType = blockEntity.cachedState.block == other.cachedState.block
138+ val searchedFor = other::class in entities
139+
140+ searchedFor && otherFullCube && sameType
141+ }
142+ } else DirectionMask .ALL
143+ }
122144
123145 private fun StaticESPRenderer.build (
124146 block : BlockEntity ,
125147 pos : BlockPos ,
126148 sides : Int ,
127149 ) = runSafe {
128- val color = if (useBlockColor) blockColor(block.cachedState, pos) else getBlockEntityColor(block) ? : return @runSafe
129- val filledMesh = blockFilledMesh(block.cachedState, pos)
130- val outlineMesh = blockOutlineMesh(block.cachedState, pos)
150+ val color = if (useBlockColor) {
151+ blockColor(block.cachedState, pos)
152+ } else getBlockEntityColor(block) ? : return @runSafe
153+ val shape = outlineShape(block.cachedState, pos)
131154
132- if (drawFaces) buildFilledMesh(filledMesh , color.setAlpha(alpha), sides)
133- if (drawOutlines) buildOutlineMesh(outlineMesh , color, sides, outlineMode)
155+ if (drawFaces) buildFilledMesh(shape , color.setAlpha(alpha), sides)
156+ if (drawOutlines) buildOutlineMesh(shape , color, sides, outlineMode)
134157 }
135158
136159 private fun StaticESPRenderer.build (
0 commit comments