Skip to content

Commit

Permalink
complete the playerTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
uhb217 committed Jan 10, 2024
1 parent 0560b46 commit 3b0aa24
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 185 deletions.
19 changes: 0 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ base {
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven {
name = "CottonMC"
url = "https://server.bbkr.space/artifactory/libs-release"
Expand All @@ -35,18 +30,13 @@ loom {
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
modImplementation include("io.github.cottonmc:LibGui:9.2.1+1.20.2")
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
}

processResources {
Expand All @@ -62,9 +52,6 @@ tasks.withType(JavaCompile).configureEach {
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
Expand All @@ -77,19 +64,13 @@ jar {
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
67 changes: 40 additions & 27 deletions src/client/java/net/uhb217/glowingentity/gui/TestGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
public class TestGUI extends LightweightGuiDescription {
private final Text OFF = Text.literal("Off").formatted(Formatting.RED);
private final Text ON = Text.literal("On").formatted(Formatting.GREEN);

public TestGUI(MinecraftClient client) {
NbtCompound nbt = ((IEntityDataSaver) client.player).getPersistentData();
WPlainPanel root = new WPlainPanel().setInsets(new Insets(0, 0, 0, 0));
this.setRootPanel(root);
root.setSize(144, 190);

createGlowingEntityModule(nbt, root);
createPlayerTrackerModule(nbt,root,client);
createPlayerTrackerModule(nbt, root, client);
}

public void createGlowingEntityModule(NbtCompound nbt, WPlainPanel root) {
Expand All @@ -64,72 +65,84 @@ public void createGlowingEntityModule(NbtCompound nbt, WPlainPanel root) {
});
root.add(button, 28, 11);
}
public void createPlayerTrackerModule(NbtCompound nbt, WPlainPanel root,MinecraftClient mc){

public void createPlayerTrackerModule(NbtCompound nbt, WPlainPanel root, MinecraftClient mc) {
Sprite playerTracker = new Sprite(new Texture(new Identifier(GlowingEntity.MOD_ID, "textures/gui/player_tracker.png"))).setToolTip(Text.literal("Player Tracker").formatted(Formatting.DARK_RED));
root.add(playerTracker, 5, 31);
WToggleButton button = new WToggleButton(Text.literal("Off").formatted(Formatting.RED));
if (nbt.contains("player_tracker") && nbt.getBoolean("player_tracker")){
if (nbt.contains("player_tracker") && nbt.getBoolean("player_tracker")) {
button.setToggle(true);
button.setLabel(ON);
}
button.setOnToggle(aBoolean -> {
if (aBoolean){
if (aBoolean) {
button.setLabel(ON);
nbt.putBoolean("player_tracker",true);
mc.setScreen(new TestScreen(new PlayerTrackerSetTargetGUI(mc)));
}else{
mc.setScreen(new TestScreen(new PlayerTrackerSetTargetGUI(mc)).setParent(new TestScreen(this)));
} else {
button.setLabel(OFF);
nbt.putBoolean("player_tracker",false);
}});
root.add(button,28,32);
nbt.putBoolean("player_tracker", false);
}
});
root.add(button, 28, 32);
}
public static class PlayerTrackerSetTargetGUI extends LightweightGuiDescription{
public PlayerTrackerSetTargetGUI(MinecraftClient mc){
WPlainPanel root = new WPlainPanel().setInsets(new Insets(0,0,0,0));

public static class PlayerTrackerSetTargetGUI extends LightweightGuiDescription {
public PlayerTrackerSetTargetGUI(MinecraftClient mc) {
WPlainPanel root = new WPlainPanel().setInsets(new Insets(0, 0, 0, 0));
this.setRootPanel(root);
root.setSize(108, 70);

Button[][] buttons = new Button[5][3];
for (int i = 0; i < buttons.length; i++) {
for (int j = 0; j < buttons[i].length; j++) {
buttons[i][j] = new Button(new ItemIcon(getPLayersHeads(mc)[0])).setToolTip(Text.literal(getPLayersNames(mc)[0]).formatted(Formatting.GREEN));
int I = i,J = j;
buttons[i][j].setOnClick(()->{
NbtCompound nbt = ((IEntityDataSaver)mc.player).getPersistentData();
if (I + J > getPLayersNames(mc).length)
nbt.putUuid("compass_target",getPlayerUUidFromName(getPLayersNames(mc)[I+J],mc));
else
nbt.putUuid("compass_target",null);
});
buttons[i][j].setSize(25,25);
root.add(buttons[i][j],5+(20 * i),5+(20*j));
buttons[i][j] = new Button();
buttons[i][j].setSize(25, 25);
NbtCompound nbt = ((IEntityDataSaver)mc.player).getPersistentData();
if (!(i + j + 1 > getPLayersHeads(mc).length)) {
String playerName = getPLayersNames(mc)[i+j];
buttons[i][j].setToolTip(Text.literal(playerName).formatted(Formatting.BLUE)).setIcon(new ItemIcon(getPLayersHeads(mc)[i + j]));
buttons[i][j].setOnClick(()->{
nbt.putBoolean("player_tracker", true);
nbt.putUuid("compass_target",getPlayerUUidFromName(playerName,mc));
mc.setScreen(new TestScreen(new TestGUI(mc)));
mc.player.sendMessage(Text.literal("Player Tracker: target: "+playerName));
});
}else
buttons[i][j].setOnClick(()->{
nbt.putBoolean("player_tracker",false);
mc.setScreen(new TestScreen(new TestGUI(mc)));
});
root.add(buttons[i][j], 5 + (20 * i), 5 + (20 * j));
}
}
}
private UUID getPlayerUUidFromName(String name,MinecraftClient mc){
for (AbstractClientPlayerEntity player: mc.world.getPlayers()){

private UUID getPlayerUUidFromName(String name, MinecraftClient mc) {
for (AbstractClientPlayerEntity player : mc.world.getPlayers()) {
if (player.getName().getString().equals(name))
return player.getUuid();
}
return null;
}

public static ItemStack[] getPLayersHeads(MinecraftClient client) {
List<AbstractClientPlayerEntity> players = client.world.getPlayers();
ItemStack[] skulls = new ItemStack[players.size()];
for (int i = 0; i < skulls.length; i++) {
skulls[i] = Items.PLAYER_HEAD.getDefaultStack();
skulls[i].setNbt(getNbtFromProfile(players.get(i).getGameProfile()));
}

return skulls;
}

public static String[] getPLayersNames(MinecraftClient client) {
List<AbstractClientPlayerEntity> players = client.world.getPlayers();
String[] names = new String[players.size()];
for (int i = 0; i < names.length; i++)
names[i] = players.get(i).getName().getString();
return names;
}

public static NbtCompound getNbtFromProfile(GameProfile profile) {
// apply player's skin to head
NbtCompound nbtCompound = new NbtCompound();
Expand Down
10 changes: 10 additions & 0 deletions src/client/java/net/uhb217/glowingentity/gui/TestScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.Screen;

@Environment(EnvType.CLIENT)
public class TestScreen extends CottonClientScreen {
private Screen parent;
public TestScreen(GuiDescription description) {
super(description);
}
public TestScreen setParent(Screen parent) {
this.parent = parent;
return this;
}
@Override
public void close() {
client.setScreen(parent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
public class Button extends WButton {
private static final int ICON_SPACING = 2;
private Text toolTip;
public Button(){
}
public Button(@Nullable Icon icon){
this.setIcon(icon);
}
Expand All @@ -25,7 +27,7 @@ public Button setToolTip(Text toolTip){
return this;
}
public static void drawToolTip(DrawContext context, int x, int y, int mouseX, int mouseY, WWidget widget,Text toolTip){
boolean shouldDrawToolTip = mouseX >= 0 && mouseX <=widget.getWidth() && mouseY >= 0 && mouseY <= widget.getHeight();
boolean shouldDrawToolTip = toolTip != null && mouseX >= 0 && mouseX <=widget.getWidth() && mouseY >= 0 && mouseY <= widget.getHeight();
if (shouldDrawToolTip){
var client = MinecraftClient.getInstance();
context.drawTooltip(client.textRenderer,toolTip,x + mouseX,y + mouseY);
Expand Down

This file was deleted.

Loading

0 comments on commit 3b0aa24

Please sign in to comment.