CCBlueX Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Writed casually BlockUtils.js

    Scripts
    3
    4
    237
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User last edited by Senk Ju

      var BlockPos = Java.type("net.minecraft.util.BlockPos");
      var Block = Java.type("net.minecraft.block.Block");
      
      /**
       * @returns {Block?} block
       * @param {BlockPos} blockPos 
       */
      function getBlock(blockPos) {
          return mc.theWorld.getBlockState(blockPos).getBlock();
      }
      
      /**
       * @returns {Map<BlockPos, Block>} blocks
       * @param {Number} radius 
       */
      function searchBlocks(radius) {
          var blocks = new Map(); radius |= 0;
          for (var x = -radius; x <= radius; x++) {
              for (var z = -radius; z <= radius; z++) {
                  for (var y = radius; z >= -radius; y--) {
                      var blockPos = new BlockPos(~~mc.thePlayer.posX + x, ~~mc.thePlayer.posY + y, ~~mc.thePlayer.posZ + z);
                      var block = getBlock(blockPos);
                      block && blocks.set(blockPos, block);
                  }
              }
          }
          return blocks;
      }
      
      function searchBlocks2(radius) {
          return new Map(BlockPos.getAllInBox(new BlockPos(mc.thePlayer.posX - radius, mc.thePlayer.posY - radius, mc.thePlayer.posZ - radius), 
              new BlockPos(mc.thePlayer.posX + radius, mc.thePlayer.posY + radius, mc.thePlayer.posZ + radius))
              .map(blockPos => [blockPos, getBlock(blockPos)]));
      }
      
      
      1 Reply Last reply Reply Quote 3
      • Temm
        Temm Moderator last edited by Temm

        Pretty Code. We need more people like you.

        1 Reply Last reply Reply Quote 0
        • ?
          A Former User last edited by

          @Temm thanks. but I don't think this script can run on LB. It's just a demo
          (may replace ?. with . then function 1&2 can work

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            Some explanation of code

            Following code in JavaScript equals number > 0 ? Math.floor(number) : Math.ceil(number)

            number |= 0
            ~~number
            

            But according to my test, ~~x is much faster than Math.floor(x) for random positive double value. So you can use bit operation instead of Math.floor(x) and parseInt(x)

            if (block != null) blocks.set(blockPos, block); can be simplified to if (block) blocks.set(blockPos, block); or just block && blocks.set(blockPos, block);
            Because null in JavaScript is considered as false value, and && operator will not do things after it if things before it is a false value.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            About
            • Terms of Service
            • Privacy Policy
            • Status
            • Contact Us
            Downloads
            • Releases
            • Source code
            • License
            Docs
            • Tutorials
            • CustomHUD
            • AutoSettings
            • ScriptAPI
            Community
            • Forum
            • Guilded
            • YouTube
            • Twitter
            • D.Tube