feat: rudimentary autodisconnect

This commit is contained in:
əlemi 2023-02-16 02:53:28 +01:00
parent f85188f310
commit bad0ff82c9
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 44 additions and 0 deletions

View file

@ -60,6 +60,7 @@ public class BoSCoVicino implements ICommons {
ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder(); ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder();
CommandDispatcher<CommandSource> dp = this.dispatcher; CommandDispatcher<CommandSource> dp = this.dispatcher;
BoSCoVicino.mods.add(new AutoDisconnect(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new ActiveModules(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new ActiveModules(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new VanillaFlight(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new VanillaFlight(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new FastInteract(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new FastInteract(cfg, dp).done(cfg));

View file

@ -0,0 +1,43 @@
package ftbsc.bscv.modules.self;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.DoubleArgumentType;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.events.PacketEvent;
import ftbsc.bscv.modules.Module;
import net.minecraft.command.CommandSource;
import net.minecraft.network.play.server.SDisconnectPacket;
import net.minecraft.network.play.server.SUpdateHealthPacket;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class AutoDisconnect extends Module implements ICommons {
public final ForgeConfigSpec.ConfigValue<Double> threshold;
public AutoDisconnect(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
super("AutoDisconnect", Group.SELF, builder, dispatcher);
this.threshold = this.option(
"threshold", "hp below which connection should be closed", 10.,
DoubleArgumentType.doubleArg(0., 20.), Double.class,
builder, dispatcher
);
}
@SubscribeEvent
public void onPacket(PacketEvent event) {
if (event.outgoing) return;
if (event.packet instanceof SUpdateHealthPacket) {
SUpdateHealthPacket packet = (SUpdateHealthPacket) event.packet;
if (packet.getHealth() < this.threshold.get()) {
MC.player.connection.handleDisconnect( // this basically invokes disconnect() for us
new SDisconnectPacket(new StringTextComponent("HP fell below threshold"))
);
this.disable();
}
}
}
}