Advertisement
Guest User

Reach Code (Minecraft 1.8.9)

a guest
Aug 25th, 2018
2,890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.65 KB | None | 0 0
  1. // This class should be initialized in the Main class during the “FMLInitializationEvent” with
  2. // “FMLCommonHandler.instance().bus().register(new <your reach class name>());”
  3.  
  4. //   -  D3V
  5.  
  6.  
  7. package <your package>;
  8.  
  9. // import <your other class>; (if needed)
  10.  
  11. import java.util.List;
  12.  
  13. import net.minecraft.client.Minecraft;
  14. import net.minecraft.client.entity.EntityOtherPlayerMP;
  15. import net.minecraft.entity.Entity;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.item.EntityItemFrame;
  18. import net.minecraft.util.AxisAlignedBB;
  19. import net.minecraft.util.ChatComponentText;
  20. import net.minecraft.util.MovingObjectPosition;
  21. import net.minecraft.util.Vec3;
  22. import net.minecraftforge.client.event.MouseEvent;
  23. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  24. import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
  25.  
  26. public class <your class name> {
  27.  
  28.     private Entity pointedEntity;
  29.     private MovingObjectPosition moving;
  30.     private static float theReach = 3.0F;
  31.    
  32.     @SubscribeEvent
  33.     public void onMouse(MouseEvent e) {
  34.         try {
  35.             if (moving != null && e.button == 0 && e.buttonstate) {
  36.                 Minecraft.getMinecraft().objectMouseOver = moving;
  37.             }
  38.         } catch (Exception er) {
  39.             er.printStackTrace();
  40.         }
  41.     }
  42.  
  43.     @SubscribeEvent
  44.     public void onClientTick(ClientTickEvent e) {
  45.         if (Minecraft.getMinecraft().theWorld != null) {
  46.             // theReach = <your other class>.theReach; (if you want to register reach with a command)
  47.             getMouseOver(1.0F);
  48.         }
  49.     }
  50.    
  51.     private void getMouseOver(float partialTicks) {
  52.           if (Minecraft.getMinecraft().getRenderViewEntity() != null && Minecraft.getMinecraft().theWorld != null) {
  53.              Minecraft.getMinecraft().pointedEntity = null;
  54.              double d0 = (double)theReach;
  55.              moving = Minecraft.getMinecraft().getRenderViewEntity().rayTrace(d0, partialTicks);
  56.              double d1 = d0;
  57.              Vec3 vec3 = Minecraft.getMinecraft().getRenderViewEntity().getPositionEyes(partialTicks);
  58.              if (moving != null) {
  59.                 d1 = moving.hitVec.distanceTo(vec3);
  60.              }
  61.  
  62.              Vec3 vec31 = Minecraft.getMinecraft().getRenderViewEntity().getLook(partialTicks);
  63.              Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
  64.              pointedEntity = null;
  65.              Vec3 vec33 = null;
  66.              float f1 = 1.0F;
  67.              List list = Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity(Minecraft.getMinecraft().getRenderViewEntity(), Minecraft.getMinecraft().getRenderViewEntity().getEntityBoundingBox().addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0).expand((double)f1, (double)f1, (double)f1));
  68.              double d2 = d1;
  69.  
  70.              for(int i = 0; i < list.size(); ++i) {
  71.                 Entity entity = (Entity)list.get(i);
  72.                 if (entity.canBeCollidedWith()) {
  73.                    float f2 = 0.13F;
  74.                    AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expand((double)f2, (double)f2, (double)f2);
  75.                    MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
  76.                    if (axisalignedbb.isVecInside(vec3)) {
  77.                       if (0.0D < d2 || d2 == 0.0D) {
  78.                          pointedEntity = entity;
  79.                          vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
  80.                          d2 = 0.0D;
  81.                       }
  82.                    } else if (movingobjectposition != null) {
  83.                       double d3 = vec3.distanceTo(movingobjectposition.hitVec);
  84.                       if (d3 < d2 || d2 == 0.0D) {
  85.                          if (entity == Minecraft.getMinecraft().getRenderViewEntity().ridingEntity && !entity.canRiderInteract()) {
  86.                             if (d2 == 0.0D) {
  87.                                pointedEntity = entity;
  88.                                vec33 = movingobjectposition.hitVec;
  89.                             }
  90.                          } else {
  91.                             pointedEntity = entity;
  92.                             vec33 = movingobjectposition.hitVec;
  93.                             d2 = d3;
  94.                          }
  95.                       }
  96.                    }
  97.                 }
  98.              }
  99.  
  100.              if (pointedEntity != null && (d2 < d1 || moving == null)) {
  101.                 moving = new MovingObjectPosition(pointedEntity, vec33);
  102.                 if (pointedEntity instanceof EntityLivingBase || pointedEntity instanceof EntityItemFrame) {
  103.                    Minecraft.getMinecraft().pointedEntity = pointedEntity;
  104.                 }
  105.              }
  106.           }
  107.  
  108.        }
  109.    
  110. }
  111.  
  112.  
  113. // Link: http://bit.ly/reachmodcode
  114. // D3V: https://www.youtube.com/channel/UCaZSjarAwZqW4yTEC5Cq9aw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement