Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.57 KB | None | 0 0
  1. package me.dukeson.calum.mod.mods;
  2.  
  3. import me.dukeson.calum.mod.Mod;
  4. import me.dukeson.calum.utils.helpers.DrawHelper;
  5. import net.minecraft.block.state.IBlockState;
  6. import net.minecraft.init.Blocks;
  7. import net.minecraft.item.ItemCloth;
  8. import net.minecraft.util.math.BlockPos;
  9. import net.minecraft.util.math.MathHelper;
  10.  
  11. import java.awt.*;
  12. import java.util.ArrayList;
  13.  
  14. public class BlockPartsBot extends Mod {
  15.  
  16.     public BlockPartsBot() {
  17.         super("BlockPartsBot", "B", 0xff00ff, Category.SCRIPT);
  18.     }
  19.  
  20.     private final int minX = -32;
  21.     private final int maxX = 16;
  22.     private final double y = 0.5;
  23.     private final int minZ = -16;
  24.     private final int maxZ = 32;
  25.  
  26.     private ArrayList<Color> blockColor;
  27.  
  28.     {
  29.         blockColor = new ArrayList() {{
  30.             add(new Color(254, 254, 254));
  31.             add(new Color(218, 120, 54));
  32.             add(new Color(177, 68, 186));
  33.             add(new Color(80, 117, 192));
  34.             add(new Color(166, 156, 36));
  35.             add(new Color(55, 150, 48));
  36.             add(new Color(209, 135, 154));
  37.             add(new Color(57, 57, 57));
  38.             add(new Color(146, 154, 154));
  39.             add(new Color(40, 96, 120));
  40.             add(new Color(137, 70, 194));
  41.             add(new Color(49, 61, 149));
  42.             add(new Color(78, 49, 30));
  43.             add(new Color(46, 62, 24));
  44.             add(new Color(141, 47, 45));
  45.             add(new Color(17, 13, 13));
  46.         }};
  47.     }
  48.  
  49.     private ArrayList<BlockPos> matchingBlocks = new ArrayList<>();
  50.     private BlockPos closestMatchingBlock;
  51.  
  52.     private int colorindex = -1;
  53.  
  54.     public void update() {
  55.         if (isActive()) {
  56.             matchingBlocks.clear();
  57.             colorindex = mc.player.inventory.getStackInSlot(4).getItem() instanceof ItemCloth ? mc.player.inventory.getStackInSlot(4).getMetadata() : -1;
  58.             if (colorindex == -1) closestMatchingBlock = null;
  59.             for (double x = minX + 0.5; x < maxX; x++) {
  60.                 for (double z = minZ + 0.5; z < maxZ; z++) {
  61.                     BlockPos bp = new BlockPos(x, y, z);
  62.                     IBlockState iBlockState = mc.world.getBlockState(bp);
  63.                     if (iBlockState.getBlock() == Blocks.CLAY || iBlockState.getBlock() == Blocks.HARDENED_CLAY || iBlockState.getBlock() == Blocks.STAINED_HARDENED_CLAY || iBlockState.getBlock() == Blocks.WOOL) {
  64.                         int index = iBlockState.getBlock().getMetaFromState(iBlockState);
  65.                         if (index == colorindex) {
  66.                             matchingBlocks.add(bp);
  67.                         }
  68.                     }
  69.                 }
  70.             }
  71.  
  72.             double distance = Double.MAX_VALUE;
  73.             for (BlockPos blockPos : matchingBlocks) {
  74.                 double x = blockPos.getX() - mc.player.posX;
  75.                 double z = blockPos.getZ() - mc.player.posZ;
  76.  
  77.                 double d = Math.sqrt(x * x + z * z);
  78.                 if (d < distance) {
  79.                     distance = d;
  80.                     closestMatchingBlock = blockPos;
  81.                 }
  82.             }
  83.  
  84.             if (closestMatchingBlock != null) {
  85.                 if (colorindex != mc.world.getBlockState(new BlockPos(mc.player.posX, mc.player.posY - 0.377d, mc.player.posZ)).getBlock().getMetaFromState(mc.world.getBlockState(new BlockPos(mc.player.posX, mc.player.posY - 0.377d, mc.player.posZ)))) {
  86.                     double x = closestMatchingBlock.getX() - mc.player.posX;
  87.                     double z = closestMatchingBlock.getZ() - mc.player.posZ;
  88.  
  89.                     float yaw = (float) ((Math.atan2(z, x) * 180.0d / Math.PI) - 90.0f);
  90.                     mc.player.rotationYaw = mc.player.rotationYaw + MathHelper.wrapDegrees(yaw - mc.player.rotationYaw);
  91.                     mc.gameSettings.keyBindSprint.pressed = true;
  92.                     mc.gameSettings.keyBindForward.pressed = true;
  93.                 } else {
  94.                     mc.gameSettings.keyBindSprint.pressed = false;
  95.                     mc.gameSettings.keyBindForward.pressed = false;
  96.                 }
  97.             } else {
  98.                 mc.gameSettings.keyBindSprint.pressed = false;
  99.                 mc.gameSettings.keyBindForward.pressed = false;
  100.             }
  101.         }
  102.     }
  103.  
  104.     public void draw() {
  105.         if (isActive()) {
  106.  
  107.             for (BlockPos bp : matchingBlocks) {
  108.                 if (bp == closestMatchingBlock) DrawHelper.tracerLineToPos2(bp, blockColor.get(colorindex));
  109.                 else DrawHelper.tracerLineToPos(bp, blockColor.get(colorindex));
  110.             }
  111.            
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement