From 3a4239c1ff341c32befc2fb64d3fa06c7f48ab4f Mon Sep 17 00:00:00 2001 From: TudbuT Date: Tue, 25 Jun 2024 23:05:59 +0200 Subject: [PATCH] add playerlog --- .../event/events/PlayerLeftViewEvent.java | 5 +- .../feature/background/PlayerListHandler.java | 3 +- .../feature/modules/render/PlayerLog.java | 101 ++++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 Client/src/main/java/de/com/baseband/client/feature/modules/render/PlayerLog.java diff --git a/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftViewEvent.java b/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftViewEvent.java index 792f83c..dd827b5 100644 --- a/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftViewEvent.java +++ b/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftViewEvent.java @@ -2,13 +2,16 @@ package de.com.baseband.client.event.events; import de.com.baseband.client.event.Event; import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.entity.player.EntityPlayer; public class PlayerLeftViewEvent extends Event { public final NetworkPlayerInfo playerInfo; + public final EntityPlayer player; public final int index; - public PlayerLeftViewEvent(NetworkPlayerInfo playerInfo, int index) { + public PlayerLeftViewEvent(NetworkPlayerInfo playerInfo, EntityPlayer player, int index) { this.playerInfo = playerInfo; + this.player = player; this.index = index; } } diff --git a/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java b/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java index ada6e97..d40580e 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java +++ b/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java @@ -42,8 +42,7 @@ public class PlayerListHandler extends Feature { for (int i = 0; i < playersInRenderDistance.size(); i++) { NetworkPlayerInfo playerInfo = playersInRenderDistance.get(i); if (!playersRD.contains(playerInfo)) { - BaseBand.publish(new PlayerLeftViewEvent(playerInfo, i)); - entityPlayersInRenderDistance.remove(i); + BaseBand.publish(new PlayerLeftViewEvent(playerInfo, entityPlayersInRenderDistance.remove(i), i)); playersInRenderDistance.remove(i--); } } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/render/PlayerLog.java b/Client/src/main/java/de/com/baseband/client/feature/modules/render/PlayerLog.java new file mode 100644 index 0000000..140a96f --- /dev/null +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/render/PlayerLog.java @@ -0,0 +1,101 @@ +package de.com.baseband.client.feature.modules.render; + +import de.com.baseband.client.event.events.PlayerLeftEvent; +import de.com.baseband.client.event.events.PlayerLeftViewEvent; +import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.Features; +import de.com.baseband.client.feature.background.PlayerListHandler; +import de.com.baseband.client.feature.category.Experimental; +import de.com.baseband.client.feature.modules.client.Client; +import de.com.baseband.client.registry.annotation.Config; +import de.com.baseband.client.registry.annotation.Gate; +import de.com.baseband.client.registry.annotation.Range; +import de.com.baseband.client.registry.annotation.Requires; +import de.com.baseband.client.util.adapt.Marker; +import de.com.baseband.client.util.render.Pixels; +import de.com.baseband.client.util.render.SimpleRender; +import de.tudbut.tools.Lock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@Experimental +@Requires(PlayerListHandler.class) +public class PlayerLog extends Feature { + + @Config("Wireframe") + public boolean wireframe = true; + + @Config("Fill") + @Marker(1) + public boolean fill = true; + + @Config("Fill opacity") + @Range("0.05..0.5@0.05") + @Gate(1) + public float opacity = 0.1f; + + + HashMap> originalPlayers = new HashMap<>(); + ArrayList boxes = new ArrayList<>(); + + public void onPlayerLeaveView(PlayerLeftViewEvent event) { + Lock lock = new Lock(); + lock.lock(1000); + originalPlayers.put(event.playerInfo.getGameProfile().getId(), new ImmutablePair<>(lock, event.player)); + } + + public void onPlayerLeave(PlayerLeftEvent event) { + Pair pair = originalPlayers.get(event.playerInfo.getGameProfile().getId()); + if(pair != null) { + boxes.add(pair.getRight().getEntityBoundingBox()); + } + } + + @Override + public void onTick() { + if(originalPlayers.isEmpty()) + return; + for (Map.Entry> entry : originalPlayers.entrySet().toArray(new Map.Entry[0])) { + if(!entry.getValue().getLeft().isLocked()) + originalPlayers.remove(entry.getKey()); + } + } + + @Override + public void onDisable() { + originalPlayers.clear(); + boxes.clear(); + } + + @SubscribeEvent + public void onRender(RenderWorldLastEvent event) { + SimpleRender render = new SimpleRender(event.getPartialTicks()); + int c = Features.getFeature(Client.class).theme.getGreenColor() | 0xff000000; + if(wireframe) + renderOn(render.color(c).lines()).end(); + if(fill) + renderOn(render.color(Pixels.mulTransparency(c, opacity)).quadsFill()).end(); + render.finish(); + } + + private SimpleRender.SimpleRenderBackend renderOn(SimpleRender.SimpleRenderBackend backend) { + for (AxisAlignedBB box : boxes) { + backend.aabb(box); + } + return backend; + } + + @Override + public String toString() { + return "PlayerLog"; + } +}