add playerlog
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m31s

This commit is contained in:
Daniella / Tove 2024-06-25 23:05:59 +02:00
parent 197c81cc2b
commit 3a4239c1ff
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
3 changed files with 106 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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--);
}
}

View file

@ -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<UUID, Pair<Lock, EntityPlayer>> originalPlayers = new HashMap<>();
ArrayList<AxisAlignedBB> 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<Lock, EntityPlayer> 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<UUID, Pair<Lock, EntityPlayer>> 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";
}
}