MASSIVE REFACTOR and pvpinfo (iseeyou + totempopcounter)
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m12s

This commit is contained in:
Jess H 2024-06-15 10:20:06 +01:00
parent 0f67fbab3b
commit 915c3f7634
Signed by: UnixSystemV
GPG key ID: 9B21C50B68D67F19
13 changed files with 142 additions and 78 deletions

View file

@ -1,10 +1,10 @@
package de.com.baseband.client;
import de.com.baseband.client.event.Event;
import de.com.baseband.client.event.EventManager;
import de.com.baseband.client.event.FMLEventHandler;
import de.com.baseband.client.event.EventBus;
import de.com.baseband.client.event.StaticEventHandler;
import de.com.baseband.client.event.remote.RemoteEvent;
import de.com.baseband.client.event.remote.RemoteEventManager;
import de.com.baseband.client.event.remote.RemoteEventBus;
import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.feature.Features;
import de.com.baseband.client.feature.modules.client.Client;
@ -31,9 +31,9 @@ public class BaseBand {
public static final SecureRandom RANDOM = new SecureRandom();
public static String buildString = LoadHandler.data.getBoolean("release-branch") ? "Broadway" : "Dark Side of the Moon";
public static final EventManager eventManager = new EventManager(LOGGER::error);
public static final RemoteEventManager remoteEventManager = new RemoteEventManager();
public static final FMLEventHandler fmlEventHandlerInstance = new FMLEventHandler();
public static final EventBus EVENT_BUS = new EventBus(LOGGER::error);
public static final RemoteEventBus REMOTE_EVENT_BUS = new RemoteEventBus();
public static final StaticEventHandler STATIC_EVENT_HANDLER_INSTANCE = new StaticEventHandler();
public static boolean enabled = true;
public static boolean finishedDisabling = false;
public static Minecraft mc;
@ -55,10 +55,12 @@ public class BaseBand {
shutdown();
}
MinecraftForge.EVENT_BUS.register(fmlEventHandlerInstance);
mc = Minecraft.getMinecraft();
MinecraftForge.EVENT_BUS.register(STATIC_EVENT_HANDLER_INSTANCE);
EVENT_BUS.subscribe(STATIC_EVENT_HANDLER_INSTANCE);
mc.gameSettings.autoJump = false; //fuck autojump, disable it on startup
LOGGER.info("Generating features...");
@ -99,9 +101,9 @@ public class BaseBand {
public static <T extends Event> T publish(T event) {
if(event instanceof RemoteEvent)
remoteEventManager.publish((RemoteEvent) event);
REMOTE_EVENT_BUS.publish((RemoteEvent) event);
else
eventManager.publish(event);
EVENT_BUS.publish(event);
return event;
}

View file

@ -55,12 +55,12 @@ public class Setup {
new Help(),
new HUD(),
//new HUD.ShowTPS(),
new ISeeYou(),
new MidClick(),
new Nametags(),
new NoRender(),
new NoSlowDown(),
new Ping(),
new PvpInfo(),
new RenderFun(),
new Say(),
new SeedOverlay(),

View file

@ -6,7 +6,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
//My god it's perfect
public class EventManager {
public class EventBus {
private final List<SubscriberMethod> subscriberMethods;
@ -14,11 +14,11 @@ public class EventManager {
private Consumer<Throwable> crashHandler = t -> {throw new RuntimeException(t);};
public EventManager() {
public EventBus() {
subscriberMethods = new CopyOnWriteArrayList<>();
}
public EventManager(Consumer<Throwable> crashHandler) {
public EventBus(Consumer<Throwable> crashHandler) {
this.crashHandler = crashHandler;
subscriberMethods = new CopyOnWriteArrayList<>();
}

View file

@ -2,12 +2,16 @@ package de.com.baseband.client.event;
import de.com.baseband.client.BaseBand;
import de.com.baseband.client.Setup;
import de.com.baseband.client.event.events.PacketEvent;
import de.com.baseband.client.event.events.PlayerDestroyEvent;
import de.com.baseband.client.event.events.TotemPopEvent;
import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.feature.Features;
import de.com.baseband.client.feature.modules.client.Client;
import de.com.baseband.client.util.interact.Chat;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.Entity;
import net.minecraft.network.play.server.SPacketEntityStatus;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -15,8 +19,10 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
import java.util.Arrays;
import static de.com.baseband.client.BaseBand.mc;
//forge mod loader more like fuck my life this shit BLOWS
public class FMLEventHandler {
public class StaticEventHandler {
Setup setup = Setup.get();
@ -44,6 +50,16 @@ public class FMLEventHandler {
}
}
public void onPacketIn(PacketEvent.Receive event) {
if (event.getPacket() instanceof SPacketEntityStatus) {
SPacketEntityStatus packet = (SPacketEntityStatus) event.getPacket();
if (packet.getOpCode() == 35) {
Entity entity = packet.getEntity(mc.world);
BaseBand.EVENT_BUS.publish(new TotemPopEvent(entity));
}
}
}
@SubscribeEvent
public void render(RenderWorldLastEvent event) {
KeyManager.updateKeyBinds();
@ -52,8 +68,8 @@ public class FMLEventHandler {
EntityPlayerSP playerLastTick = null;
@SubscribeEvent
public void tick(TickEvent.ClientTickEvent event) {
BaseBand.remoteEventManager.onTick();
if(BaseBand.mc.world == null || BaseBand.mc.player == null) {
BaseBand.REMOTE_EVENT_BUS.onTick();
if(mc.world == null || mc.player == null) {
if(playerLastTick != null) {
BaseBand.publish(new PlayerDestroyEvent(playerLastTick));
}
@ -62,7 +78,7 @@ public class FMLEventHandler {
}
if(event.phase != TickEvent.Phase.END)
return;
playerLastTick = BaseBand.mc.player;
playerLastTick = mc.player;
KeyManager.updateKeyBinds();
for(Feature feature : Features.features) {
feature.onEveryTick();

View file

@ -2,7 +2,7 @@ package de.com.baseband.client.event.events;
import de.com.baseband.client.BaseBand;
import de.com.baseband.client.event.remote.RemoteEvent;
import de.com.baseband.client.event.remote.RemoteEventManager;
import de.com.baseband.client.event.remote.RemoteEventBus;
import de.com.baseband.client.util.interact.BlockUtils;
import de.com.baseband.client.util.type.Selection;
import de.tudbut.obj.Save;
@ -20,8 +20,8 @@ public class SelectEvent extends RemoteEvent {
public Selection getMySelection() {
if(selection == null)
return null;
if(BaseBand.remoteEventManager.isConnected()) {
RemoteEventManager manager = BaseBand.remoteEventManager;
if(BaseBand.REMOTE_EVENT_BUS.isConnected()) {
RemoteEventBus manager = BaseBand.REMOTE_EVENT_BUS;
Selection[] splitSelection = BlockUtils.splitSelection1D(selection, manager.getPeers());
BaseBand.LOGGER.info("Split selection: {}", Arrays.toString(splitSelection));
if(splitSelection.length > manager.getID())

View file

@ -0,0 +1,16 @@
package de.com.baseband.client.event.events;
import de.com.baseband.client.event.Event;
import net.minecraft.entity.Entity;
public class TotemPopEvent extends Event {
public TotemPopEvent(Entity entity) {
this.entity = entity;
}
Entity entity;
public Entity getEntity() {
return entity;
}
}

View file

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
public class RemoteEventManager {
public class RemoteEventBus {
private final de.com.baseband.client.Setup Setup = de.com.baseband.client.Setup.get();
public Socket head = null;
@ -208,7 +208,7 @@ public class RemoteEventManager {
BaseBand.notify("[Remote] Peers connected: " + peers + ".");
}
else {
BaseBand.eventManager.publish(event);
BaseBand.EVENT_BUS.publish(event);
}
}
if(!isConnected())

View file

@ -86,12 +86,12 @@ public abstract class Feature extends ToggleButton implements SetCommand {
public void updateEnabled() {
if(enabled) {
BaseBand.eventManager.subscribe(this);
BaseBand.EVENT_BUS.subscribe(this);
MinecraftForge.EVENT_BUS.register(this);
BaseBand.notify("§l" + this + "§a enabled§r.");
onEnable();
} else {
BaseBand.eventManager.unsubscribe(this);
BaseBand.EVENT_BUS.unsubscribe(this);
MinecraftForge.EVENT_BUS.unregister(this);
BaseBand.notify("§l" + this + "§c disabled§r.");
onDisable();

View file

@ -1,49 +0,0 @@
package de.com.baseband.client.feature.modules.chat;
import de.com.baseband.client.feature.Feature;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import java.util.ArrayList;
@de.com.baseband.client.feature.category.Chat
public class ISeeYou extends Feature {
private final ArrayList<String> names = new ArrayList<>();
private final ArrayList<String> newnames = new ArrayList<>();
@Override
public String toString() {
return "ISeeYou";
}
@Override
public void onTick() {
if(!notIngame()) {
localPlayerCheck();
text = "ISeeYou" + (enabled ? " §7[" + names.size() +"]" : "");
}
}
public void localPlayerCheck() {
newnames.clear();
try {
for (final Entity entity : mc.world.loadedEntityList) if (entity instanceof EntityPlayer && !entity.getName().equalsIgnoreCase(mc.player.getName())) newnames.add(entity.getName());
if (!names.equals(newnames)) {
for (final String name : newnames) if (!names.contains(name)) de.com.baseband.client.util.interact.Chat.print("[ISeeYou] I locally see "+name);
for (final String name : names) if (!newnames.contains(name)) de.com.baseband.client.util.interact.Chat.print("[ISeeYou] I no longer locally see "+name);
names.clear();
names.addAll(newnames);
}
} catch (Exception ignored) {}
}
@Override
public void onDisable() {
text = "ISeeYou";
names.clear();
newnames.clear();
}
}

View file

@ -0,0 +1,79 @@
package de.com.baseband.client.feature.modules.chat;
import de.com.baseband.client.BaseBand;
import de.com.baseband.client.event.events.TotemPopEvent;
import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.registry.annotation.Config;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import java.util.ArrayList;
import java.util.HashMap;
@de.com.baseband.client.feature.category.Chat
public class PvpInfo extends Feature {
private final ArrayList<String> names = new ArrayList<>();
private final ArrayList<String> newnames = new ArrayList<>();
private HashMap<String, Integer> popList = new HashMap<>();
@Config("Totem Pops")
public boolean totemPops;
@Config("Visual Range")
public boolean visualRange;
@Override
public String toString() {
return "PvpInfo";
}
@Override
public void onTick() {
if(visualRange) {
newnames.clear();
try {
for (final Entity entity : mc.world.loadedEntityList) if (entity instanceof EntityPlayer && !entity.getName().equalsIgnoreCase(mc.player.getName())) newnames.add(entity.getName());
if (!names.equals(newnames)) {
for (final String name : newnames) if (!names.contains(name)) BaseBand.notify("[PvpInfo] "+name+" has entered Visual Range.");
for (final String name : names) if (!newnames.contains(name)) BaseBand.notify("[PvpInfo] "+name+" has left Visual Range.");
names.clear();
names.addAll(newnames);
}
} catch (Exception ignored) {}
}
if(totemPops) {
for (EntityPlayer player : mc.world.playerEntities) {
if (player.getHealth() <= 0) {
if (popList.containsKey(player.getName())) {
BaseBand.notify("[PvpInfo] " + player.getName() + " died after popping " + popList.get(player.getName()) + " totem(s).");
popList.remove(player.getName(), popList.get(player.getName()));
}
}
}
}
}
public void totemPop(TotemPopEvent event) {
if(popList.get(event.getEntity().getName()) == null) {
popList.put(event.getEntity().getName(), 1);
BaseBand.notify("[PvpInfo] " + event.getEntity().getName() + " popped " + 1 + " totem.");
} else if(popList.get(event.getEntity().getName()) != null) {
int popCounter = popList.get(event.getEntity().getName());
int newPopCounter = popCounter + 1;
popList.put(event.getEntity().getName(), newPopCounter);
BaseBand.notify("[PvpInfo] " + event.getEntity().getName() + " popped " + newPopCounter + " totems.");
}
}
@Override
public void onDisable() {
text = "PvpInfo";
names.clear();
newnames.clear();
popList.clear();
}
}

View file

@ -34,14 +34,14 @@ public class AltControl extends Feature {
public void onEnable() {
notEnabled = false;
BaseBand.remoteEventManager.connect(ip);
BaseBand.REMOTE_EVENT_BUS.connect(ip);
}
@Trigger("Stop")
@Gate(M_ENABLED)
public void onDisable() {
notEnabled = true;
BaseBand.remoteEventManager.end();
BaseBand.REMOTE_EVENT_BUS.end();
}
public void onRemoteSendChat(RemoteSendMessageEvent event) {

View file

@ -89,7 +89,7 @@ public class Client extends Feature {
}
disableLock = true;
Chat.print("Unloading...");
MinecraftForge.EVENT_BUS.unregister(BaseBand.fmlEventHandlerInstance);
MinecraftForge.EVENT_BUS.unregister(BaseBand.STATIC_EVENT_HANDLER_INSTANCE);
mc.displayGuiScreen(null);
BaseBand.enabled = false;
Chat.print("Waiting for config...");

View file

@ -54,7 +54,7 @@ public class MixinProxy {
public static void onPlayerDamageBlock(BlockPos posBlock, EnumFacing directionFacing, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
DamageBlockEvent event = new DamageBlockEvent(posBlock, directionFacing);
BaseBand.eventManager.publish(event);
BaseBand.EVENT_BUS.publish(event);
if (event.isCancelled()) {
callbackInfoReturnable.setReturnValue(false);
}