Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This class should be initialized in the Main class during the “FMLInitializationEvent” with
- // “FMLCommonHandler.instance().bus().register(new <your reach class name>());”
- // - D3V
- package <your package>;
- // import <your other class>; (if needed)
- import java.util.List;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.entity.EntityOtherPlayerMP;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItemFrame;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.ChatComponentText;
- import net.minecraft.util.MovingObjectPosition;
- import net.minecraft.util.Vec3;
- import net.minecraftforge.client.event.MouseEvent;
- import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
- import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
- public class <your class name> {
- private Entity pointedEntity;
- private MovingObjectPosition moving;
- private static float theReach = 3.0F;
- @SubscribeEvent
- public void onMouse(MouseEvent e) {
- try {
- if (moving != null && e.button == 0 && e.buttonstate) {
- Minecraft.getMinecraft().objectMouseOver = moving;
- }
- } catch (Exception er) {
- er.printStackTrace();
- }
- }
- @SubscribeEvent
- public void onClientTick(ClientTickEvent e) {
- if (Minecraft.getMinecraft().theWorld != null) {
- // theReach = <your other class>.theReach; (if you want to register reach with a command)
- getMouseOver(1.0F);
- }
- }
- private void getMouseOver(float partialTicks) {
- if (Minecraft.getMinecraft().getRenderViewEntity() != null && Minecraft.getMinecraft().theWorld != null) {
- Minecraft.getMinecraft().pointedEntity = null;
- double d0 = (double)theReach;
- moving = Minecraft.getMinecraft().getRenderViewEntity().rayTrace(d0, partialTicks);
- double d1 = d0;
- Vec3 vec3 = Minecraft.getMinecraft().getRenderViewEntity().getPositionEyes(partialTicks);
- if (moving != null) {
- d1 = moving.hitVec.distanceTo(vec3);
- }
- Vec3 vec31 = Minecraft.getMinecraft().getRenderViewEntity().getLook(partialTicks);
- Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
- pointedEntity = null;
- Vec3 vec33 = null;
- float f1 = 1.0F;
- 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));
- double d2 = d1;
- for(int i = 0; i < list.size(); ++i) {
- Entity entity = (Entity)list.get(i);
- if (entity.canBeCollidedWith()) {
- float f2 = 0.13F;
- AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expand((double)f2, (double)f2, (double)f2);
- MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
- if (axisalignedbb.isVecInside(vec3)) {
- if (0.0D < d2 || d2 == 0.0D) {
- pointedEntity = entity;
- vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
- d2 = 0.0D;
- }
- } else if (movingobjectposition != null) {
- double d3 = vec3.distanceTo(movingobjectposition.hitVec);
- if (d3 < d2 || d2 == 0.0D) {
- if (entity == Minecraft.getMinecraft().getRenderViewEntity().ridingEntity && !entity.canRiderInteract()) {
- if (d2 == 0.0D) {
- pointedEntity = entity;
- vec33 = movingobjectposition.hitVec;
- }
- } else {
- pointedEntity = entity;
- vec33 = movingobjectposition.hitVec;
- d2 = d3;
- }
- }
- }
- }
- }
- if (pointedEntity != null && (d2 < d1 || moving == null)) {
- moving = new MovingObjectPosition(pointedEntity, vec33);
- if (pointedEntity instanceof EntityLivingBase || pointedEntity instanceof EntityItemFrame) {
- Minecraft.getMinecraft().pointedEntity = pointedEntity;
- }
- }
- }
- }
- }
- // Link: http://bit.ly/reachmodcode
- // D3V: https://www.youtube.com/channel/UCaZSjarAwZqW4yTEC5Cq9aw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement