diff --git a/src/openonyx/features/render/TNTTimer.java b/src/openonyx/features/render/TNTTimer.java new file mode 100644 index 0000000..17ce5b4 --- /dev/null +++ b/src/openonyx/features/render/TNTTimer.java @@ -0,0 +1,67 @@ +package openonyx.features.render; + +import java.util.Iterator; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.util.Vec3; +import openonyx.features.Module; +import openonyx.features.ModuleCategory; +import openonyx.history.internal.ColorSetting; +import openonyx.render.Render2D; +import openonyx.render.WorldToScreen; +import openonyx.theme.Fonts; + +public final class TNTTimer extends Module { + public final ColorSetting color = new ColorSetting("Color", -41892); + + public void L(Render2D render2D, float f, float g, float h) { + TNTTimer tNTTimer1 = this; + if (tNTTimer1.isEnabled() && mc.theWorld != null && WorldToScreen.L()) { + Iterator iterator = mc.theWorld.loadedEntityList.iterator(); + + label24: + while (true) { + Iterator iterator1 = iterator; + + while (iterator1.hasNext()) { + Entity entity; + if (!((entity = (Entity)iterator.next()) instanceof EntityTNTPrimed)) { + continue label24; + } + + EntityTNTPrimed entityTNTPrimed = (EntityTNTPrimed)entity; + float[] i; + if (( + i = WorldToScreen.L( + new Vec3( + entityTNTPrimed.lastTickPosX + (entityTNTPrimed.posX - entityTNTPrimed.lastTickPosX) * h, + entityTNTPrimed.lastTickPosY + (entityTNTPrimed.posY - entityTNTPrimed.lastTickPosY) * h + 1.25, + entityTNTPrimed.lastTickPosZ + (entityTNTPrimed.posZ - entityTNTPrimed.lastTickPosZ) * h + ), + f, + g + ) + ) + == null) { + iterator1 = iterator; + } else { + Object[] objects = new Object[1]; + boolean bl = true; + objects[0] = Math.max(0.0F, (entityTNTPrimed.fuse - h) / 20.0F); + String string = String.format("%.1fs", objects); + iterator1 = iterator; + float j = render2D.getTextWidth(Fonts.FONT_STYLE11, string) + 8.0F; + render2D.roundedRect(i[0] - j / 2.0F, i[1] - 7.0F, j, 14.0F, 8.0F, -1206643431); + render2D.drawTextCenteredVCentered(Fonts.FONT_STYLE11, string, i[0], i[1], tNTTimer1.color.getOpaque()); + } + } + + return; + } + } + } + + public TNTTimer() { + super("TNTTimer", "Shows time remaining before TNT explodes", ModuleCategory.RENDER); + } +} diff --git a/src/openonyx/features/render/ThemeMode.java b/src/openonyx/features/render/ThemeMode.java new file mode 100644 index 0000000..9064901 --- /dev/null +++ b/src/openonyx/features/render/ThemeMode.java @@ -0,0 +1,29 @@ +package openonyx.features.render; + +import openonyx.history.DisplayNamed; + +public enum ThemeMode implements DisplayNamed { + FILL("Outline + fill"), + OUTLINE("Outline"), + GLINT("Outline + glint"); + + private final String H; + + ThemeMode(String string1) { + this.H = string1; + } + + private static ThemeMode[] L() { + ThemeMode[] themeModes = new ThemeMode[3]; + boolean bl = true; + themeModes[0] = OUTLINE; + themeModes[1] = FILL; + themeModes[2] = GLINT; + return themeModes; + } + + @Override + public String getDisplayName() { + return this.H; + } +} diff --git a/src/openonyx/features/render/Trails.java b/src/openonyx/features/render/Trails.java new file mode 100644 index 0000000..e2db462 --- /dev/null +++ b/src/openonyx/features/render/Trails.java @@ -0,0 +1,127 @@ +package openonyx.features.render; + +import java.util.ArrayList; +import java.util.List; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.util.Vec3; +import openonyx.configuration.internal.TickEndEvent; +import openonyx.configuration.internal.WorldChangeEvent; +import openonyx.features.Module; +import openonyx.features.ModuleCategory; +import openonyx.history.internal.BooleanSetting; +import openonyx.history.internal.ColorSetting; +import openonyx.history.internal.EnumSetting; +import openonyx.history.internal.NumberSetting; +import openonyx.render.group_m.TrailPoint; +import openonyx.render.group_m.TrailsRenderer; +import openonyx.render.group_m.TrailsStyle; + +public final class Trails extends Module { + public final NumberSetting pointSize; + private static final double L = 1.0E-8; + public final NumberSetting lineWidth; + public final NumberSetting opacity; + private static final float h = 0.8F; + public final EnumSetting mode = new EnumSetting<>("Mode", Mode.WALL); + public final NumberSetting length; + private final TrailsRenderer trailsRenderer; + private final List trailPoints; + public final BooleanSetting firstPerson; + public final BooleanSetting throughWalls; + public final ColorSetting color = new ColorSetting("Color", -10178561).D(); + + @Override + protected void onEnable() { + this.trailPoints.clear(); + } + + private TrailsStyle L() { + return new TrailsStyle( + this.mode.getValue(), + this.color.getOpaque(), + this.opacity.getFloat() / 100.0F, + (long)(this.length.getValue() * 1000.0), + this.lineWidth.getFloat(), + this.pointSize.getFloat(), + this.throughWalls.isEnabled() + ); + } + + private void h() { + long l = System.currentTimeMillis() - (long)(this.length.getValue() * 1000.0); + this.trailPoints.removeIf(trailPoint -> trailPoint.time() < l); + } + + public Trails() { + super("Trails", "Leaves a fading trail behind you", ModuleCategory.RENDER); + this.length = new NumberSetting("Length", 1.0, 0.25, 5.0, 0.05).withSuffix(" s").describe("How long the trail stays behind you"); + this.opacity = new NumberSetting("Opacity", 60.0, 5.0, 100.0, 1.0).withSuffix("%").describe("Overall opacity of the trail"); + this.lineWidth = new NumberSetting("Line width", 1.5, 0.5, 5.0, 0.5) + .withSuffix(" px") + .describe("Thickness of the two lines bounding the wall") + .visibleWhen(this.mode, mode -> modex == Mode.WALL); + this.pointSize = new NumberSetting("Point size", 4.0, 1.0, 12.0, 0.5).withSuffix(" px").visibleWhen(this.mode, mode -> modex == Mode.POINTS); + this.firstPerson = new BooleanSetting("First person", false).describe("Draw the trail in first person too, where it runs through the camera"); + this.throughWalls = new BooleanSetting("Through walls", false); + this.trailsRenderer = new TrailsRenderer(); + this.trailPoints = new ArrayList<>(); + } + + private List L(float f) { + Trails trails1 = this; + ArrayList arrayList; + (arrayList = new ArrayList(trails1.trailPoints.size() + 1)).addAll(trails1.trailPoints); + arrayList.add( + new TrailPoint( + new Vec3( + mc.thePlayer.prevPosX + (mc.thePlayer.posX - mc.thePlayer.prevPosX) * f, + mc.thePlayer.prevPosY + (mc.thePlayer.posY - mc.thePlayer.prevPosY) * f, + mc.thePlayer.prevPosZ + (mc.thePlayer.posZ - mc.thePlayer.prevPosZ) * f + ), + System.currentTimeMillis() + ) + ); + return arrayList; + } + + @EventHandler + private void onTickEnd(TickEndEvent tickEndEvent) { + Trails trails1 = this; + if (mc.thePlayer != null && mc.theWorld != null) { + trails1.h(); + Vec3 vec3 = new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ); + TrailPoint trailPoint = trails1.trailPoints.isEmpty() ? null : trails1.trailPoints.get(trails1.trailPoints.size() - 1); + if (trailPoint == null || trailPoint.position().squareDistanceTo(vec3) > 1.0E-8) { + trails1.trailPoints.add(new TrailPoint(vec3, System.currentTimeMillis())); + } + } + } + + @EventHandler + private void onWorldChange(WorldChangeEvent worldChangeEvent) { + this.trailPoints.clear(); + } + + private float L() { + return mc.thePlayer.height * (mc.thePlayer.isSneaking() ? 0.8F : 1.0F); + } + + @Override + protected void onDisable() { + this.trailPoints.clear(); + this.trailsRenderer.d(); + } + + public void L(float f) { + Trails trails1 = this; + if (trails1.isEnabled() && mc.theWorld != null && mc.thePlayer != null) { + if (trails1.firstPerson.isEnabled() || mc.gameSettings.thirdPersonView != 0) { + trails1.h(); + List list; + if ((list = trails1.L(f)).size() >= (trails1.mode.is(Mode.WALL) ? 2 : 1)) { + trails1.trailsRenderer.L(f, list, trails1.L(), trails1.L()); + } + } + } + } +} diff --git a/src/openonyx/features/render/Trajectories.java b/src/openonyx/features/render/Trajectories.java new file mode 100644 index 0000000..40a2a53 --- /dev/null +++ b/src/openonyx/features/render/Trajectories.java @@ -0,0 +1,242 @@ +package openonyx.features.render; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemBow; +import net.minecraft.item.ItemEgg; +import net.minecraft.item.ItemEnderPearl; +import net.minecraft.item.ItemPotion; +import net.minecraft.item.ItemSnowball; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import openonyx.features.Module; +import openonyx.features.ModuleCategory; +import openonyx.history.internal.BooleanSetting; +import openonyx.history.internal.ColorSetting; +import openonyx.history.internal.NumberSetting; +import openonyx.render.BoxRenderer; +import openonyx.render.LineRenderer3D; +import openonyx.theme.internal.ColorUtils; + +public final class Trajectories extends Module { + private static final double j = 0.03; + public final BooleanSetting throughWalls; + public final ColorSetting color = new ColorSetting("Color", -8857601).D().describe("Colour of the predicted path"); + public final NumberSetting maxTicks; + public final BooleanSetting impactMarker; + private static final double d = 0.05; + public final ColorSetting impactColor = new ColorSetting("Impact color", -38302).describe("Colour of the landing marker"); + public final NumberSetting lineWidth = new NumberSetting("Line width", 1.5, 0.5, 5.0, 0.5).withSuffix(" px"); + public final TrajectoriesPart trajectoriesPart; + private static final double e = 0.99; + + public void L(float f) { + Trajectories trajectories1 = this; + if (trajectories1.isEnabled() && mc.theWorld != null && mc.thePlayer != null) { + TrajectoriesMode trajectoriesMode; + if ((trajectoriesMode = trajectories1.L(mc.thePlayer.getHeldItem())) != null) { + float g; + if (!((g = trajectories1.L(trajectoriesMode)) <= 0.0F)) { + TrajectoriesData trajectoriesData; + if ((trajectoriesData = trajectories1.L(trajectoriesMode, g, f)).points().size() >= 2) { + if (LineRenderer3D.L(f, trajectories1.throughWalls.isEnabled(), trajectories1.lineWidth.getFloat())) { + int k; + int l = k = trajectories1.color.getValue(); + int i = ColorUtils.withAlpha(l, ColorUtils.alpha(l) / 255.0F * 0.35F); + LineRenderer3D.L(trajectoriesData.points(), k, i); + LineRenderer3D.d(); + if (trajectories1.impactMarker.isEnabled() && trajectoriesData.hit() != null) { + if (BoxRenderer.L(f, trajectories1.throughWalls.isEnabled())) { + int jx = trajectories1.impactColor.getValue(); + double dx = 0.12; + BoxRenderer.L( + AxisAlignedBB.fromBounds( + trajectoriesData.hit().xCoord - dx, + trajectoriesData.hit().yCoord - dx, + trajectoriesData.hit().zCoord - dx, + trajectoriesData.hit().xCoord + dx, + trajectoriesData.hit().yCoord + dx, + trajectoriesData.hit().zCoord + dx + ), + jx, + trajectories1.lineWidth.getFloat(), + ColorUtils.withAlpha(jx, ColorUtils.alpha(jx) / 255.0F * 0.25F) + ); + BoxRenderer.L(); + } + } + } + } + } + } + } + } + + public Trajectories() { + super("Trajectories", "Predicts where thrown items will land", ModuleCategory.RENDER); + this.impactMarker = new BooleanSetting("Impact marker", true).describe("Draw a box where the projectile lands"); + this.throughWalls = new BooleanSetting("Through walls", false); + this.maxTicks = new NumberSetting("Max ticks", 120.0, 20.0, 300.0, 10.0).describe("How far ahead to simulate"); + this.trajectoriesPart = new TrajectoriesPart(); + } + + private TrajectoriesMode L(ItemStack itemStack) { + if (itemStack == null) { + return null; + } + + if (itemStack.getItem() instanceof ItemEnderPearl) { + return this.trajectoriesPart.enderPearls.isEnabled() ? TrajectoriesMode.PEARL : null; + } + + if (!(itemStack.getItem() instanceof ItemSnowball) && !(itemStack.getItem() instanceof ItemEgg)) { + if (itemStack.getItem() instanceof ItemPotion) { + return this.trajectoriesPart.splashPotions.isEnabled() && ItemPotion.isSplash(itemStack.getMetadata()) ? TrajectoriesMode.POTION : null; + } else if (!(itemStack.getItem() instanceof ItemBow)) { + return null; + } else { + return this.trajectoriesPart.bows.isEnabled() ? TrajectoriesMode.ARROW : null; + } + } else { + return this.trajectoriesPart.snowballsAndEggs.isEnabled() ? TrajectoriesMode.SNOWBALL : null; + } + } + + private float L(TrajectoriesMode trajectoriesMode) { + if (trajectoriesMode != TrajectoriesMode.ARROW) { + return trajectoriesMode.d(); + } + + if (!mc.thePlayer.isUsingItem()) { + return 0.0F; + } + + float f; + float h = f = mc.thePlayer.getItemInUseDuration() / 20.0F; + float g; + if ((g = (h * h + f * 2.0F) / 3.0F) < 0.1F) { + return 0.0F; + } + + if (g > 1.0F) { + g = 1.0F; + } + + return g * 2.0F * 1.5F; + } + + private Vec3 L(Vec3 vec3, Vec3 vec31) { + if (!this.trajectoriesPart.stopAtEntities.isEnabled()) { + return null; + } + + AxisAlignedBB axisAlignedBB = AxisAlignedBB.fromBounds( + Math.min(vec3.xCoord, vec31.xCoord), + Math.min(vec3.yCoord, vec31.yCoord), + Math.min(vec3.zCoord, vec31.zCoord), + Math.max(vec3.xCoord, vec31.xCoord), + Math.max(vec3.yCoord, vec31.yCoord), + Math.max(vec3.zCoord, vec31.zCoord) + ) + .expand(1.0, 1.0, 1.0); + Vec3 vec32 = null; + double dx = Double.MAX_VALUE; + Iterator iterator = mc.theWorld.getEntitiesWithinAABBExcludingEntity(mc.thePlayer, axisAlignedBB).iterator(); + + label35: + while (true) { + Iterator iterator1 = iterator; + + while (iterator1.hasNext()) { + Entity entity; + if (!(entity = (Entity)iterator.next()).canBeCollidedWith()) { + continue label35; + } + + if (entity == mc.thePlayer) { + iterator1 = iterator; + } else { + MovingObjectPosition movingObjectPosition; + if ((movingObjectPosition = entity.getEntityBoundingBox().expand(0.3, 0.3, 0.3).calculateIntercept(vec3, vec31)) == null) { + continue label35; + } + + if (movingObjectPosition.hitVec != null) { + double ex; + if ((ex = vec3.squareDistanceTo(movingObjectPosition.hitVec)) < dx) { + dx = ex; + vec32 = movingObjectPosition.hitVec; + } + continue label35; + } + + iterator1 = iterator; + } + } + + return vec32; + } + } + + private TrajectoriesData L(TrajectoriesMode trajectoriesMode, float f, float g) { + g = mc.thePlayer.rotationYaw; + float h = mc.thePlayer.rotationPitch; + double dx = g / 180.0 * Math.PI; + double ex = h / 180.0 * Math.PI; + double i = (h + trajectoriesMode.L()) / 180.0 * Math.PI; + double jx = mc.thePlayer.posX - Math.cos(dx) * 0.16; + double k = mc.thePlayer.posY + mc.thePlayer.getEyeHeight() - 0.1F; + double l = mc.thePlayer.posZ - Math.sin(dx) * 0.16; + double m = -Math.sin(dx) * Math.cos(ex); + dx = Math.cos(dx) * Math.cos(ex); + ex = -Math.sin(i); + if ((i = Math.sqrt(m * m + ex * ex + dx * dx)) < 1.0E-6) { + return new TrajectoriesData(List.of(), null); + } + + m = m / i * f; + ex = ex / i * f; + dx = dx / i * f; + i = trajectoriesMode.L(); + ArrayList arrayList = new ArrayList(); + arrayList.add(new Vec3(jx, k, l)); + int n = this.maxTicks.getInt(); + int o = 0; + + for (int p = o; p < n; p = o) { + Vec3 vec31 = new Vec3(jx, k, l); + jx += m; + k += ex; + l += dx; + Vec3 vec3 = new Vec3(jx, k, l); + MovingObjectPosition movingObjectPosition; + if ((movingObjectPosition = mc.theWorld.rayTraceBlocks(vec31, vec3, false, true, false)) != null && movingObjectPosition.hitVec != null) { + arrayList.add(movingObjectPosition.hitVec); + return new TrajectoriesData(arrayList, movingObjectPosition.hitVec); + } + + Vec3 vec32; + if ((vec32 = this.L(vec31, vec3)) != null) { + arrayList.add(vec32); + return new TrajectoriesData(arrayList, vec32); + } + + arrayList.add(vec3); + if (k < 0.0) { + return new TrajectoriesData(arrayList, null); + } + + m *= 0.99; + ex *= 0.99; + dx *= 0.99; + o++; + ex -= i; + } + + return new TrajectoriesData(arrayList, null); + } +} diff --git a/src/openonyx/features/render/TrajectoriesData.java b/src/openonyx/features/render/TrajectoriesData.java new file mode 100644 index 0000000..1e2b48a --- /dev/null +++ b/src/openonyx/features/render/TrajectoriesData.java @@ -0,0 +1,7 @@ +package openonyx.features.render; + +import java.util.List; +import net.minecraft.util.Vec3; + +record TrajectoriesData(List points, Vec3 hit) { +}