feat: added search filter to entitylist

This commit is contained in:
əlemi 2023-02-20 02:29:50 +01:00
parent a3491632e7
commit 385797718d
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -8,11 +8,15 @@ import java.util.List;
import java.util.stream.Collectors;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.modules.HudModule;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.util.text.Color;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.ForgeConfigSpec;
@ -20,8 +24,16 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class EntityList extends HudModule implements ICommons {
public final ForgeConfigSpec.ConfigValue<String> search;
public EntityList(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
super("EntityList", builder, dispatcher);
this.search = this.option(
"search", "highlight names containing this text", "",
StringArgumentType.string(), String.class,
builder, dispatcher
);
}
@SubscribeEvent
@ -52,6 +64,11 @@ public class EntityList extends HudModule implements ICommons {
.x(this.x.get())
.y(this.y.get() + offset)
.scale(this.scale.get())
.style(
this.search.get().length() > 0 && u.toLowerCase().contains(this.search.get().toLowerCase())
? Style.EMPTY.withBold(true).withColor(Color.fromLegacyFormat(TextFormatting.GOLD))
: Style.EMPTY.withColor(Color.fromLegacyFormat(TextFormatting.WHITE))
)
.render(event.getMatrixStack(), event.getWindow());
offset += MC.font.lineHeight;
}