Skip to content

Commit 638b4e9

Browse files
authored
Merge pull request #542 from rfresh2/search-update
Search: prevent possible concurrent modification + old signs
2 parents 88bf61d + 45134eb commit 638b4e9

File tree

1 file changed

+63
-20
lines changed
  • src/main/kotlin/com/lambda/client/module/modules/render

1 file changed

+63
-20
lines changed

src/main/kotlin/com/lambda/client/module/modules/render/Search.kt

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import com.lambda.client.module.Category
1010
import com.lambda.client.module.Module
1111
import com.lambda.client.module.modules.client.Hud
1212
import com.lambda.client.setting.settings.impl.collection.CollectionSetting
13+
import com.lambda.client.util.EntityUtils
1314
import com.lambda.client.util.color.ColorHolder
1415
import com.lambda.client.util.graphics.ESPRenderer
1516
import com.lambda.client.util.graphics.GeometryMasks
17+
import com.lambda.client.util.graphics.LambdaTessellator
1618
import com.lambda.client.util.graphics.ShaderHelper
1719
import com.lambda.client.util.math.VectorUtils.distanceTo
1820
import com.lambda.client.util.text.MessageSendHelper
@@ -26,14 +28,19 @@ import kotlinx.coroutines.isActive
2628
import kotlinx.coroutines.launch
2729
import net.minecraft.block.BlockEnderChest
2830
import net.minecraft.block.BlockShulkerBox
31+
import net.minecraft.block.BlockStandingSign
32+
import net.minecraft.block.BlockWallSign
33+
import net.minecraft.block.state.BlockStateContainer.StateImplementation
2934
import net.minecraft.block.state.IBlockState
3035
import net.minecraft.entity.EntityList
3136
import net.minecraft.entity.item.EntityItemFrame
3237
import net.minecraft.init.Blocks
3338
import net.minecraft.network.play.server.SPacketBlockChange
3439
import net.minecraft.network.play.server.SPacketMultiBlockChange
40+
import net.minecraft.tileentity.TileEntitySign
3541
import net.minecraft.util.math.BlockPos
3642
import net.minecraft.util.math.ChunkPos
43+
import net.minecraft.util.text.TextComponentString
3744
import net.minecraft.world.chunk.Chunk
3845
import net.minecraftforge.fml.common.gameevent.TickEvent
3946
import java.util.concurrent.ConcurrentHashMap
@@ -52,6 +59,8 @@ object Search : Module(
5259
private val blockSearch by setting("Block Search", true)
5360
private val illegalBedrock = setting("Illegal Bedrock", false)
5461
private val illegalNetherWater = setting("Illegal Nether Water", false)
62+
private val oldSigns = setting("Old Signs", true)
63+
private val oldSignsColor by setting("Old Signs Color", ColorHolder(220, 0, 0, 110), visibility = { oldSigns.value })
5564
private val range by setting("Search Range", 512, 0..4096, 8)
5665
private val yRangeBottom by setting("Top Y", 256, 0..256, 1)
5766
private val yRangeTop by setting("Bottom Y", 0, 0..256, 1)
@@ -91,6 +100,7 @@ object Search : Module(
91100
blockSearchList.editListeners.add { blockSearchListUpdateListener(isEnabled) }
92101
illegalBedrock.listeners.add { blockSearchListUpdateListener(illegalBedrock.value) }
93102
illegalNetherWater.listeners.add { blockSearchListUpdateListener(illegalNetherWater.value) }
103+
oldSigns.listeners.add { blockSearchListUpdateListener(oldSigns.value) }
94104

95105
onEnable {
96106
if (!overrideWarning && ShaderHelper.isIntegratedGraphics) {
@@ -142,7 +152,7 @@ object Search : Module(
142152
}
143153

144154
safeListener<ChunkDataEvent> {
145-
// We avoid listening to SPacketChunkData directly here as even on PostReceive the chunk is not always
155+
// We avoid listening to SPacketChunkData directly here, as even on PostReceive the chunk is not always
146156
// fully loaded into the world. Chunk load is handled on a separate thread in mc code.
147157
// i.e. world.getChunk(x, z) can and will return an empty chunk in the packet event
148158
defaultScope.launch {
@@ -191,16 +201,18 @@ object Search : Module(
191201
entitySearchDimensionFilter.value.find { dimFilter -> dimFilter.searchKey == entityName }?.dim
192202
}?.contains(player.dimension) ?: true
193203
}
194-
.sortedBy {
195-
it.distanceTo(player.getPositionEyes(1f))
196-
}
204+
.sortedBy { it.distanceTo(player.getPositionEyes(1f)) }
197205
.take(maximumEntities)
198-
.filter {
199-
it.distanceTo(player.getPositionEyes(1f)) < range
206+
.filter { it.distanceTo(player.getPositionEyes(1f)) < range }
207+
.map {
208+
Triple(
209+
it.renderBoundingBox.offset(EntityUtils.getInterpolatedAmount(it, LambdaTessellator.pTicks())),
210+
entitySearchColor,
211+
GeometryMasks.Quad.ALL
212+
)
200213
}
201214
.toMutableList()
202-
entityRenderer.clear()
203-
renderList.forEach { entityRenderer.add(it, entitySearchColor) }
215+
entityRenderer.replaceAll(renderList)
204216
}
205217

206218
private fun SafeClientEvent.searchAllLoadedChunks() {
@@ -270,7 +282,6 @@ object Search : Module(
270282
}
271283
}
272284
.toMutableList()
273-
274285
blockRenderer.replaceAll(renderList)
275286
}
276287

@@ -294,6 +305,15 @@ object Search : Module(
294305
for (y in yRange) for (x in xRange) for (z in zRange) {
295306
val pos = BlockPos(x, y, z)
296307
val blockState = chunk.getBlockState(pos)
308+
if (isOldSign(blockState, pos)) {
309+
val signState = if (blockState.block == Blocks.STANDING_SIGN) {
310+
OldStandingSign(blockState)
311+
} else {
312+
OldWallSign(blockState)
313+
}
314+
blocks.add(pos to signState)
315+
continue // skip searching for regular sign at this pos
316+
}
297317
if (searchQuery(blockState, pos)) blocks.add(pos to blockState)
298318
}
299319
return blocks
@@ -304,8 +324,8 @@ object Search : Module(
304324
if (block == Blocks.AIR) return false
305325
return (blockSearchList.contains(block.registryName.toString())
306326
&& blockSearchDimensionFilter.value.find { dimFilter ->
307-
dimFilter.searchKey == block.registryName.toString()
308-
}?.dim?.contains(player.dimension) ?: true)
327+
dimFilter.searchKey == block.registryName.toString()
328+
}?.dim?.contains(player.dimension) ?: true)
309329
|| isIllegalBedrock(state, pos)
310330
|| isIllegalWater(state)
311331
}
@@ -314,15 +334,9 @@ object Search : Module(
314334
if (!illegalBedrock.value) return false
315335
if (state.block != Blocks.BEDROCK) return false
316336
return when (player.dimension) {
317-
0 -> {
318-
pos.y >= 5
319-
}
320-
-1 -> {
321-
pos.y in 5..122
322-
}
323-
else -> {
324-
false
325-
}
337+
0 -> pos.y >= 5
338+
-1 -> pos.y in 5..122
339+
else -> false
326340
}
327341
}
328342

@@ -331,6 +345,25 @@ object Search : Module(
331345
return player.dimension == -1 && state.isWater
332346
}
333347

348+
private fun SafeClientEvent.isOldSign(state: IBlockState, pos: BlockPos): Boolean {
349+
if (!oldSigns.value) return false
350+
return (state.block == Blocks.STANDING_SIGN || state.block == Blocks.WALL_SIGN) && isOldSignText(pos)
351+
}
352+
353+
private fun SafeClientEvent.isOldSignText(pos: BlockPos): Boolean {
354+
// Explanation: Old signs on 2b2t (pre-2015 <1.9 ?) have older style NBT text tags.
355+
// We can tell them apart by checking if there are siblings in the tag.
356+
// Old signs won't have siblings.
357+
val signTextComponents = listOf(world.getTileEntity(pos))
358+
.filterIsInstance<TileEntitySign>()
359+
.flatMap { it.signText.toList() }
360+
.filterIsInstance<TextComponentString>()
361+
.toList()
362+
return signTextComponents.isNotEmpty()
363+
&& signTextComponents.all { it.siblings.size == 0 }
364+
&& !signTextComponents.all { it.text.isEmpty() }
365+
}
366+
334367
private fun SafeClientEvent.getBlockColor(pos: BlockPos, blockState: IBlockState): ColorHolder {
335368
val block = blockState.block
336369
return if (autoBlockColor) {
@@ -345,6 +378,12 @@ object Search : Module(
345378
is BlockEnderChest -> {
346379
ColorHolder(64, 49, 114)
347380
}
381+
is BlockOldStandingSign -> {
382+
oldSignsColor
383+
}
384+
is BlockOldWallSign -> {
385+
oldSignsColor
386+
}
348387
else -> {
349388
val colorInt = blockState.getMapColor(world, pos).colorValue
350389
ColorHolder((colorInt shr 16), (colorInt shr 8 and 255), (colorInt and 255))
@@ -361,4 +400,8 @@ object Search : Module(
361400
}
362401
}
363402

403+
class OldWallSign(blockStateIn: IBlockState): StateImplementation(BlockOldWallSign, blockStateIn.properties)
404+
class OldStandingSign(blockStateIn: IBlockState): StateImplementation(BlockOldStandingSign, blockStateIn.properties)
405+
object BlockOldWallSign: BlockWallSign()
406+
object BlockOldStandingSign: BlockStandingSign()
364407
}

0 commit comments

Comments
 (0)