Skip to content

Commit

Permalink
feat(legacy): added more block overlay blocks support (CCBlueX#3906)
Browse files Browse the repository at this point in the history
Closes: CCBlueX#3905
  • Loading branch information
EclipsesDev committed Sep 8, 2024
1 parent 288d2e6 commit 7f9bb07
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import net.minecraft.block.Block
import net.minecraft.block.BlockBed
import net.minecraft.block.state.IBlockState
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager.resetColor
import net.minecraft.init.Blocks
import net.minecraft.util.BlockPos
import net.minecraft.util.ResourceLocation
Expand Down Expand Up @@ -363,6 +364,7 @@ object BedPlates : Module("BedPlates", Category.RENDER, hideModule = false) {
glDisable(GL_LINE_SMOOTH)
glDisable(GL_BLEND)
glEnable(GL_TEXTURE_2D)
resetColor()

glPopMatrix()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.ui.font.Fonts
import net.ccbluex.liquidbounce.utils.block.BlockUtils.canBeClicked
import net.ccbluex.liquidbounce.utils.block.BlockUtils.getBlock
import net.ccbluex.liquidbounce.utils.extensions.center
import net.ccbluex.liquidbounce.utils.extensions.component1
import net.ccbluex.liquidbounce.utils.extensions.component2
import net.ccbluex.liquidbounce.utils.render.ColorUtils.rainbow
Expand Down Expand Up @@ -66,7 +67,6 @@ object BlockOverlay : Module("BlockOverlay", Category.RENDER, gameDetecting = fa

block.setBlockBoundsBasedOnState(mc.theWorld, blockPos)


val thePlayer = mc.thePlayer ?: return

val x = thePlayer.lastTickPosX + (thePlayer.posX - thePlayer.lastTickPosX) * partialTicks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import net.ccbluex.liquidbounce.utils.PacketUtils.sendPacket
import net.ccbluex.liquidbounce.utils.Rotation
import net.ccbluex.liquidbounce.utils.RotationUtils
import net.ccbluex.liquidbounce.utils.RotationUtils.getVectorForRotation
import net.ccbluex.liquidbounce.utils.block.BlockUtils.isFullBlock
import net.ccbluex.liquidbounce.utils.block.BlockUtils.isBlockBBValid
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.inventory.InventoryUtils
import net.ccbluex.liquidbounce.utils.inventory.InventoryUtils.serverSlot
Expand Down Expand Up @@ -307,7 +307,7 @@ object BedDefender : Module("BedDefender", Category.WORLD, hideModule = false) {
movingObjectPosition != null && movingObjectPosition.blockPos == pos
}

"around" -> EnumFacing.values().any { !isFullBlock(pos.offset(it)) }
"around" -> EnumFacing.values().any { !isBlockBBValid(pos.offset(it)) }

else -> true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import net.ccbluex.liquidbounce.utils.RotationUtils.toRotation
import net.ccbluex.liquidbounce.utils.block.BlockUtils.getBlock
import net.ccbluex.liquidbounce.utils.block.BlockUtils.getBlockName
import net.ccbluex.liquidbounce.utils.block.BlockUtils.getCenterDistance
import net.ccbluex.liquidbounce.utils.block.BlockUtils.isFullBlock
import net.ccbluex.liquidbounce.utils.block.BlockUtils.isBlockBBValid
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.render.RenderUtils.disableGlCap
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawBlockBox
Expand Down Expand Up @@ -450,7 +450,7 @@ object Fucker : Module("Fucker", Category.WORLD, hideModule = false) {
movingObjectPosition != null && movingObjectPosition.blockPos == blockPos
}

"around" -> EnumFacing.values().any { !isFullBlock(blockPos.offset(it)) }
"around" -> EnumFacing.values().any { !isBlockBBValid(blockPos.offset(it)) }

else -> true
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/net/ccbluex/liquidbounce/utils/block/BlockUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object BlockUtils : MinecraftInstance() {
val block = state.block ?: return false

return block.canCollideCheck(state, false) && blockPos in mc.theWorld.worldBorder && !block.material.isReplaceable
&& !block.hasTileEntity(state) && isFullBlock(blockPos, state, true)
&& !block.hasTileEntity(state) && isBlockBBValid(blockPos, state, supportSlabs = true, supportPartialBlocks = true)
&& mc.theWorld.loadedEntityList.find { it is EntityFallingBlock && it.position == blockPos } == null
&& block !is BlockContainer && block !is BlockWorkbench
}
Expand All @@ -55,13 +55,18 @@ object BlockUtils : MinecraftInstance() {
fun getBlockName(id: Int): String = Block.getBlockById(id).localizedName

/**
* Check if block is full block
* Check if block bounding box is full or partial (non-full)
*/
fun isFullBlock(blockPos: BlockPos, blockState: IBlockState? = null, supportSlabs: Boolean = false): Boolean {
fun isBlockBBValid(blockPos: BlockPos, blockState: IBlockState? = null, supportSlabs: Boolean = false, supportPartialBlocks: Boolean = false): Boolean {
val state = blockState ?: getState(blockPos) ?: return false

val box = state.block.getCollisionBoundingBox(mc.theWorld, blockPos, state) ?: return false

// Support blocks like stairs, slab (1x), dragon-eggs, glass-panes, fences, etc
if (supportPartialBlocks && (box.maxY - box.minY < 1.0 || box.maxX - box.minX < 1.0 || box.maxZ - box.minZ < 1.0)) {
return true
}

// The slab will only return true if it's placed at a level that can be placed like any normal full block
return box.maxX - box.minX == 1.0 && (box.maxY - box.minY == 1.0 || supportSlabs && box.maxY % 1.0 == 0.0) && box.maxZ - box.minZ == 1.0
}
Expand Down

0 comments on commit 7f9bb07

Please sign in to comment.