Skip to content

Commit

Permalink
Merge pull request #3 from N3ROO/MC_1.16.2_dev
Browse files Browse the repository at this point in the history
Mc 1.16.2 dev
  • Loading branch information
lilgallon authored Sep 5, 2020
2 parents 196cdee + ad25911 commit 08029e1
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 29 deletions.
Binary file added .github/images/1_2_0_before_update.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/1_2_0_smart_aim.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/1_2_0_smart_aim_captions.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## Version 1.2.0

- Smart block aim assistance

**BEFORE:**
![before](.github/images/1_2_0_before_update.gif)

**AFTER:**

It will recognize the block that you're trying to break.
![smart aim](.github/images/1_2_0_smart_aim.gif)

But, if you want to change the block that you're breaking, just move your mouse.
![smart aim](.github/images/1_2_0_smart_aim_captions.gif)

- Improved attack assistance (it puts your crosshair higher than before)
- Increased attack assistance duration (1 sec -> 1.7 sec)
- The assistance won't be running while you're in GUIs


## Version 1.1.0

- Built for forge 1.16.2 (also works with forge 1.16.1)
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.1.0-MC1.16.2'
version = '1.2.0-MC1.16.2'
group = 'dev.nero.aimassistance' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'aimassistance'

Expand All @@ -34,7 +34,7 @@ minecraft {
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
aimassistancemod {
source sourceSets.main
}
}
Expand All @@ -43,5 +43,5 @@ minecraft {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.16.2-33.0.21'
minecraft 'net.minecraftforge:forge:1.16.2-33.0.37'
}
4 changes: 3 additions & 1 deletion src/main/java/dev/nero/aimassistance/AimAssistanceMod.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package dev.nero.aimassistance;

import dev.nero.aimassistance.config.Config;
import dev.nero.aimassistance.module.AimAssistance;
import dev.nero.aimassistance.core.AimAssistance;
import dev.nero.aimassistance.utils.MouseUtils;
import dev.nero.aimassistance.utils.Wrapper;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
Expand Down Expand Up @@ -55,6 +56,7 @@ public void onPlayerTick(TickEvent.PlayerTickEvent playerTickEvent) {
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent clientTickEvent) {
if (Wrapper.playerPlaying()) {
MouseUtils.checkForMouseMove();
aimAssistance.analyseEnvironment();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.nero.aimassistance.module;
package dev.nero.aimassistance.core;

import dev.nero.aimassistance.config.Config;
import dev.nero.aimassistance.utils.MouseUtils;
import dev.nero.aimassistance.utils.TimeHelper;
import dev.nero.aimassistance.utils.Wrapper;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class AimAssistance {
private final float INTERACTION_ATTACK_SPEED = 1f / 1000f; // (attacks per ms) user faster means user attacking
private final int INTERACTION_ATTACK_DURATION = 2000; // (ms) duration after which we give up
private final int INTERACTION_MINING_DURATION = 500; // (ms) duration the player needs to be mining to assist
private final int ASSISTANCE_ATTACK_DURATION = 1000; // (ms) duration during which the assistance will assist on mobs
private final int ASSISTANCE_ATTACK_DURATION = 1700; // (ms) duration during which the assistance will assist on mobs
private final int ASSISTANCE_MINING_DURATION = 300; // (ms) duration during which the assistance will assist on blocks
private final float RANGE_TO_SCAN = 5; // (blocks) range to scan from the player to find entities
private final Class<? extends Entity> ENTITY_TYPE_TO_SCAN = MobEntity.class; // defines the type of entity to scan
Expand Down Expand Up @@ -109,6 +110,8 @@ else if (!this.miningTimer.isDelayComplete(this.INTERACTION_MINING_DURATION) &&
// Else (means that the player is mining) if the player has been mining for the given duration, then they're
// interacting
else if (this.miningTimer.isDelayComplete(this.INTERACTION_MINING_DURATION) && Wrapper.attackKeyPressed()) {
this.attackTimer.stop();

this.miningTimer.stop();
this.interactionTimer.start(); // it will reset if already started, so we're all good
this.interactingWith = TargetType.BLOCK;
Expand Down Expand Up @@ -141,6 +144,8 @@ else if (this.attackCount > 0 && playerAttacks) {
// If player's attack speed is greater than the speed given to toggle the assistance, then we can tell to
// the instance that the player is interacting
if (speed > this.INTERACTION_ATTACK_SPEED) {
this.miningTimer.stop();

// We need to reset the variables that are used to define if the player is interacting because we know
// that the user is interacting right now
this.attackCount = 0;
Expand Down Expand Up @@ -191,7 +196,33 @@ public void assistIfPossible() {
aimForce, aimForce // forceX, forceY
);

Wrapper.setRotations(rotations[0], rotations[1]);
boolean assist = true;

// We need to prevent focusing an other block while assisting if the player is not moving his mouse
if (this.interactingWith == TargetType.BLOCK && !MouseUtils.mouseMoved()) {
BlockRayTraceResult nextBlock = Wrapper.rayTrace(
this.BLOCK_REACH, Wrapper.MC.player.getEyePosition(1.0F), rotations[0], rotations[1]
);

// If, after moving the mouse, an other block is focused, then don't assist
if (nextBlock != null && this.target.getTarget() != null) {
if (this.target.getTarget() instanceof BlockRayTraceResult) {

BlockPos next = nextBlock.getPos();
BlockPos curr = ((BlockRayTraceResult) this.target.getTarget()).getPos();

assist = (
next.getX() == curr.getX() &&
next.getY() == curr.getY() &&
next.getZ() == curr.getZ()
);
} else {
assist = false;
}
}
}

if (assist) Wrapper.setRotations(rotations[0], rotations[1]);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.nero.aimassistance.module;
package dev.nero.aimassistance.core;

import net.minecraft.entity.Entity;
import net.minecraft.util.Direction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.nero.aimassistance.module;
package dev.nero.aimassistance.core;

public enum TargetType {
ENTITY, BLOCK, NONE
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/dev/nero/aimassistance/utils/MouseUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dev.nero.aimassistance.utils;

/**
* Need this class because forge did not implement the mouse move event. They did for the scroll and
* input events, but not when the mouse moves.
*/
public class MouseUtils {

private static boolean mouseMoved;

private static int delay = 2;
private static double prevX = -1;
private static double prevY = -1;

public static void checkForMouseMove() {
double currX = Wrapper.MC.mouseHelper.getMouseX();
double currY = Wrapper.MC.mouseHelper.getMouseY();

if (prevX != -1 && prevY != -1) {
mouseMoved = prevX != currX || prevY != currY;
}

if (delay == 0) {
prevX = currX;
prevY = currY;
delay = 2;
} else {
delay --;
}
}

public static boolean mouseMoved() {
return mouseMoved;
}
}
50 changes: 33 additions & 17 deletions src/main/java/dev/nero/aimassistance/utils/Wrapper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.nero.aimassistance.utils;

import dev.nero.aimassistance.module.Target;
import dev.nero.aimassistance.module.TargetType;
import dev.nero.aimassistance.core.Target;
import dev.nero.aimassistance.core.TargetType;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.*;
Expand All @@ -17,7 +17,7 @@ public class Wrapper {
* @return true if the player is playing
*/
public static boolean playerPlaying() {
return Wrapper.MC.player != null;
return Wrapper.MC.player != null && Wrapper.MC.currentScreen == null;
}

/**
Expand Down Expand Up @@ -45,28 +45,28 @@ public static BlockRayTraceResult getPointedBlock(float maxRange) {
}

/**
* Copied from Item#rayTrace, and updated
* Performs ray tracing
*
* @param range range to perform ray tracing
* @return result of ray tracing from the player's view within the range
* @param range the max range to look for blocks - it's actually the vector's length)
* @param source the source position - it's actually the vector's position)
* @param yaw the raw of the unit from that source - it's the vector's x/z (horizontal) direction
* @param pitch the pitch of the vector from that source - it's the vector's y (vertical) direction
* @return target.getPos() is instance of BlockPos.Mutable if nothing found, else it's an instance of the thing found.
*/
private static BlockRayTraceResult rayTrace(double range) {
public static BlockRayTraceResult rayTrace(double range, Vector3d source, float yaw, float pitch) {
if (Wrapper.MC.player == null) return null;

float f = Wrapper.MC.player.rotationPitch;
float f1 = Wrapper.MC.player.rotationYaw;
Vector3d vector3d = Wrapper.MC.player.getEyePosition(1.0F);
float f2 = MathHelper.cos(-f1 * ((float)Math.PI / 180F) - (float)Math.PI);
float f3 = MathHelper.sin(-f1 * ((float)Math.PI / 180F) - (float)Math.PI);
float f4 = -MathHelper.cos(-f * ((float)Math.PI / 180F));
float f5 = MathHelper.sin(-f * ((float)Math.PI / 180F));
float f2 = MathHelper.cos(- yaw * ((float) Math.PI / 180F) - (float) Math.PI);
float f3 = MathHelper.sin(- yaw * ((float) Math.PI / 180F) - (float) Math.PI);
float f4 = -MathHelper.cos(- pitch * ((float) Math.PI / 180F));
float f5 = MathHelper.sin(- pitch * ((float) Math.PI / 180F));
float f6 = f3 * f4;
float f7 = f2 * f4;
Vector3d vector3d1 = vector3d.add((double)f6 * range, (double)f5 * range, (double)f7 * range);
Vector3d vector3d1 = source.add((double)f6 * range, (double)f5 * range, (double)f7 * range);

return Wrapper.MC.world.rayTraceBlocks(
new RayTraceContext(
vector3d,
source,
vector3d1,
RayTraceContext.BlockMode.OUTLINE,
RayTraceContext.FluidMode.NONE,
Expand All @@ -75,6 +75,22 @@ private static BlockRayTraceResult rayTrace(double range) {
);
}


/**
* Performs ray tracing by taking into account the player's view
*
* @param range range to perform ray tracing
* @return result of ray tracing from the player's view within the range
*/
private static BlockRayTraceResult rayTrace(double range) {
return Wrapper.rayTrace(
range,
Wrapper.MC.player.getEyePosition(1.0F),
Wrapper.MC.player.rotationPitch,
Wrapper.MC.player.rotationYaw
);
}

/**
* @param range in blocks, defines the range around the player to scan for entities
* @param entityClass the entity type to look for (Check the Entity class: MobEntity.class for mobs for example)
Expand Down Expand Up @@ -130,7 +146,7 @@ public static float[] getYawPitchBetween(Entity source, Entity target) {
// getPosY returns the ground position
// getPosY + EyeHeight return the eye's position
// getPosY + EyeHeight/1.5 returns the upper body position
final float SHIFT_FACTOR = 1.5f;
final float SHIFT_FACTOR = 1.25f;

return Wrapper.getYawPitchBetween(
// source
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license="MIT License"

[[mods]]
modId="aimassistancemod"
version="1.1.0"
version="1.2.0"
displayName="Aim Assistance"
updateJSONURL="https://raw.githubusercontent.com/N3ROO/AimAssistanceMod/MC_1.16.2/update.json"
displayURL="https://github.com/N3ROO/AimAssistanceMod/"
Expand Down
4 changes: 2 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"homepage": "https://github.com/N3ROO/AimAssistanceMod/releases",
"promos": {
"1.16.2-latest": "1.1.0",
"1.16.2-recommended": "1.1.0"
"1.16.2-latest": "1.2.0",
"1.16.2-recommended": "1.2.0"
}
}

0 comments on commit 08029e1

Please sign in to comment.