spot player(s) when they enter render distance

This commit is contained in:
frelodev 2024-01-10 23:35:13 +01:00
parent bf5405d64d
commit a2df8fd999
2 changed files with 35 additions and 1 deletions

View file

@ -71,9 +71,13 @@ public class Boscovicino implements ICommons {
}
public static void log(String message) {
log(message, true);
}
public static void log(String message, boolean overlay) {
LOGGER.info(message);
if (MC.player != null) {
MC.player.displayClientMessage(new StringTextComponent(message), true);
MC.player.displayClientMessage(new StringTextComponent(message), overlay);
}
}

View file

@ -3,17 +3,37 @@ package ftbsc.bscv.modules.hud;
import com.google.auto.service.AutoService;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.HudModule;
import ftbsc.bscv.tools.Setting;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import static ftbsc.bscv.tools.Text.TextBuilder;
import static ftbsc.bscv.Boscovicino.log;
@AutoService(ILoadable.class)
public class PlayerList extends HudModule {
public final ForgeConfigSpec.ConfigValue<Boolean> notify;
public PlayerList() {
super();
this.notify = Setting.Bool.builder()
.fallback(false)
.name("notify")
.comment("notify when players enter render distance")
.build(this);
}
@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) {
if (event.getType() != ElementType.TEXT) return;
@ -34,4 +54,14 @@ public class PlayerList extends HudModule {
offset += MC.font.lineHeight;
}
}
@SubscribeEvent
public void onEntityEntersRenderdistance(EntityJoinWorldEvent event) {
if (!notify.get()) return;
if (event.getEntity() instanceof PlayerEntity){
PlayerEntity player = (PlayerEntity) event.getEntity();
if (MC.player != null && player.getId() == MC.player.getId()) return;
log(String.format("%s spotted", player.getDisplayName().getString()), false);
}
}
}