From 480bf3577eef18a545e271bbcd246c9615e05ef0 Mon Sep 17 00:00:00 2001 From: Colton Date: Thu, 27 Jun 2024 23:27:46 -0400 Subject: [PATCH] Added other projectiles to Trajectory --- src/main/java/net/aoba/misc/ModuleUtils.java | 16 +- .../module/modules/render/Trajectory.java | 182 ++++++++++-------- 2 files changed, 103 insertions(+), 95 deletions(-) diff --git a/src/main/java/net/aoba/misc/ModuleUtils.java b/src/main/java/net/aoba/misc/ModuleUtils.java index 93313c85..c0b048ea 100644 --- a/src/main/java/net/aoba/misc/ModuleUtils.java +++ b/src/main/java/net/aoba/misc/ModuleUtils.java @@ -34,25 +34,11 @@ public class ModuleUtils { public static boolean isThrowable(ItemStack stack) { Item item = stack.getItem(); - return item instanceof BowItem || item instanceof SnowballItem || item instanceof EggItem + return item == Items.BOW || item == Items.SNOWBALL || item == Items.EGG || item instanceof EnderPearlItem || item instanceof SplashPotionItem || item instanceof LingeringPotionItem || item instanceof FishingRodItem; } - public static double throwableGravity(Item item) { - if(item instanceof RangedWeaponItem) { - return 0.05; - }else if(item instanceof ThrowablePotionItem) { - return 0.4; - }else if(item instanceof FishingRodItem) { - return 0.15; - }else if(item instanceof TridentItem) { - return 0.015; - }else { - return 0.03; - } - } - public static boolean isPlantable(ItemStack stack) { Item item = stack.getItem(); return item == Items.WHEAT_SEEDS || item == Items.CARROT || item == Items.POTATO; diff --git a/src/main/java/net/aoba/module/modules/render/Trajectory.java b/src/main/java/net/aoba/module/modules/render/Trajectory.java index 873d9063..26938a03 100644 --- a/src/main/java/net/aoba/module/modules/render/Trajectory.java +++ b/src/main/java/net/aoba/module/modules/render/Trajectory.java @@ -48,7 +48,13 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.ProjectileUtil; import net.minecraft.item.BowItem; +import net.minecraft.item.FishingRodItem; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.item.RangedWeaponItem; +import net.minecraft.item.ThrowablePotionItem; +import net.minecraft.item.TridentItem; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.HitResult; @@ -60,15 +66,16 @@ public class Trajectory extends Module implements RenderListener { private ColorSetting color = new ColorSetting("trajectory_color", "Color", "Color", new Color(0, 1f, 1f)); - private FloatSetting blipSize = new FloatSetting("trajectory_blipsize", "Blip Size", "Blip Size", 0.15f, 0.05f, 1.0f, 0.05f); - + private FloatSetting blipSize = new FloatSetting("trajectory_blipsize", "Blip Size", "Blip Size", 0.15f, 0.05f, + 1.0f, 0.05f); + public Trajectory() { super(new KeybindSetting("key.trajectory", "Trajectory Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0))); - + this.setName("Trajectory"); this.setCategory(Category.Render); this.setDescription("Allows the player to see where they are aiming. (DISABLED)"); - + this.addSetting(color); this.addSetting(blipSize); } @@ -87,88 +94,103 @@ public void onEnable() { public void onToggle() { } - + @Override public void OnRender(RenderEvent event) { - if(MC.player.isUsingItem()) { - Color renderColor = color.getValue(); - Matrix4f matrix = event.GetMatrix().peek().getPositionMatrix(); - - ItemStack itemStack = MC.player.getActiveItem(); - if(ModuleUtils.isThrowable(itemStack)) { - float initialVelocity = (52f * BowItem.getPullProgress(MC.player.getItemUseTime())); - - Camera camera = MC.gameRenderer.getCamera(); - Vec3d offset = RenderUtils.getEntityPositionOffsetInterpolated(MC.cameraEntity, event.GetPartialTicks()); - Vec3d eyePos = MC.cameraEntity.getEyePos(); - - // Calculate look direction. - Vec3d right = Vec3d.fromPolar(0, camera.getYaw() + 90).multiply(0.14f); - Vec3d lookDirection = Vec3d.fromPolar(camera.getPitch(), camera.getYaw()); - Vec3d velocity = lookDirection.multiply(initialVelocity).multiply(0.2f); - - // Calculate starting point. - Vec3d prevPoint = new Vec3d(0, 0, 0).add(eyePos).subtract(offset).add(right); - Vec3d landPosition = null; - - RenderSystem.setShaderColor(renderColor.getRedFloat(), renderColor.getGreenFloat(), renderColor.getBlueFloat(), renderColor.getAlphaFloat()); - - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_DEPTH_TEST); - - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - RenderSystem.setShader(GameRenderer::getPositionProgram); - BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION); - - for(int iteration = 0; iteration < 150; iteration++){ - Vec3d nextPoint = prevPoint.add(velocity.multiply(0.1)); - bufferBuilder.vertex(matrix, (float) prevPoint.x, (float) prevPoint.y, (float) prevPoint.z); - - // Check to see if we have collided with a block. - RaycastContext context = new RaycastContext(prevPoint, nextPoint, RaycastContext.ShapeType.COLLIDER, FluidHandling.NONE, MC.player); - BlockHitResult result = MC.world.raycast(context); - if(result.getType() != HitResult.Type.MISS) { - // Arrow is collided with a block, draw one last vertice and set land position to the raycast result position. - landPosition = result.getPos(); - bufferBuilder.vertex(matrix, (float) landPosition.x, (float) landPosition.y, (float) landPosition.z); + Color renderColor = color.getValue(); + Matrix4f matrix = event.GetMatrix().peek().getPositionMatrix(); + + ItemStack itemStack = MC.player.getMainHandStack(); + if (ModuleUtils.isThrowable(itemStack)) { + + // Get Velocity + float initialVelocity = (52f); + if (itemStack.getItem() == Items.BOW && MC.player.isUsingItem()) + initialVelocity *= BowItem.getPullProgress(MC.player.getItemUseTime()); + + Camera camera = MC.gameRenderer.getCamera(); + Vec3d offset = RenderUtils.getEntityPositionOffsetInterpolated(MC.cameraEntity, event.GetPartialTicks()); + Vec3d eyePos = MC.cameraEntity.getEyePos(); + + // Calculate look direction. + Vec3d right = Vec3d.fromPolar(0, camera.getYaw() + 90).multiply(0.14f); + Vec3d lookDirection = Vec3d.fromPolar(camera.getPitch(), camera.getYaw()); + Vec3d velocity = lookDirection.multiply(initialVelocity).multiply(0.2f); + + // Calculate starting point. + Vec3d prevPoint = new Vec3d(0, 0, 0).add(eyePos).subtract(offset).add(right); + Vec3d landPosition = null; + + RenderSystem.setShaderColor(renderColor.getRedFloat(), renderColor.getGreenFloat(), + renderColor.getBlueFloat(), renderColor.getAlphaFloat()); + + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_DEPTH_TEST); + + Tessellator tessellator = RenderSystem.renderThreadTesselator(); + RenderSystem.setShader(GameRenderer::getPositionProgram); + BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION); + + for (int iteration = 0; iteration < 150; iteration++) { + Vec3d nextPoint = prevPoint.add(velocity.multiply(0.1)); + bufferBuilder.vertex(matrix, (float) prevPoint.x, (float) prevPoint.y, (float) prevPoint.z); + + // Check to see if we have collided with a block. + RaycastContext context = new RaycastContext(prevPoint, nextPoint, RaycastContext.ShapeType.COLLIDER, + FluidHandling.NONE, MC.player); + BlockHitResult result = MC.world.raycast(context); + if (result.getType() != HitResult.Type.MISS) { + // Arrow is collided with a block, draw one last vertice and set land position + // to the raycast result position. + landPosition = result.getPos(); + bufferBuilder.vertex(matrix, (float) landPosition.x, (float) landPosition.y, + (float) landPosition.z); + break; + } else { + // We did NOT find a collision with a block, check entities. + Box box = new Box(prevPoint, nextPoint); + Predicate predicate = e -> !e.isSpectator() && e.canHit(); + EntityHitResult entityResult = ProjectileUtil.raycast(MC.player, prevPoint, nextPoint, box, + predicate, 4096); + + if (entityResult != null && entityResult.getType() != HitResult.Type.MISS) { + // Arrow is collided with an entity, draw one last vertice and set land position + // to the raycast result position. + landPosition = entityResult.getPos(); + bufferBuilder.vertex(matrix, (float) landPosition.x, (float) landPosition.y, + (float) landPosition.z); break; - }else { - // We did NOT find a collision with a block, check entities. - Box box = new Box(prevPoint, nextPoint); - Predicate predicate = e -> !e.isSpectator() && e.canHit(); - EntityHitResult entityResult = ProjectileUtil.raycast(MC.player, prevPoint, nextPoint, box, predicate, 4096); - - if(entityResult != null && entityResult.getType() != HitResult.Type.MISS) { - // Arrow is collided with an entity, draw one last vertice and set land position to the raycast result position. - landPosition = entityResult.getPos(); - bufferBuilder.vertex(matrix, (float) landPosition.x, (float) landPosition.y, (float) landPosition.z); - break; - }else { - // No collisions from raycast, draw next vertice. - bufferBuilder.vertex(matrix, (float) nextPoint.x, (float) nextPoint.y, (float) nextPoint.z); - } + } else { + // No collisions from raycast, draw next vertice. + bufferBuilder.vertex(matrix, (float) nextPoint.x, (float) nextPoint.y, (float) nextPoint.z); } - - prevPoint = nextPoint; - velocity = velocity.multiply(0.99).add(0, -0.045f, 0); - } - - - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - RenderSystem.setShaderColor(1, 1, 1, 1); - - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glDisable(GL11.GL_BLEND); - - // Draw Cube if a landing position exists. - if(landPosition != null) { - float size = blipSize.getValue(); - Vec3d pos1 = landPosition.add(-size, -size, -size); - Vec3d pos2 = landPosition.add(size, size, size); - Box box = new Box(pos1.x, pos1.y, pos1.z, pos2.x, pos2.y, pos2.z); - RenderUtils.draw3DBox(matrix, box, renderColor); } + + prevPoint = nextPoint; + velocity = velocity.multiply(0.99).add(0, throwableGravity(itemStack.getItem()), 0); + } + + BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + RenderSystem.setShaderColor(1, 1, 1, 1); + + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_BLEND); + + // Draw Cube if a landing position exists. + if (landPosition != null) { + float size = blipSize.getValue(); + Vec3d pos1 = landPosition.add(-size, -size, -size); + Vec3d pos2 = landPosition.add(size, size, size); + Box box = new Box(pos1.x, pos1.y, pos1.z, pos2.x, pos2.y, pos2.z); + RenderUtils.draw3DBox(matrix, box, renderColor); } } } + + public double throwableGravity(Item item) { + if(item == Items.BOW) + return -0.045f; + else + return -0.13f; + } } \ No newline at end of file