Skip to content

Commit

Permalink
Pre Renders Bow MeteorDevelopment#4765
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandBhasme committed Jul 24, 2024
1 parent acbee85 commit 9701594
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public class Trajectories extends Module {
.build()
);

private final Setting<Boolean> preRender = sgGeneral.add(new BoolSetting.Builder() // Render the trajectory
// beforehand
.name("Pre-render")
.description("Calculates and renders trajectories for Bow and Crossbow even before charging them")
.defaultValue(false)
.build()
);

private final Setting<Boolean> otherPlayers = sgGeneral.add(new BoolSetting.Builder()
.name("other-players")
.description("Calculates trajectories for other players.")
Expand Down Expand Up @@ -147,14 +155,15 @@ private void calculatePath(PlayerEntity player, double tickDelta) {
}

// Calculate paths
if (!simulator.set(player, itemStack, 0, accurate.get(), tickDelta)) return;
//Added one more parameter to the set method
if (!simulator.set(player, itemStack, preRender.get(), 0, accurate.get(), tickDelta)) return;
getEmptyPath().calculate();

if (itemStack.getItem() instanceof CrossbowItem && Utils.hasEnchantment(itemStack, Enchantments.MULTISHOT)) {
if (!simulator.set(player, itemStack, MULTISHOT_OFFSET, accurate.get(), tickDelta)) return; // left multishot arrow
if (!simulator.set(player, itemStack, preRender.get(), MULTISHOT_OFFSET, accurate.get(), tickDelta)) return; // left multishot arrow
getEmptyPath().calculate();

if (!simulator.set(player, itemStack, -MULTISHOT_OFFSET, accurate.get(), tickDelta)) return; // right multishot arrow
if (!simulator.set(player, itemStack, preRender.get(), -MULTISHOT_OFFSET, accurate.get(), tickDelta)) return; // right multishot arrow
getEmptyPath().calculate();
}
}
Expand Down Expand Up @@ -251,15 +260,13 @@ private void processHitResult(HitResult result) {
hitQuadZ1 -= 0.25;
hitQuadX2 += 0.25;
hitQuadZ2 += 0.25;
}
else if (r.getSide() == Direction.NORTH || r.getSide() == Direction.SOUTH) {
} else if (r.getSide() == Direction.NORTH || r.getSide() == Direction.SOUTH) {
hitQuadHorizontal = false;
hitQuadX1 -= 0.25;
hitQuadY1 -= 0.25;
hitQuadX2 += 0.25;
hitQuadY2 += 0.25;
}
else {
} else {
hitQuadHorizontal = false;
hitQuadZ1 -= 0.25;
hitQuadY1 -= 0.25;
Expand All @@ -268,8 +275,7 @@ else if (r.getSide() == Direction.NORTH || r.getSide() == Direction.SOUTH) {
}

points.add(Utils.set(vec3s.get(), result.getPos()));
}
else if (result.getType() == HitResult.Type.ENTITY) {
} else if (result.getType() == HitResult.Type.ENTITY) {
collidingEntity = ((EntityHitResult) result).getEntity();

points.add(Utils.set(vec3s.get(), result.getPos()).add(0, collidingEntity.getHeight() / 2, 0));
Expand All @@ -279,14 +285,20 @@ else if (result.getType() == HitResult.Type.ENTITY) {
public void render(Render3DEvent event) {
// Render path
for (Vector3d point : points) {
if (lastPoint != null) event.renderer.line(lastPoint.x, lastPoint.y, lastPoint.z, point.x, point.y, point.z, lineColor.get());
if (lastPoint != null)
event.renderer.line(lastPoint.x, lastPoint.y, lastPoint.z, point.x, point.y, point.z,
lineColor.get());
lastPoint = point;
}

// Render hit quad
if (hitQuad) {
if (hitQuadHorizontal) event.renderer.sideHorizontal(hitQuadX1, hitQuadY1, hitQuadZ1, hitQuadX1 + 0.5, hitQuadZ1 + 0.5, sideColor.get(), lineColor.get(), shapeMode.get());
else event.renderer.sideVertical(hitQuadX1, hitQuadY1, hitQuadZ1, hitQuadX2, hitQuadY2, hitQuadZ2, sideColor.get(), lineColor.get(), shapeMode.get());
if (hitQuadHorizontal)
event.renderer.sideHorizontal(hitQuadX1, hitQuadY1, hitQuadZ1, hitQuadX1 + 0.5, hitQuadZ1 + 0.5,
sideColor.get(), lineColor.get(), shapeMode.get());
else
event.renderer.sideVertical(hitQuadX1, hitQuadY1, hitQuadZ1, hitQuadX2, hitQuadY2, hitQuadZ2,
sideColor.get(), lineColor.get(), shapeMode.get());
}

// Render entity
Expand All @@ -296,7 +308,8 @@ public void render(Render3DEvent event) {
double z = (collidingEntity.getZ() - collidingEntity.prevZ) * event.tickDelta;

Box box = collidingEntity.getBoundingBox();
event.renderer.box(x + box.minX, y + box.minY, z + box.minZ, x + box.maxX, y + box.maxY, z + box.maxZ, sideColor.get(), lineColor.get(), shapeMode.get(), 0);
event.renderer.box(x + box.minX, y + box.minY, z + box.minZ, x + box.maxX, y + box.maxY, z + box.maxZ,
sideColor.get(), lineColor.get(), shapeMode.get(), 0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.MissHitResult;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ChargedProjectilesComponent;
import net.minecraft.component.type.FireworksComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.*;
import net.minecraft.entity.projectile.thrown.*;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.*;
import net.minecraft.text.Text;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.*;
import net.minecraft.world.RaycastContext;
import org.joml.Quaterniond;
import org.joml.Vector3d;

import java.util.List;

import static meteordevelopment.meteorclient.MeteorClient.mc;

public class ProjectileEntitySimulator {
Expand All @@ -40,12 +45,15 @@ public class ProjectileEntitySimulator {

// held items

public boolean set(Entity user, ItemStack itemStack, double simulated, boolean accurate, double tickDelta) {
public boolean set(Entity user, ItemStack itemStack, boolean prerender, double simulated, boolean accurate, double tickDelta) {
Item item = itemStack.getItem();

if (item instanceof BowItem) {
double charge = BowItem.getPullProgress(mc.player.getItemUseTime());
if (charge <= 0) return false;
if (charge <= 0 && !prerender)
return false;
else if (charge == 0 && prerender)
charge = 1; // render fully charged bow

set(user, 0, charge * 3, simulated, 0.05000000074505806, 0.6, accurate, tickDelta);
}
Expand Down

0 comments on commit 9701594

Please sign in to comment.