Skip to content

Commit a789a1f

Browse files
committed
fix: sync custom claim problems to client as well as standard ones
1 parent 3334d29 commit a789a1f

File tree

4 files changed

+31
-39
lines changed

4 files changed

+31
-39
lines changed

common/src/main/java/dev/ftb/mods/ftbchunks/api/ClaimResult.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ default boolean isSuccess() {
3333
*
3434
* @return the message to be displayed
3535
*/
36-
MutableComponent getMessage();
36+
default MutableComponent getMessage() {
37+
return Component.translatable(getResultId());
38+
}
3739

3840
/**
3941
* Create a custom claim failure result. This may be of use to mods which add extra checks to claiming/forcing/etc.
@@ -76,23 +78,19 @@ enum StandardProblem implements ClaimResult {
7678

7779
public static final NameMap<StandardProblem> NAME_MAP = NameMap.of(NOT_OWNER, values()).baseNameKey("ftbchunks.standard_problem").create();
7880

79-
private final String resultName;
81+
private final String resultId;
8082

81-
StandardProblem(String resultName) {
82-
this.resultName = resultName;
83+
StandardProblem(String resultId) {
84+
this.resultId = "ftbchunks.claim_result." + resultId;
8385
}
8486

8587
public static Optional<StandardProblem> forName(String name) {
8688
return Optional.ofNullable(NAME_MAP.getNullable(name));
8789
}
8890

89-
public MutableComponent getMessage() {
90-
return Component.translatable("ftbchunks.claim_result." + getResultId());
91-
}
92-
9391
@Override
9492
public String getResultId() {
95-
return resultName;
93+
return resultId;
9694
}
9795
}
9896

@@ -102,20 +100,15 @@ public String getResultId() {
102100
* Use {@link ClaimResult#customProblem(String)} to create instances of this class.
103101
*/
104102
class CustomProblem implements ClaimResult {
105-
private final String name;
103+
private final String translationKey;
106104

107-
private CustomProblem(String name) {
108-
this.name = name;
105+
private CustomProblem(String translationKey) {
106+
this.translationKey = translationKey;
109107
}
110108

111109
@Override
112110
public String getResultId() {
113-
return name;
114-
}
115-
116-
@Override
117-
public MutableComponent getMessage() {
118-
return Component.translatable(name);
111+
return translationKey;
119112
}
120113
}
121114
}

common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/map/ChunkScreenPanel.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import dev.architectury.networking.NetworkManager;
55
import dev.ftb.mods.ftbchunks.FTBChunks;
66
import dev.ftb.mods.ftbchunks.FTBChunksWorldConfig;
7-
import dev.ftb.mods.ftbchunks.api.ClaimResult.StandardProblem;
87
import dev.ftb.mods.ftbchunks.api.FTBChunksAPI;
98
import dev.ftb.mods.ftbchunks.api.client.icon.MapType;
109
import dev.ftb.mods.ftbchunks.client.FTBChunksClient;
@@ -38,6 +37,7 @@
3837
import net.minecraft.client.gui.GuiGraphics;
3938
import net.minecraft.client.renderer.RenderPipelines;
4039
import net.minecraft.network.chat.Component;
40+
import net.minecraft.network.chat.MutableComponent;
4141
import net.minecraft.server.permissions.Permissions;
4242
import net.minecraft.world.entity.player.Player;
4343
import net.minecraft.world.level.ChunkPos;
@@ -75,7 +75,7 @@ public ChunkScreenPanel(ChunkScreen panel) {
7575
alignWidgets();
7676
}
7777

78-
public static void notifyChunkUpdates(int totalChunks, int changedChunks, EnumMap<StandardProblem, Integer> problems) {
78+
public static void notifyChunkUpdates(int totalChunks, int changedChunks, Map<String, Integer> problems) {
7979
if (Minecraft.getInstance().screen instanceof ScreenWrapper sw && sw.getGui() instanceof ChunkScreen cs) {
8080
cs.getChunkScreen().updateInfo = new ChunkUpdateInfo(totalChunks, changedChunks, problems, ClientUtils.getClientLevel().getGameTime());
8181
FTBChunksClient.INSTANCE.getMinimapRenderer().requestTextureRefresh();
@@ -195,10 +195,10 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int
195195
if (updateInfo.shouldDisplay()) {
196196
theme.drawString(graphics, updateInfo.summary(), sx + 2, sy + 2, Theme.SHADOW);
197197
int line = 1;
198-
for (Map.Entry<StandardProblem, Integer> entry : updateInfo.problems.entrySet()) {
199-
StandardProblem problem = entry.getKey();
198+
for (Map.Entry<String, Integer> entry : updateInfo.problems.entrySet()) {
199+
MutableComponent problem = Component.translatable(entry.getKey());
200200
int count = entry.getValue();
201-
theme.drawString(graphics, problem.getMessage().append(": " + count), sx + 2, sy + 5 + theme.getFontHeight() * line++, Theme.SHADOW);
201+
theme.drawString(graphics, problem.append(": " + count), sx + 2, sy + 5 + theme.getFontHeight() * line++, Theme.SHADOW);
202202
}
203203
}
204204
}
@@ -348,11 +348,10 @@ public XZ getChunkPos() {
348348
}
349349
}
350350

351-
public record ChunkUpdateInfo(int totalChunks, int changedChunks, EnumMap<StandardProblem, Integer> problems, long timestamp) {
351+
public record ChunkUpdateInfo(int totalChunks, int changedChunks, Map<String, Integer> problems, long timestamp) {
352352
private static final ChunkUpdateInfo NONE = new ChunkUpdateInfo(
353-
0, 0, new EnumMap<>(StandardProblem.class), 0L
353+
0, 0, Map.of(), 0L
354354
);
355-
356355
public boolean shouldDisplay() {
357356
if (timestamp == 0L) return false;
358357

common/src/main/java/dev/ftb/mods/ftbchunks/net/ChunkChangeResponsePacket.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package dev.ftb.mods.ftbchunks.net;
22

33
import dev.architectury.networking.NetworkManager;
4-
import dev.ftb.mods.ftbchunks.api.ClaimResult.StandardProblem;
54
import dev.ftb.mods.ftbchunks.api.FTBChunksAPI;
65
import dev.ftb.mods.ftbchunks.client.gui.map.ChunkScreenPanel;
7-
import dev.ftb.mods.ftblibrary.util.NetworkHelper;
86
import net.minecraft.network.FriendlyByteBuf;
97
import net.minecraft.network.codec.ByteBufCodecs;
108
import net.minecraft.network.codec.StreamCodec;
119
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
1210

13-
import java.util.EnumMap;
11+
import java.util.HashMap;
12+
import java.util.Map;
1413

15-
public record ChunkChangeResponsePacket(int totalChunks, int changedChunks, EnumMap<StandardProblem,Integer> problems) implements CustomPacketPayload {
14+
public record ChunkChangeResponsePacket(
15+
int totalChunks, int changedChunks, Map<String,Integer> problems
16+
) implements CustomPacketPayload
17+
{
1618
public static final Type<ChunkChangeResponsePacket> TYPE = new Type<>(FTBChunksAPI.id("chunk_change_response_packet"));
1719

1820
public static final StreamCodec<FriendlyByteBuf, ChunkChangeResponsePacket> STREAM_CODEC = StreamCodec.composite(
1921
ByteBufCodecs.VAR_INT, ChunkChangeResponsePacket::totalChunks,
2022
ByteBufCodecs.VAR_INT, ChunkChangeResponsePacket::changedChunks,
21-
ByteBufCodecs.map(i -> new EnumMap<>(StandardProblem.class), NetworkHelper.enumStreamCodec(StandardProblem.class), ByteBufCodecs.VAR_INT), ChunkChangeResponsePacket::problems,
23+
ByteBufCodecs.map(HashMap::new, ByteBufCodecs.STRING_UTF8, ByteBufCodecs.VAR_INT), ChunkChangeResponsePacket::problems,
2224
ChunkChangeResponsePacket::new
2325
);
2426

common/src/main/java/dev/ftb/mods/ftbchunks/net/RequestChunkChangePacket.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,15 @@ public static void handle(RequestChunkChangePacket message, NetworkManager.Packe
6767
case UNLOAD -> pos -> data.unForceLoad(source, pos.dim(player.level()), false, message.tryAdminChanges);
6868
};
6969

70-
EnumMap<ClaimResult.StandardProblem, Integer> problems = new EnumMap<>(ClaimResult.StandardProblem.class);
70+
Map<String,Integer> problems = new HashMap<>();
71+
7172
int changed = 0;
7273
for (XZ pos : message.chunks) {
73-
ClaimResult result = consumer.apply(pos);
74-
if (!result.isSuccess()) {
74+
ClaimResult r = consumer.apply(pos);
75+
if (!r.isSuccess()) {
7576
FTBChunks.LOGGER.debug("{} tried to {} @ {}:{}:{} but got result {}",
76-
player.getScoreboardName(), message.action.name, player.level().dimension().identifier(),
77-
pos.x(), pos.z(), result);
78-
if (result instanceof ClaimResult.StandardProblem problem) {
79-
problems.put(problem, problems.getOrDefault(problem, 0) + 1);
80-
}
77+
player.getScoreboardName(), message.action.name, player.level().dimension().identifier(), pos.x(), pos.z(), r);
78+
problems.put(r.getResultId(), problems.getOrDefault(r.getResultId(), 0) + 1);
8179
} else {
8280
changed++;
8381
}

0 commit comments

Comments
 (0)