Skip to content

Commit 32a2790

Browse files
committed
chore: a whole bunch more cleanup
1 parent d9366b7 commit 32a2790

File tree

94 files changed

+732
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+732
-560
lines changed

common/src/main/java/dev/ftb/mods/ftbchunks/ColorMapLoader.java

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package dev.ftb.mods.ftbchunks;
22

3-
import com.google.gson.Gson;
4-
import com.google.gson.GsonBuilder;
5-
import com.google.gson.JsonElement;
6-
import com.google.gson.JsonObject;
3+
import com.google.gson.*;
74
import dev.ftb.mods.ftbchunks.client.map.color.BlockColor;
85
import dev.ftb.mods.ftbchunks.client.map.color.BlockColors;
96
import dev.ftb.mods.ftbchunks.client.map.color.CustomBlockColor;
@@ -27,7 +24,7 @@ public class ColorMapLoader extends SimplePreparableReloadListener<JsonObject> {
2724

2825
@Override
2926
protected JsonObject prepare(ResourceManager resourceManager, ProfilerFiller profiler) {
30-
Gson gson = new GsonBuilder().setLenient().create();
27+
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).create();
3128
JsonObject object = new JsonObject();
3229

3330
for (String namespace : resourceManager.getNamespaces()) {
@@ -60,30 +57,28 @@ protected void apply(JsonObject object, ResourceManager resourceManager, Profile
6057
Block block = entry.getValue();
6158
Identifier id = entry.getKey().identifier();
6259

63-
if (id != null) {
64-
if (block instanceof AirBlock
65-
|| block instanceof BushBlock
66-
|| block instanceof FireBlock
67-
|| block instanceof ButtonBlock
68-
|| block instanceof TorchBlock && !(block instanceof RedstoneTorchBlock)
69-
|| block instanceof StainedGlassPaneBlock
70-
) {
71-
BLOCK_ID_TO_COLOR_MAP.put(id, BlockColors.IGNORED);
72-
} else if (block instanceof GrassBlock) {
73-
BLOCK_ID_TO_COLOR_MAP.put(id, BlockColors.GRASS);
74-
} else if (block instanceof LeavesBlock || block instanceof VineBlock) {
75-
BLOCK_ID_TO_COLOR_MAP.put(id, BlockColors.FOLIAGE);
76-
} else if (block instanceof FlowerPotBlock) {
77-
BLOCK_ID_TO_COLOR_MAP.put(id, new CustomBlockColor(Color4I.rgb(0x683A2D)));
78-
} else if (FTBCUtils.isRail(block)) {
79-
BLOCK_ID_TO_COLOR_MAP.put(id, new CustomBlockColor(Color4I.rgb(0x888888)));
80-
} else if (block.defaultMapColor() != null) {
81-
BLOCK_ID_TO_COLOR_MAP.put(id, new CustomBlockColor(Color4I.rgb(block.defaultMapColor().col)));
82-
} else {
83-
BLOCK_ID_TO_COLOR_MAP.put(id, new CustomBlockColor(Color4I.RED));
84-
}
85-
}
86-
}
60+
if (block instanceof AirBlock
61+
|| block instanceof BushBlock
62+
|| block instanceof FireBlock
63+
|| block instanceof ButtonBlock
64+
|| block instanceof TorchBlock
65+
|| block instanceof StainedGlassPaneBlock
66+
) {
67+
BLOCK_ID_TO_COLOR_MAP.put(id, BlockColors.IGNORED);
68+
} else if (block instanceof GrassBlock) {
69+
BLOCK_ID_TO_COLOR_MAP.put(id, BlockColors.GRASS);
70+
} else if (block instanceof LeavesBlock || block instanceof VineBlock) {
71+
BLOCK_ID_TO_COLOR_MAP.put(id, BlockColors.FOLIAGE);
72+
} else if (block instanceof FlowerPotBlock) {
73+
BLOCK_ID_TO_COLOR_MAP.put(id, new CustomBlockColor(Color4I.rgb(0x683A2D)));
74+
} else if (FTBCUtils.isRail(block)) {
75+
BLOCK_ID_TO_COLOR_MAP.put(id, new CustomBlockColor(Color4I.rgb(0x888888)));
76+
} else if (block.defaultMapColor() != null) {
77+
BLOCK_ID_TO_COLOR_MAP.put(id, new CustomBlockColor(Color4I.rgb(block.defaultMapColor().col)));
78+
} else {
79+
BLOCK_ID_TO_COLOR_MAP.put(id, new CustomBlockColor(Color4I.RED));
80+
}
81+
}
8782

8883
// Fire event Pre
8984

common/src/main/java/dev/ftb/mods/ftbchunks/FTBCUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static boolean isRail(Block block) {
1313
throw new AssertionError();
1414
}
1515

16-
1716
/**
1817
* Used after various events have been cancelled server-side; client may already have updated the held item for the
1918
* player, but it needs to be brought back in sync with the server.

common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunks.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
5+
import com.google.gson.Strictness;
56
import dev.architectury.event.EventResult;
67
import dev.architectury.event.events.common.*;
78
import dev.architectury.hooks.level.entity.PlayerHooks;
@@ -62,8 +63,9 @@
6263
public class FTBChunks {
6364
public static final String MOD_ID = "ftbchunks";
6465
public static final Logger LOGGER = LogManager.getLogger("FTB Chunks");
65-
public static final Gson GSON = new GsonBuilder().disableHtmlEscaping().setLenient().create();
66+
public static final Gson GSON = new GsonBuilder().disableHtmlEscaping().setStrictness(Strictness.LENIENT).create();
6667

68+
@Nullable
6769
public static FTBChunks instance;
6870

6971
public static final int TILES = 15;
@@ -119,7 +121,9 @@ public FTBChunks() {
119121
PlayerEvent.CHANGE_DIMENSION.register(this::playerChangedDimension);
120122
PlayerEvent.ATTACK_ENTITY.register(this::playerAttackEntity);
121123

122-
EntityEvent.ENTER_SECTION.register(this::enterSection);
124+
// this doesn't work - Arch hook missing?
125+
// EntityEvent.ENTER_SECTION.register(this::enterSection);
126+
123127
EntityEvent.LIVING_CHECK_SPAWN.register(this::checkSpawn);
124128
EntityEvent.LIVING_HURT.register(this::onLivingHurt);
125129

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@ public interface ChunkTeamData {
2424
ClaimedChunkManager getManager();
2525

2626
/**
27-
* Convenience method to get the FTB Teams manager instances.
27+
* Convenience method to get the FTB Teams manager instance.
2828
* @return the team manager
2929
*/
3030
TeamManager getTeamManager();
3131

3232
/**
33-
* Get the team that this data pertains to.
33+
* Get the FTB Teams team that this data pertains to.
3434
*
3535
* @return the team
3636
*/
3737
Team getTeam();
3838

3939
/**
40-
* Get a collection of all the chunks this team currently has claimed.
40+
* Get an immutable collection of all the chunks this team currently has claimed.
4141
*
4242
* @return all the claimed chunks for this team
4343
*/
4444
Collection<? extends ClaimedChunk> getClaimedChunks();
4545

4646
/**
47-
* Get a collection of all the chunks this team currently has force-loading enabled for. Note that the chunks
47+
* Get an immutable collection of all the chunks this team currently has force-loading enabled for. Note that the chunks
4848
* are not necessarily force-loaded right now, depending on player online status and server offline force-loading
4949
* settings; use {@link ClaimedChunk#isActuallyForceLoaded()} to verify this.
5050
*

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dev.ftb.mods.ftblibrary.util.NameMap;
44
import net.minecraft.network.chat.Component;
55
import net.minecraft.network.chat.MutableComponent;
6+
import org.jspecify.annotations.Nullable;
67

78
import java.util.Optional;
89

@@ -55,6 +56,7 @@ static ClaimResult customProblem(String translationKey) {
5556
*
5657
* @return a successful outcome
5758
*/
59+
@Nullable
5860
static ClaimResult success() {
5961
return null;
6062
}
@@ -81,7 +83,7 @@ enum StandardProblem implements ClaimResult {
8183
}
8284

8385
public static Optional<StandardProblem> forName(String name) {
84-
return Optional.ofNullable(NAME_MAP.get(name));
86+
return Optional.ofNullable(NAME_MAP.getNullable(name));
8587
}
8688

8789
public MutableComponent getMessage() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public interface ClaimedChunkManager {
4949
* @param id a player UUID
5050
* @return the FTB Chunks data for the player, or null if something went wrong
5151
*/
52+
@Nullable
5253
ChunkTeamData getPersonalData(UUID id);
5354

5455
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package dev.ftb.mods.ftbchunks.api.client.event;
3+
4+
import org.jspecify.annotations.NullMarked;

common/src/main/java/dev/ftb/mods/ftbchunks/api/client/icon/MapIcon.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ default int getPriority() {
8585
*/
8686
default void addTooltip(TooltipList list) {
8787
Player player = Minecraft.getInstance().player;
88-
Vec3 pos = getPos(1F);
89-
list.styledString(String.format("%,d m", Mth.ceil(MathUtils.dist(player.getX(), player.getZ(), pos.x, pos.z))), ChatFormatting.GRAY);
88+
if (player != null) {
89+
Vec3 pos = getPos(1F);
90+
list.styledString(String.format("%,d m", Mth.ceil(MathUtils.dist(player.getX(), player.getZ(), pos.x, pos.z))), ChatFormatting.GRAY);
91+
}
9092
}
9193

9294
/**
@@ -125,9 +127,9 @@ default void addTooltip(TooltipList list) {
125127
*/
126128
class SimpleMapIcon implements MapIcon {
127129
protected final Vec3 pos;
128-
protected Icon icon;
130+
protected Icon<?> icon;
129131

130-
public SimpleMapIcon(Vec3 pos, Icon icon) {
132+
public SimpleMapIcon(Vec3 pos, Icon<?> icon) {
131133
this.pos = pos;
132134
this.icon = icon;
133135
}
@@ -141,11 +143,11 @@ public Vec3 getPos(float partialTick) {
141143
return pos;
142144
}
143145

144-
public Icon getIcon() {
146+
public Icon<?> getIcon() {
145147
return icon;
146148
}
147149

148-
public void setIcon(Icon icon) {
150+
public void setIcon(Icon<?> icon) {
149151
this.icon = icon;
150152
}
151153

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package dev.ftb.mods.ftbchunks.api.client.icon;
3+
4+
import org.jspecify.annotations.NullMarked;

common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapContext.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import dev.ftb.mods.ftblibrary.math.XZ;
55
import net.minecraft.client.Minecraft;
66
import net.minecraft.client.player.LocalPlayer;
7+
import net.minecraft.world.entity.player.Player;
8+
import net.minecraft.world.level.Level;
79
import net.minecraft.world.phys.Vec3;
810

911
import java.util.Map;
12+
import java.util.Objects;
1013

1114
/**
1215
* Minimal context for Minimap Info Components
@@ -20,7 +23,7 @@
2023
*/
2124
public record MinimapContext(
2225
Minecraft minecraft,
23-
LocalPlayer player,
26+
Player player,
2427
MapDimension mapDimension,
2528
XZ mapChunksPos,
2629
Vec3 playerPos,
@@ -30,4 +33,12 @@ public record MinimapContext(
3033
public String getSetting(MinimapInfoComponent infoComponent) {
3134
return infoSettings.getOrDefault(infoComponent.id().toString(), "");
3235
}
36+
37+
public Level clientLevel() {
38+
return Objects.requireNonNull(minecraft.level);
39+
}
40+
41+
public Player clientPlayer() {
42+
return Objects.requireNonNull(minecraft.player);
43+
}
3344
}

0 commit comments

Comments
 (0)