Skip to content

Commit 4e95650

Browse files
committed
old sign search
1 parent 51e3a62 commit 4e95650

File tree

1 file changed

+38
-0
lines changed
  • src/main/kotlin/com/lambda/client/module/modules/render

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ import kotlinx.coroutines.isActive
2525
import kotlinx.coroutines.launch
2626
import net.minecraft.block.BlockEnderChest
2727
import net.minecraft.block.BlockShulkerBox
28+
import net.minecraft.block.BlockStandingSign
29+
import net.minecraft.block.BlockWallSign
30+
import net.minecraft.block.state.BlockStateContainer.StateImplementation
2831
import net.minecraft.block.state.IBlockState
2932
import net.minecraft.entity.EntityList
3033
import net.minecraft.entity.item.EntityItemFrame
3134
import net.minecraft.init.Blocks
3235
import net.minecraft.network.play.server.SPacketBlockChange
3336
import net.minecraft.network.play.server.SPacketMultiBlockChange
37+
import net.minecraft.tileentity.TileEntitySign
3438
import net.minecraft.util.math.BlockPos
3539
import net.minecraft.util.math.ChunkPos
40+
import net.minecraft.util.text.TextComponentString
3641
import net.minecraft.world.chunk.Chunk
3742
import net.minecraftforge.fml.common.gameevent.TickEvent
3843
import java.util.concurrent.ConcurrentHashMap
@@ -51,6 +56,7 @@ object Search : Module(
5156
private val blockSearch by setting("Block Search", true)
5257
private val illegalBedrock = setting("Illegal Bedrock", false)
5358
private val illegalNetherWater = setting("Illegal Nether Water", false)
59+
private val oldSigns = setting("Old Signs", true)
5460
private val range by setting("Search Range", 512, 0..4096, 8)
5561
private val yRangeBottom by setting("Top Y", 256, 0..256, 1)
5662
private val yRangeTop by setting("Bottom Y", 0, 0..256, 1)
@@ -90,6 +96,7 @@ object Search : Module(
9096
blockSearchList.editListeners.add { blockSearchListUpdateListener(isEnabled) }
9197
illegalBedrock.listeners.add { blockSearchListUpdateListener(illegalBedrock.value) }
9298
illegalNetherWater.listeners.add { blockSearchListUpdateListener(illegalNetherWater.value) }
99+
oldSigns.listeners.add { blockSearchListUpdateListener(oldSigns.value) }
93100

94101
onEnable {
95102
if (!overrideWarning && ShaderHelper.isIntegratedGraphics) {
@@ -274,6 +281,11 @@ object Search : Module(
274281
for (y in yRange) for (x in xRange) for (z in zRange) {
275282
val pos = BlockPos(x, y, z)
276283
val blockState = chunk.getBlockState(pos)
284+
if (isOldSign(blockState, pos)) {
285+
val signState = if (blockState.block == Blocks.STANDING_SIGN) OldStandingSign(blockState) else OldWallSign(blockState)
286+
blocks.add((pos to signState))
287+
continue // skip searching for regular sign at this pos
288+
}
277289
if (searchQuery(blockState, pos)) blocks.add((pos to blockState))
278290
}
279291
return blocks
@@ -311,6 +323,22 @@ object Search : Module(
311323
return player.dimension == -1 && state.isWater
312324
}
313325

326+
private fun SafeClientEvent.isOldSign(state: IBlockState, pos: BlockPos): Boolean {
327+
if (!oldSigns.value) return false
328+
return (state.block == Blocks.STANDING_SIGN || state.block == Blocks.WALL_SIGN) && isOldSignText(pos)
329+
}
330+
331+
private fun SafeClientEvent.isOldSignText(pos: BlockPos): Boolean {
332+
// Explanation: Old signs on 2b2t (pre-2015 <1.9 ?) have older style NBT text tags.
333+
// we can tell them apart by checking if there are siblings in the tag. Old signs won't have siblings.
334+
val signTextComponents = listOf(world.getTileEntity(pos))
335+
.filterIsInstance<TileEntitySign>()
336+
.flatMap { it.signText.toList() }
337+
.filterIsInstance<TextComponentString>()
338+
.toList()
339+
return signTextComponents.isNotEmpty() && signTextComponents.all { it.siblings.size == 0 }
340+
}
341+
314342
private fun SafeClientEvent.getBlockColor(pos: BlockPos, blockState: IBlockState): ColorHolder {
315343
val block = blockState.block
316344
return if (autoBlockColor) {
@@ -325,6 +353,12 @@ object Search : Module(
325353
is BlockEnderChest -> {
326354
ColorHolder(64, 49, 114)
327355
}
356+
is BlockOldStandingSign -> {
357+
ColorHolder(0, 0, 220, 100)
358+
}
359+
is BlockOldWallSign -> {
360+
ColorHolder(0, 0, 220, 100)
361+
}
328362
else -> {
329363
val colorInt = blockState.getMapColor(world, pos).colorValue
330364
ColorHolder((colorInt shr 16), (colorInt shr 8 and 255), (colorInt and 255))
@@ -341,4 +375,8 @@ object Search : Module(
341375
}
342376
}
343377

378+
class OldWallSign(blockStateIn: IBlockState): StateImplementation(BlockOldWallSign, blockStateIn.properties)
379+
class OldStandingSign(blockStateIn: IBlockState): StateImplementation(BlockOldStandingSign, blockStateIn.properties)
380+
object BlockOldWallSign: BlockWallSign()
381+
object BlockOldStandingSign: BlockStandingSign()
344382
}

0 commit comments

Comments
 (0)