|
| 1 | +//By Zgoly |
| 2 | +package zgoly.meteorist.modules; |
| 3 | + |
| 4 | +import meteordevelopment.meteorclient.events.render.Render3DEvent; |
| 5 | +import meteordevelopment.meteorclient.events.world.TickEvent; |
| 6 | +import meteordevelopment.meteorclient.renderer.ShapeMode; |
| 7 | +import meteordevelopment.meteorclient.settings.*; |
| 8 | +import meteordevelopment.meteorclient.systems.modules.Module; |
| 9 | +import meteordevelopment.meteorclient.utils.player.FindItemResult; |
| 10 | +import meteordevelopment.meteorclient.utils.player.InvUtils; |
| 11 | +import meteordevelopment.meteorclient.utils.render.color.SettingColor; |
| 12 | +import meteordevelopment.meteorclient.utils.world.BlockUtils; |
| 13 | +import meteordevelopment.orbit.EventHandler; |
| 14 | +import net.minecraft.block.Block; |
| 15 | +import net.minecraft.block.Blocks; |
| 16 | +import net.minecraft.util.math.BlockPos; |
| 17 | +import zgoly.meteorist.Meteorist; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +public class AutoLight extends Module { |
| 22 | + private final SettingGroup sgGeneral = settings.getDefaultGroup(); |
| 23 | + private final SettingGroup sgRange = settings.createGroup("Range"); |
| 24 | + private final SettingGroup sgColor = settings.createGroup("Render"); |
| 25 | + |
| 26 | + private final Setting<List<Block>> blocks = sgGeneral.add(new BlockListSetting.Builder() |
| 27 | + .name("blocks") |
| 28 | + .description("Light blocks to check.") |
| 29 | + .defaultValue(Blocks.TORCH) |
| 30 | + .build() |
| 31 | + ); |
| 32 | + |
| 33 | + private final Setting<Boolean> place = sgGeneral.add(new BoolSetting.Builder() |
| 34 | + .name("place") |
| 35 | + .description("Place blocks.") |
| 36 | + .defaultValue(true) |
| 37 | + .build() |
| 38 | + ); |
| 39 | + |
| 40 | + private final Setting<Boolean> rotate = sgGeneral.add(new BoolSetting.Builder() |
| 41 | + .name("rotate") |
| 42 | + .description("Rotate camera.") |
| 43 | + .defaultValue(true) |
| 44 | + .visible(place::get) |
| 45 | + .build() |
| 46 | + ); |
| 47 | + |
| 48 | + private final Setting<Integer> range = sgRange.add(new IntSetting.Builder() |
| 49 | + .name("range") |
| 50 | + .description("Range to light source.") |
| 51 | + .defaultValue(4) |
| 52 | + .min(1) |
| 53 | + .build() |
| 54 | + ); |
| 55 | + |
| 56 | + private final Setting<Integer> gRange = sgRange.add(new IntSetting.Builder() |
| 57 | + .name("grid-range") |
| 58 | + .description("Grid range in blocks.") |
| 59 | + .defaultValue(13) |
| 60 | + .min(1) |
| 61 | + .build() |
| 62 | + ); |
| 63 | + |
| 64 | + private final Setting<Boolean> show = sgColor.add(new BoolSetting.Builder() |
| 65 | + .name("show") |
| 66 | + .description("Shows overlay of suggested places for light.") |
| 67 | + .defaultValue(true) |
| 68 | + .build() |
| 69 | + ); |
| 70 | + |
| 71 | + private final Setting<Boolean> dynHeight = sgColor.add(new BoolSetting.Builder() |
| 72 | + .name("dynamic-height") |
| 73 | + .description("Places light source on the ground.") |
| 74 | + .defaultValue(true) |
| 75 | + .build() |
| 76 | + ); |
| 77 | + |
| 78 | + private final Setting<SettingColor> sC1 = sgColor.add(new ColorSetting.Builder() |
| 79 | + .name("main-side-color") |
| 80 | + .description("The color of the sides of the blocks being rendered.") |
| 81 | + .defaultValue(new SettingColor(255, 0, 0, 40)) |
| 82 | + .build() |
| 83 | + ); |
| 84 | + |
| 85 | + private final Setting<SettingColor> lC1 = sgColor.add(new ColorSetting.Builder() |
| 86 | + .name("main-line-color") |
| 87 | + .description("The color of the lines of the blocks being rendered.") |
| 88 | + .defaultValue(new SettingColor(255, 0, 0, 100)) |
| 89 | + .build() |
| 90 | + ); |
| 91 | + |
| 92 | + private final Setting<SettingColor> sC2 = sgColor.add(new ColorSetting.Builder() |
| 93 | + .name("hologram-side-color") |
| 94 | + .description("The color of the sides of the blocks being rendered.") |
| 95 | + .defaultValue(new SettingColor(255, 255, 0, 40)) |
| 96 | + .build() |
| 97 | + ); |
| 98 | + |
| 99 | + private final Setting<SettingColor> lC2 = sgColor.add(new ColorSetting.Builder() |
| 100 | + .name("hologram-line-color") |
| 101 | + .description("The color of the lines of the blocks being rendered.") |
| 102 | + .defaultValue(new SettingColor(255, 255, 0, 100)) |
| 103 | + .build() |
| 104 | + ); |
| 105 | + |
| 106 | + public AutoLight() { |
| 107 | + super(Meteorist.CATEGORY, "auto-light", "Shows best place to place light source block."); |
| 108 | + } |
| 109 | + |
| 110 | + boolean work = false; |
| 111 | + BlockPos finalPos = new BlockPos(0,0,0); |
| 112 | + BlockPos xP = new BlockPos(0,0,0); |
| 113 | + BlockPos xM = new BlockPos(0,0,0); |
| 114 | + BlockPos zP = new BlockPos(0,0,0); |
| 115 | + BlockPos zM = new BlockPos(0,0,0); |
| 116 | + |
| 117 | + @Override |
| 118 | + public void onDeactivate() { |
| 119 | + work = false; |
| 120 | + } |
| 121 | + |
| 122 | + @EventHandler |
| 123 | + private void onTick(TickEvent.Pre event) { |
| 124 | + for (int x = -range.get(); x <= range.get(); x++) { |
| 125 | + for (int y = -range.get(); y <= range.get(); y++) { |
| 126 | + for (int z = -range.get(); z <= range.get(); z++) { |
| 127 | + BlockPos pos = mc.player.getBlockPos().add(x, y, z); |
| 128 | + final Block block = mc.world.getBlockState(pos).getBlock(); |
| 129 | + if (blocks.get().contains(block)) { |
| 130 | + finalPos = pos; |
| 131 | + xP = finalPos.add(gRange.get(), 0, 0); |
| 132 | + xM = finalPos.add(-gRange.get(), 0, 0); |
| 133 | + zP = finalPos.add(0, 0, gRange.get()); |
| 134 | + zM = finalPos.add(0, 0, -gRange.get()); |
| 135 | + |
| 136 | + if (dynHeight.get()) { |
| 137 | + while (!mc.world.getBlockState(xP).isAir()) xP = xP.add(0, 1, 0); |
| 138 | + while (mc.world.getBlockState(xP.add(0, -1, 0)).isAir()) xP = xP.add(0, -1, 0); |
| 139 | + while (!mc.world.getBlockState(xM).isAir()) xM = xM.add(0, 1, 0); |
| 140 | + while (mc.world.getBlockState(xM.add(0, -1, 0)).isAir()) xM = xM.add(0, -1, 0); |
| 141 | + while (!mc.world.getBlockState(zP).isAir()) zP = zP.add(0, 1, 0); |
| 142 | + while (mc.world.getBlockState(zP.add(0, -1, 0)).isAir()) zP = zP.add(0, -1, 0); |
| 143 | + while (!mc.world.getBlockState(zM).isAir()) zM = zM.add(0, 1, 0); |
| 144 | + while (mc.world.getBlockState(zM.add(0, -1, 0)).isAir()) zM = zM.add(0, -1, 0); |
| 145 | + } |
| 146 | + |
| 147 | + work = true; |
| 148 | + } |
| 149 | + if (place.get() & mc.world.getBlockState(pos).isAir()) { |
| 150 | + if (pos.toString().contains(xP.toString()) || |
| 151 | + pos.toString().contains(xM.toString()) || |
| 152 | + pos.toString().contains(zP.toString()) || |
| 153 | + pos.toString().contains(zM.toString())) { |
| 154 | + for (Block b : blocks.get()) { |
| 155 | + FindItemResult item = InvUtils.findInHotbar(b.asItem()); |
| 156 | + BlockUtils.place(pos, item, rotate.get(), 0, true); |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + @EventHandler |
| 166 | + private void onRender(Render3DEvent event) { |
| 167 | + if (work && show.get()) { |
| 168 | + event.renderer.box(finalPos, sC1.get(), lC1.get(), ShapeMode.Both, 0); |
| 169 | + event.renderer.box(xP, sC2.get(), lC2.get(), ShapeMode.Both, 0); |
| 170 | + event.renderer.box(xM, sC2.get(), lC2.get(), ShapeMode.Both, 0); |
| 171 | + event.renderer.box(zP, sC2.get(), lC2.get(), ShapeMode.Both, 0); |
| 172 | + event.renderer.box(zM, sC2.get(), lC2.get(), ShapeMode.Both, 0); |
| 173 | + } else event.renderer.end(); |
| 174 | + } |
| 175 | +} |
0 commit comments