| 1 | /*
|
| 2 | * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
|
| 3 | * Copyright (c) Meteor Development.
|
| 4 | */
|
| 5 |
|
| 6 | package meteordevelopment.meteorclient.systems.modules.render;
|
| 7 |
|
| 8 | import meteordevelopment.meteorclient.events.packets.PacketEvent;
|
| 9 | import meteordevelopment.meteorclient.events.world.TickEvent;
|
| 10 | import meteordevelopment.meteorclient.settings.DoubleSetting;
|
| 11 | import meteordevelopment.meteorclient.settings.Setting;
|
| 12 | import meteordevelopment.meteorclient.settings.SettingGroup;
|
| 13 | import meteordevelopment.meteorclient.systems.modules.Categories;
|
| 14 | import meteordevelopment.meteorclient.systems.modules.Module;
|
| 15 | import meteordevelopment.orbit.EventHandler;
|
| 16 | import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
|
| 17 |
|
| 18 | public class WeatherChanger extends Module {
|
| 19 | private final SettingGroup sgGeneral = settings.getDefaultGroup();
|
| 20 |
|
| 21 | private final Setting<Double> rainLevel = sgGeneral.add(new DoubleSetting.Builder()
|
| 22 | .name("rain-level")
|
| 23 | .description("The specified rain level to be set.")
|
| 24 | .defaultValue(0)
|
| 25 | .sliderRange(0, 1)
|
| 26 | .build()
|
| 27 | );
|
| 28 |
|
| 29 | private final Setting<Double> thunderLevel = sgGeneral.add(new DoubleSetting.Builder()
|
| 30 | .name("thunder-level")
|
| 31 | .description("The specified thunder level to be set.")
|
| 32 | .defaultValue(0)
|
| 33 | .sliderRange(0, 1)
|
| 34 | .build()
|
| 35 | );
|
| 36 |
|
| 37 | private float oldThunderLevel;
|
| 38 | private float oldRainLevel;
|
| 39 |
|
| 40 | public WeatherChanger() {
|
| 41 | super(Categories.Render, "weather-changer", "Allows you to override the world's current weather.");
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | public void onActivate() {
|
| 46 | if (mc.level == null) return;
|
| 47 |
|
| 48 | oldThunderLevel = mc.level.getThunderLevel(1f);
|
| 49 | oldRainLevel = mc.level.getRainLevel(1f);
|
| 50 | }
|
| 51 |
|
| 52 | @Override
|
| 53 | public void onDeactivate() {
|
| 54 | if (mc.level == null) return;
|
| 55 |
|
| 56 | mc.level.setRainLevel(oldRainLevel);
|
| 57 | mc.level.setThunderLevel(oldThunderLevel);
|
| 58 | }
|
| 59 |
|
| 60 | @EventHandler
|
| 61 | private void onPacketReceive(PacketEvent.Receive event) {
|
| 62 | if (!(event.packet instanceof ClientboundGameEventPacket packet)) return;
|
| 63 |
|
| 64 | ClientboundGameEventPacket.Type type = packet.getEvent();
|
| 65 | if (!isWeatherPacket(type)) return;
|
| 66 |
|
| 67 | if (type == ClientboundGameEventPacket.THUNDER_LEVEL_CHANGE) {
|
| 68 | oldThunderLevel = packet.getParam();
|
| 69 | } else if (type == ClientboundGameEventPacket.RAIN_LEVEL_CHANGE) {
|
| 70 | oldRainLevel = packet.getParam();
|
| 71 | }
|
| 72 |
|
| 73 | event.cancel();
|
| 74 | }
|
| 75 |
|
| 76 | private boolean isWeatherPacket(ClientboundGameEventPacket.Type type) {
|
| 77 | return type == ClientboundGameEventPacket.START_RAINING
|
| 78 | || type == ClientboundGameEventPacket.STOP_RAINING
|
| 79 | || type == ClientboundGameEventPacket.THUNDER_LEVEL_CHANGE
|
| 80 | || type == ClientboundGameEventPacket.RAIN_LEVEL_CHANGE;
|
| 81 | }
|
| 82 |
|
| 83 | @EventHandler
|
| 84 | private void onTick(TickEvent.Post event) {
|
| 85 | if (mc.level == null) return;
|
| 86 |
|
| 87 | mc.level.setRainLevel(rainLevel.get().floatValue());
|
| 88 | mc.level.setThunderLevel(thunderLevel.get().floatValue());
|
| 89 | }
|
| 90 | }
|
| 91 |
|