Skip to content

Commit 2cb03c9

Browse files
Tablist rework
Reworked Tablist and it's underlying mechanics, this is the initial works, the rework is to come to Scoreboard as well
1 parent ed2bf99 commit 2cb03c9

6 files changed

Lines changed: 167 additions & 148 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package mod.gate.core.events;
2+
3+
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
4+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
5+
6+
public class TablistEvent {
7+
public PlayerListS2CPacket packet;
8+
public CallbackInfo info;
9+
10+
public TablistEvent(PlayerListS2CPacket packet, CallbackInfo info) {
11+
this.packet = packet;
12+
this.info = info;
13+
}
14+
}

src/main/java/mod/gate/core/mixin/ActionbarMixin.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212

1313
@Mixin(InGameHud.class)
1414
public class ActionbarMixin {
15-
1615
private static String cachedContent;
1716

18-
1917
@Inject(at = @At("HEAD"), method = "setOverlayMessage", cancellable = true)
20-
private void setOverlayMessageMixin(Text message, boolean tinted, CallbackInfo info) {
18+
private void setOverlayMessage(Text message, boolean tinted, CallbackInfo info) {
2119
if (!message.asString().equals(cachedContent)) {
2220
//only run if it's different than the current stored cache
2321
cachedContent = message.asString();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package mod.gate.core.mixin;
2+
3+
import mod.gate.core.events.ActionbarReceiveEvent;
4+
import mod.gate.core.events.EventHandler;
5+
import mod.gate.core.events.TablistEvent;
6+
import net.minecraft.client.network.ClientPlayNetworkHandler;
7+
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Mixin(ClientPlayNetworkHandler.class)
14+
public class TablistMixin {
15+
16+
@Inject(method = "onPlayerList", at = @At("TAIL"))
17+
private void onPlayerList(PlayerListS2CPacket packet, CallbackInfo info) {
18+
EventHandler.run(new TablistEvent(packet, info));
19+
}
20+
}
Lines changed: 83 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,117 @@
11
package mod.gate.features;
22

33
import mod.gate.core.config.Config;
4-
import mod.gate.core.events.TickEvent;
54
import mod.gate.core.events.Event;
6-
import mod.gate.core.events.JoinWorldEvent;
75
import mod.gate.utils.ChatUtils;
86
import mod.gate.utils.Tablist;
97
import net.minecraft.text.ClickEvent;
108
import net.minecraft.text.HoverEvent;
119
import net.minecraft.text.Style;
1210
import net.minecraft.text.Text;
13-
import org.apache.commons.lang3.reflect.FieldUtils;
11+
12+
import java.util.ArrayList;
1413

1514
public class ForgeReminder {
1615
//region CONFIG
1716
@Config(description = "the configuration for the forge reminder")
18-
public ForgeConfig forgereminder = new ForgeConfig();
17+
public ForgeConfig forgeReminder = new ForgeConfig();
1918
//endregion
2019

20+
@Event(event = Tablist.TablistUpdateEvent.class)
21+
public void onTablistUpdate(Tablist.TablistUpdateEvent event) {
22+
if (event.type != Tablist.TablistUpdateType.OTHER) return;
2123

22-
private boolean hasReceivedTabList = false;
24+
// Finding if the 5th slot is unlocked, it isn't shown on Tablist
25+
if (event.line.equals("Forges (+1 more)") && !forgeReminder.slots.get(5).unlocked) {
26+
forgeReminder.slots.get(5).unlocked = true;
27+
}
2328

24-
@Event(event = JoinWorldEvent.class)
25-
public void onJoinWorldEvent(JoinWorldEvent event) {
26-
if (!this.hasReceivedTabList || !this.forgereminder.enabled) return;
27-
//region check for slots
28-
for (int i = 1; i <= 5; i++) {
29-
try {
30-
long slotTime = FieldUtils.getField(ForgeConfig.class,"slot" + i).getLong(forgereminder);
29+
for (ForgeSlot slot : forgeReminder.slots) {
30+
if (slot.slotNumber != 5) {
31+
processLine(slot, event.line);
32+
};
3133

32-
//if (FieldUtils.getField(ForgeConfig.class, "unlocked" + i).getBoolean(forgereminder)) ChatUtils.sendChatMessage("slot" + i + " is currently at timestamp: " + slotTime);
33-
if (FieldUtils.getField(ForgeConfig.class, "unlocked" + i).getBoolean(forgereminder)
34-
&& System.currentTimeMillis() >= slotTime && slotTime != 0L)
35-
{
36-
//forgereminder.getClass().getField("slot" + i).set(forgereminder, 0L);//set that when the item is removed from forge
34+
if (!slot.unlocked && System.currentTimeMillis() < slot.time && slot.time == 0L && !slot.notify) continue;
35+
slot.notify = false;
3736

38-
Style style = Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of("Click to warp to the forge (if unlocked)")));
39-
style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warpforge"));//TODO find a way to make this click event work
37+
Style style = Style.EMPTY
38+
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of("Click to warp to the forge [if unlocked]")))
39+
//TODO find a way to make this click event work
40+
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warpforge"));
4041

41-
ChatUtils.sendChatMessage(Text.of("§l§6[Gate/ForgeReminder]§f§b Forge §3slot " + i + " is available for pickup.").getWithStyle(style).get(0));
42-
}
43-
}catch (Exception e) {
44-
e.printStackTrace();
45-
}
42+
ChatUtils.sendChatMessage(Text.of(ChatUtils.PREFIX + "§8 | [§bForgeReminder§8] §f> " + "Forge §3slot " + slot.slotNumber + " §fis available for pickup.").getWithStyle(style).get(0));
4643
}
47-
//endregion
48-
49-
this.hasReceivedTabList = false;//first scoreboard packet isn't received at that point
5044
}
5145

52-
@Event(event = TickEvent.class)
53-
public void onTick(TickEvent event) {
54-
if (this.hasReceivedTabList || Tablist.getLines() == null || !this.forgereminder.enabled) return;
55-
this.hasReceivedTabList = true;
56-
//first tick of the scoreboard being accessible
57-
if (!Tablist.getArea().equals("dwarven_mines")) return;
58-
59-
60-
for (String line: Tablist.getLines()) {
61-
if (line.equals("Forges (+1 more)") && !forgereminder.unlocked5) {
62-
forgereminder.unlocked5 = true;//5th one is unlocked
63-
}
64-
65-
for (int i = 1; i<=4; i++) {//forge 5 isn't accessible through tablist
66-
try {
67-
if (line.startsWith(i+")")) {
68-
if (line.endsWith("EMPTY")) {
69-
if (FieldUtils.getField(ForgeConfig.class, "slot" + i).getLong(forgereminder) != 0L) {
70-
forgereminder.getClass().getField("slot" + i).set(forgereminder, 0L);//clear date
71-
}
72-
73-
if (!FieldUtils.getField(ForgeConfig.class, "unlocked" + i).getBoolean(forgereminder)) {
74-
forgereminder.getClass().getField("unlocked" + i).set(forgereminder, true);//set to unlocked
75-
}
76-
77-
} else if (line.endsWith("Ready!")) {
78-
FieldUtils.getField(ForgeConfig.class, "slot"+i).set(forgereminder, System.currentTimeMillis());
79-
if (!FieldUtils.getField(ForgeConfig.class, "unlocked" + i).getBoolean(forgereminder)) {
80-
forgereminder.getClass().getField("unlocked" + i).set(forgereminder, true);//set to unlocked
81-
}
82-
} else {
83-
String DatetoParse = line.substring(3);
84-
85-
long total = 0L;
86-
87-
for (String time: DatetoParse.split(" ")) {
88-
try {
89-
if (time.contains("s")) {
90-
time = time.replace("s", "");
91-
int s = Integer.parseInt(time);
92-
total+= s * 1000L;
93-
} else if (time.contains("m")) {
94-
time = time.replace("m", "");
95-
int m = Integer.parseInt(time);
96-
total += m * 60000L;
97-
} else if (time.contains("h")) {
98-
time = time.replace("h", "");
99-
int h = Integer.parseInt(time);
100-
total += h * 3600000L;
101-
} else if (time.contains("d")) {
102-
time = time.replace("d", "");
103-
int d = Integer.parseInt(time);
104-
total += d * 86400000L;
105-
}
106-
}catch (Exception ignored) {}
107-
//System.out.println("parsed time: " + total);
108-
total += System.currentTimeMillis();
109-
//might be useful to do a check to see if result is accurate
110-
111-
//System.out.println("when it will end: " + (total + System.currentTimeMillis()));
112-
FieldUtils.getField(ForgeConfig.class, "slot"+i).set(forgereminder, total);
113-
}
114-
115-
if (!FieldUtils.getField(ForgeConfig.class, "unlocked" + i).getBoolean(forgereminder)) {
116-
forgereminder.getClass().getField("unlocked" + i).set(forgereminder, true);//set to unlocked
117-
}
118-
}
46+
private void processLine(ForgeSlot slot, String line) {
47+
if (!line.startsWith(slot.slotNumber + ")")) return;
48+
49+
if (line.endsWith("EMPTY")) {
50+
if (slot.time != 0L) slot.time = 0L;
51+
52+
slot.unlocked = true;
53+
slot.notify = true;
54+
} else if (line.endsWith("Ready!")) {
55+
slot.time = System.currentTimeMillis();
56+
57+
slot.unlocked = true;
58+
} else {
59+
String DateToParse = line.substring(3);
60+
long total = 0L;
61+
62+
for (String time : DateToParse.split(" ")) {
63+
if (time.contains("s")) {
64+
time = time.replace("s", "");
65+
int s = Integer.parseInt(time);
66+
total+= s * 1000L;
67+
} else if (time.contains("m")) {
68+
time = time.replace("m", "");
69+
int m = Integer.parseInt(time);
70+
total += m * 60000L;
71+
} else if (time.contains("h")) {
72+
time = time.replace("h", "");
73+
int h = Integer.parseInt(time);
74+
total += h * 3600000L;
75+
} else if (time.contains("d")) {
76+
time = time.replace("d", "");
77+
int d = Integer.parseInt(time);
78+
total += d * 86400000L;
11979
}
120-
}catch (Exception e) {
121-
e.printStackTrace();
12280
}
81+
82+
total += System.currentTimeMillis();
83+
84+
slot.time = total;
85+
86+
slot.unlocked = true;
87+
slot.notify = true;
12388
}
124-
}
12589
}
12690

12791
public static class ForgeConfig {
12892
public boolean enabled = true;
93+
public ArrayList<ForgeSlot> slots = new ArrayList<>();
94+
95+
public ForgeConfig() {
96+
slots.add(new ForgeSlot(1));
97+
slots.add(new ForgeSlot(2));
98+
slots.add(new ForgeSlot(3));
99+
slots.add(new ForgeSlot(4));
100+
slots.add(new ForgeSlot(5));
101+
}
102+
}
129103

130-
public long slot1 = 0L;
131-
public boolean unlocked1 = false;
132-
133-
public long slot2 = 0L;
134-
public boolean unlocked2 = false;
135-
136-
public long slot3 = 0L;
137-
public boolean unlocked3 = false;
138-
139-
public long slot4 = 0L;
140-
public boolean unlocked4 = false;
141-
142-
public long slot5 = 0L;//inaccessible through tab list
143-
public boolean unlocked5 = false;//inaccessible through tab list
104+
public static class ForgeSlot {
105+
public long time;
106+
public boolean unlocked;
107+
public int slotNumber;
108+
public boolean notify;
109+
110+
public ForgeSlot(int slotNumber) {
111+
this.slotNumber = slotNumber;
112+
this.time = 0L;
113+
this.unlocked = false;
114+
this.notify = true;
115+
}
144116
}
145117
}

0 commit comments

Comments
 (0)