Some optimization for Utils

  • BlockUtils.kt

    //All start position is from the player's eyes
    fun getCenterDistance(blockPos: BlockPos) = mc.thePlayer.getPositionEyes(mc.getRenderPartialTicks()).distanceTo(blockPos.vec)
    //from LB ChestAura.(simplified)
    fun canBlockBeSeen(blockPos: BlockPos) = mc.theWorld.rayTraceBlocks(mc.thePlayer.getPositionEyes(mc.renderPartialTicks), blockPos.vec, false, false, false)?.blockPos == blockPos
    //getAllInBox -> Iterable<BlockPos>
    fun searchBlocks(radius: Int): Map<BlockPos, Block> = BlockPos.getAllInBox(BlockPos(mc.thePlayer.getPositionEyes(mc.renderPartialTicks).addVector(-radius.toDouble(), -radius.toDouble(), -radius.toDouble())), BlockPos(mc.thePlayer.getPositionEyes(mc.renderPartialTicks).addVector(radius.toDouble(), radius.toDouble(), radius.toDouble()))).map { it to getBlock(it) }.toMap()

    My BlockPos.getVec():

         * Get the center position of this BlockPos
        public Vec3 getVec() {
        	final AxisAlignedBB axisAlignedBB = Minecraft.theWorld.getBlockState(this).getBoundingBox(Minecraft.theWorld, this);
        	return new Vec3(getX() + 0.5 * (axisAlignedBB.maxX + axisAlignedBB.minX), getY() + 0.5 * (axisAlignedBB.maxY + axisAlignedBB.minY), getZ() + 0.5 * (axisAlignedBB.maxZ + axisAlignedBB.minZ));

    PS: I have seen BlockPos.getVec() in LB's ChestAura, but it doesn't exist in ScriptAPI and MCP. (and I want to ask why u used getter in .kt class?
    BlockESP should use searchBlocks too.

Log in to reply