|
| 1 | +package nekiplay.meteorplus.mixin.meteorclient.modules; |
| 2 | + |
| 3 | +import meteordevelopment.meteorclient.events.render.Render2DEvent; |
| 4 | +import meteordevelopment.meteorclient.mixin.ClientPlayerInteractionManagerAccessor; |
| 5 | +import meteordevelopment.meteorclient.mixin.WorldRendererAccessor; |
| 6 | +import meteordevelopment.meteorclient.renderer.text.TextRenderer; |
| 7 | +import meteordevelopment.meteorclient.settings.BoolSetting; |
| 8 | +import meteordevelopment.meteorclient.settings.ColorSetting; |
| 9 | +import meteordevelopment.meteorclient.settings.Setting; |
| 10 | +import meteordevelopment.meteorclient.settings.SettingGroup; |
| 11 | +import meteordevelopment.meteorclient.systems.modules.Category; |
| 12 | +import meteordevelopment.meteorclient.systems.modules.Module; |
| 13 | +import meteordevelopment.meteorclient.systems.modules.Modules; |
| 14 | +import meteordevelopment.meteorclient.systems.modules.render.BreakIndicators; |
| 15 | +import meteordevelopment.meteorclient.systems.modules.world.PacketMine; |
| 16 | +import meteordevelopment.meteorclient.utils.render.NametagUtils; |
| 17 | +import meteordevelopment.meteorclient.utils.render.color.SettingColor; |
| 18 | +import meteordevelopment.orbit.EventHandler; |
| 19 | +import nekiplay.meteorplus.MeteorPlusAddon; |
| 20 | +import net.minecraft.block.BlockState; |
| 21 | +import net.minecraft.entity.player.BlockBreakingInfo; |
| 22 | +import net.minecraft.util.math.BlockPos; |
| 23 | +import net.minecraft.util.math.Box; |
| 24 | +import net.minecraft.util.shape.VoxelShape; |
| 25 | +import org.joml.Vector3d; |
| 26 | +import org.spongepowered.asm.mixin.Mixin; |
| 27 | +import org.spongepowered.asm.mixin.Unique; |
| 28 | +import java.util.List; |
| 29 | +import java.util.Map; |
| 30 | + |
| 31 | +@Mixin(BreakIndicators.class) |
| 32 | +public class BreakIndicatorsMixin extends Module { |
| 33 | + |
| 34 | + @Unique |
| 35 | + private final SettingGroup sgPercentageRenderPlus = settings.createGroup(MeteorPlusAddon.HUD_TITLE + " Percentage Render"); |
| 36 | + |
| 37 | + @Unique |
| 38 | + public final Setting<Boolean> percentageRender = sgPercentageRenderPlus.add(new BoolSetting.Builder() |
| 39 | + .name("enable-percentage-render") |
| 40 | + .description("Enable percentage text render.") |
| 41 | + .defaultValue(true) |
| 42 | + .build() |
| 43 | + ); |
| 44 | + |
| 45 | + @Unique |
| 46 | + public final Setting<Boolean> packetMine = sgPercentageRenderPlus.add(new BoolSetting.Builder() |
| 47 | + .name("packet-mine") |
| 48 | + .description("Render packet mine blocks.") |
| 49 | + .defaultValue(true) |
| 50 | + .visible(percentageRender::get) |
| 51 | + .build() |
| 52 | + ); |
| 53 | + |
| 54 | + @Unique |
| 55 | + private final Setting<SettingColor> percentageColor = sgPercentageRenderPlus.add(new ColorSetting.Builder() |
| 56 | + .name("percentage-color") |
| 57 | + .description("The color for the percentage text.") |
| 58 | + .defaultValue(new SettingColor(25, 252, 25, 150)) |
| 59 | + .visible(percentageRender::get) |
| 60 | + .build() |
| 61 | + ); |
| 62 | + |
| 63 | + |
| 64 | + public BreakIndicatorsMixin(Category category, String name, String description, String... aliases) { |
| 65 | + super(category, name, description, aliases); |
| 66 | + } |
| 67 | + |
| 68 | + @Unique |
| 69 | + @EventHandler |
| 70 | + private void on2DRender(Render2DEvent event) { |
| 71 | + |
| 72 | + Map<Integer, BlockBreakingInfo> blocks = ((WorldRendererAccessor) mc.worldRenderer).getBlockBreakingInfos(); |
| 73 | + |
| 74 | + float ownBreakingStage = ((ClientPlayerInteractionManagerAccessor) mc.interactionManager).getBreakingProgress(); |
| 75 | + BlockPos ownBreakingPos = ((ClientPlayerInteractionManagerAccessor) mc.interactionManager).getCurrentBreakingBlockPos(); |
| 76 | + |
| 77 | + |
| 78 | + if (ownBreakingPos != null && ownBreakingStage > 0) { |
| 79 | + |
| 80 | + double shrinkFactor = 1d - ownBreakingStage; |
| 81 | + |
| 82 | + |
| 83 | + BlockState state = mc.world.getBlockState(ownBreakingPos); |
| 84 | + VoxelShape shape = state.getOutlineShape(mc.world, ownBreakingPos); |
| 85 | + if (shape == null || shape.isEmpty()) return; |
| 86 | + |
| 87 | + Box orig = shape.getBoundingBox(); |
| 88 | + |
| 89 | + renderBlock(event, ownBreakingPos, shrinkFactor, orig); |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + blocks.values().forEach(info -> { |
| 94 | + BlockPos pos = info.getPos(); |
| 95 | + int stage = info.getStage(); |
| 96 | + if (pos.equals(ownBreakingPos)) return; |
| 97 | + |
| 98 | + BlockState state = mc.world.getBlockState(pos); |
| 99 | + VoxelShape shape = state.getOutlineShape(mc.world, pos); |
| 100 | + if (shape == null || shape.isEmpty()) return; |
| 101 | + |
| 102 | + Box orig = shape.getBoundingBox(); |
| 103 | + |
| 104 | + double shrinkFactor = (9 - (stage + 1)) / 9d; |
| 105 | + double progress = 1d - shrinkFactor; |
| 106 | + |
| 107 | + renderBlock(event, pos, shrinkFactor, orig); |
| 108 | + }); |
| 109 | + |
| 110 | + if (packetMine.get() && !Modules.get().get(PacketMine.class).blocks.isEmpty()) { |
| 111 | + renderPacket(event, Modules.get().get(PacketMine.class).blocks); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + @Unique |
| 116 | + private void renderBlock(Render2DEvent event, BlockPos pos, double shrinkFactor, Box orig) { |
| 117 | + Vector3d vector3d = new Vector3d(pos.getX() + orig.getCenter().x, pos.getY() + orig.getCenter().y, pos.getZ() + orig.getCenter().z); |
| 118 | + if (percentageRender.get()) { |
| 119 | + if (NametagUtils.to2D(vector3d, 1, true)) { |
| 120 | + TextRenderer text = TextRenderer.get(); |
| 121 | + NametagUtils.begin(vector3d, event.drawContext); |
| 122 | + text.beginBig(); |
| 123 | + String label = String.format("%1$,.0f", shrinkFactor * 100) + "%"; |
| 124 | + |
| 125 | + double hologramWidth = text.getWidth(label, true); |
| 126 | + double heightDown = text.getHeight(true); |
| 127 | + |
| 128 | + double widthHalf = hologramWidth / 2; |
| 129 | + |
| 130 | + |
| 131 | + double hX = -widthHalf; |
| 132 | + double hY = -heightDown; |
| 133 | + |
| 134 | + text.render(label, hX, hY, percentageColor.get(), true); |
| 135 | + |
| 136 | + text.end(); |
| 137 | + NametagUtils.end(event.drawContext); |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + @Unique |
| 143 | + private void renderPacket(Render2DEvent event, List<PacketMine.MyBlock> blocks) { |
| 144 | + for (PacketMine.MyBlock block : blocks) { |
| 145 | + if (block.mining && block.progress != Double.POSITIVE_INFINITY) { |
| 146 | + VoxelShape shape = block.blockState.getOutlineShape(mc.world, block.blockPos); |
| 147 | + if (shape == null || shape.isEmpty()) return; |
| 148 | + |
| 149 | + Box orig = shape.getBoundingBox(); |
| 150 | + |
| 151 | + double progressNormalised = block.progress > 1 ? 1 : block.progress; |
| 152 | + double shrinkFactor = 1d - progressNormalised; |
| 153 | + BlockPos pos = block.blockPos; |
| 154 | + |
| 155 | + renderBlock(event, pos, shrinkFactor, orig); |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | +} |
0 commit comments