Skip to content

Commit 47b9123

Browse files
committed
v0.15.3.3-rc3 - Fix some StorageData constraints to be IStorageData instead
1 parent b3428b8 commit 47b9123

File tree

10 files changed

+71
-13
lines changed

10 files changed

+71
-13
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ parchment_mappings_version=2024.11.17
1717
mod_id=pmweatherapi
1818
mod_name=PMWeatherAPI
1919
mod_license=GNU GPL 3.0
20-
mod_version=0.15.3.3-rc2
20+
mod_version=0.15.3.3-rc3
2121
mod_group_id=net.nullved
2222
mod_authors=nullved
2323
mod_description=An API for interfacing with ProtoManly's Weather Mod

src/main/java/net/nullved/pmweatherapi/PMWeatherAPI.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import net.minecraft.resources.ResourceLocation;
55
import net.neoforged.bus.api.IEventBus;
66
import net.neoforged.fml.ModContainer;
7+
import net.neoforged.fml.ModList;
8+
import net.neoforged.fml.ModLoader;
79
import net.neoforged.fml.common.Mod;
810
import net.neoforged.fml.config.ModConfig;
911
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
@@ -29,6 +31,8 @@
2931
import net.nullved.pmweatherapi.radar.storage.*;
3032
import net.nullved.pmweatherapi.storage.data.BlockPosData;
3133
import net.nullved.pmweatherapi.storage.data.StorageDataManager;
34+
import org.apache.maven.artifact.versioning.ArtifactVersion;
35+
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
3236
import org.checkerframework.checker.units.qual.C;
3337
import org.slf4j.Logger;
3438

@@ -48,6 +52,23 @@ public PMWeatherAPI(IEventBus modEventBus, ModContainer modContainer) {
4852

4953
LOGGER.info("Initialized PMWAPI");
5054

55+
if (ModList.get().isLoaded("pmweather")) {
56+
ModContainer pmweather = ModList.get().getModContainerById("pmweather").get();
57+
58+
ArtifactVersion pmweatherVer = pmweather.getModInfo().getVersion();
59+
String pmweatherVerS = pmweatherVer.getMajorVersion() + "." + pmweatherVer.getMinorVersion() + "." + pmweatherVer.getIncrementalVersion();
60+
String pmweatherExpected = "0.15.3-1.21.1-alpha";
61+
int pmweatherCompared = pmweatherVer.compareTo(new DefaultArtifactVersion(pmweatherExpected));
62+
63+
if (pmweatherCompared == 0) {
64+
PMWeatherAPI.LOGGER.info("Found PMWeather Version {}", pmweatherExpected.split("-")[0]);
65+
} else if (pmweatherCompared > 0) {
66+
PMWeatherAPI.LOGGER.warn("Found newer PMWeather Version {} than supported ({})! Support is NOT guaranteed!", pmweatherVerS, pmweatherExpected.split("-")[0]);
67+
} else {
68+
PMWeatherAPI.LOGGER.info("Found old PMWeather Version {}! Please update PMWeather to version {}!", pmweatherVerS, pmweatherExpected.split("-")[0]);
69+
}
70+
}
71+
5172
if (FMLEnvironment.dist.isClient()) {
5273
modContainer.registerConfig(ModConfig.Type.CLIENT, PMWClientConfig.SPEC);
5374
modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);

src/main/java/net/nullved/pmweatherapi/client/data/PMWClientStorages.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static void set(ResourceLocation location, ClientStorageInstance<?, ?> in
114114
* @param <T> The {@link IClientStorage}
115115
* @since 0.15.3.3
116116
*/
117-
public static <D extends StorageData, T extends IClientStorage<D>> Optional<ClientStorageInstance<D, T>> get(ResourceLocation location, Class<T> clazz) {
117+
public static <D extends IStorageData, T extends IClientStorage<D>> Optional<ClientStorageInstance<D, T>> get(ResourceLocation location, Class<T> clazz) {
118118
return get(location).cast(clazz);
119119
}
120120

@@ -154,7 +154,7 @@ public static void loadDimension(ClientLevel clientLevel) {
154154
* @param <C> The {@link IClientStorage}
155155
* @since 0.15.3.3
156156
*/
157-
public static <D extends StorageData, C extends IClientStorage<D>> void registerStorage(ResourceLocation id, Class<C> clazz, Function<ClientLevel, C> creator) {
157+
public static <D extends IStorageData, C extends IClientStorage<D>> void registerStorage(ResourceLocation id, Class<C> clazz, Function<ClientLevel, C> creator) {
158158
ClientStorageInstance<D, C> instance = new ClientStorageInstance<>(id, clazz, creator);
159159
STORAGE_INSTANCES.put(id, instance);
160160
}

src/main/java/net/nullved/pmweatherapi/client/storage/ClientStorageInstance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @param <C> The {@link IClientStorage}
2323
* @since 0.15.3.3
2424
*/
25-
public class ClientStorageInstance<D extends StorageData, C extends IClientStorage<D>> {
25+
public class ClientStorageInstance<D extends IStorageData, C extends IClientStorage<D>> {
2626
private final ResourceLocation id;
2727
private final Class<C> clazz;
2828
private final Function<ClientLevel, C> creator;
@@ -46,7 +46,7 @@ public void set(C storage) {
4646
this.storage = storage;
4747
}
4848

49-
public <F extends StorageData, O extends IClientStorage<F>> Optional<ClientStorageInstance<F, O>> cast(Class<O> oclazz) {
49+
public <F extends IStorageData, O extends IClientStorage<F>> Optional<ClientStorageInstance<F, O>> cast(Class<O> oclazz) {
5050
if (oclazz.isAssignableFrom(clazz)) {
5151
@SuppressWarnings("unchecked")
5252
ClientStorageInstance<F, O> casted = new ClientStorageInstance<>(id(), oclazz, cl -> (O) creator.apply(cl));

src/main/java/net/nullved/pmweatherapi/command/StoragesCommand.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.nullved.pmweatherapi.data.PMWStorages;
1919
import net.nullved.pmweatherapi.storage.IServerStorage;
2020
import net.nullved.pmweatherapi.storage.IStorage;
21+
import net.nullved.pmweatherapi.storage.data.IStorageData;
2122
import net.nullved.pmweatherapi.storage.data.StorageData;
2223
import net.nullved.pmweatherapi.util.PMWUtils;
2324

@@ -52,7 +53,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
5253
);
5354
}
5455

55-
private static <D extends StorageData> int clientAll(CommandContext<CommandSourceStack> ctx) {
56+
private static <D extends IStorageData> int clientAll(CommandContext<CommandSourceStack> ctx) {
5657
BiFunction<IStorage<D>, Player, Set<D>> func;
5758
try {
5859
final int radius = ctx.getArgument("radius", Integer.class);
@@ -64,7 +65,7 @@ private static <D extends StorageData> int clientAll(CommandContext<CommandSourc
6465
return execClient(ctx, func);
6566
}
6667

67-
private static <D extends StorageData> int serverAll(CommandContext<CommandSourceStack> ctx) {
68+
private static <D extends IStorageData> int serverAll(CommandContext<CommandSourceStack> ctx) {
6869
BiFunction<IStorage<D>, Player, Set<D>> func;
6970
try {
7071
final int radius = ctx.getArgument("radius", Integer.class);
@@ -84,7 +85,7 @@ private static int serverAdjacentChunks(CommandContext<CommandSourceStack> ctx)
8485
return exec(ctx, (stg, plr) -> stg.getInAdjacentChunks(new ChunkPos(plr.blockPosition())));
8586
}
8687

87-
private static <D extends StorageData> int exec(CommandContext<CommandSourceStack> ctx, BiFunction<IStorage<D>, Player, Set<D>> blocksFunction) {
88+
private static <D extends IStorageData> int exec(CommandContext<CommandSourceStack> ctx, BiFunction<IStorage<D>, Player, Set<D>> blocksFunction) {
8889
PMWeatherAPI.LOGGER.info("Checking for nearby storages...");
8990

9091
Player plr = ctx.getSource().getPlayer();
@@ -120,7 +121,7 @@ private static <D extends StorageData> int exec(CommandContext<CommandSourceStac
120121
return Command.SINGLE_SUCCESS;
121122
}
122123

123-
private static <D extends StorageData> int execClient(CommandContext<CommandSourceStack> ctx, BiFunction<IStorage<D>, Player, Set<D>> blocksFunction) {
124+
private static <D extends IStorageData> int execClient(CommandContext<CommandSourceStack> ctx, BiFunction<IStorage<D>, Player, Set<D>> blocksFunction) {
124125
PMWeatherAPI.LOGGER.info("Checking for nearby storages...");
125126

126127
Player plr = ctx.getSource().getPlayer();

src/main/java/net/nullved/pmweatherapi/data/PMWStorages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static void set(ResourceLocation location, StorageInstance<?, ?> instance
8686
* @param <T> The {@link IServerStorage}
8787
* @since 0.15.3.3
8888
*/
89-
public static <D extends StorageData, T extends IServerStorage<D>> Optional<StorageInstance<D, T>> get(ResourceLocation location, Class<T> clazz) {
89+
public static <D extends IStorageData, T extends IServerStorage<D>> Optional<StorageInstance<D, T>> get(ResourceLocation location, Class<T> clazz) {
9090
return STORAGE_INSTANCES.get(location).cast(clazz);
9191
}
9292

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package net.nullved.pmweatherapi.example.storage;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.nbt.CompoundTag;
5+
import net.minecraft.resources.ResourceLocation;
6+
import net.nullved.pmweatherapi.storage.data.StorageData;
7+
8+
public class CustomStorageData extends StorageData {
9+
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("example", "custom_sd");
10+
private final String string;
11+
12+
public CustomStorageData(BlockPos pos, String string) {
13+
super(pos);
14+
this.string = string;
15+
}
16+
17+
@Override
18+
public ResourceLocation getId() {
19+
return ID;
20+
}
21+
22+
@Override
23+
public CompoundTag serializeToNBT() {
24+
CompoundTag tag = super.serializeToNBT();
25+
tag.putString("string", string);
26+
return tag;
27+
}
28+
29+
public static CustomStorageData deserializeFromNBT(CompoundTag tag, int version) {
30+
BlockPos pos = deserializeBlockPos(tag);
31+
if (pos == null) throw new IllegalArgumentException("Could not read BlockPos in CustomStorageData!");
32+
33+
return new CustomStorageData(pos, tag.getString("string"));
34+
}
35+
}

src/main/java/net/nullved/pmweatherapi/storage/ISyncServerStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import java.util.Collection;
88

9-
public interface ISyncServerStorage<D extends StorageData> extends IServerStorage<D> {
9+
public interface ISyncServerStorage<D extends IStorageData> extends IServerStorage<D> {
1010
/**
1111
* Shorthand for calling {@link #add(IStorageData)} and {@link #syncAdd(IStorageData)}
1212
* @param data The {@link IStorageData} to add and sync

src/main/java/net/nullved/pmweatherapi/storage/PMWStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* @see IClientStorage
5454
* @since 0.15.3.3
5555
*/
56-
public abstract class PMWStorage<D extends StorageData> implements IStorage<D> {
56+
public abstract class PMWStorage<D extends IStorageData> implements IStorage<D> {
5757

5858
/**
5959
* A {@link Set} of {@link IStorageData} split up by {@link ChunkPos}

src/main/java/net/nullved/pmweatherapi/util/PMWUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.world.level.Level;
77
import net.nullved.pmweatherapi.radar.NearbyRadars;
88
import net.nullved.pmweatherapi.storage.IStorage;
9+
import net.nullved.pmweatherapi.storage.data.IStorageData;
910
import net.nullved.pmweatherapi.storage.data.StorageData;
1011

1112
import java.util.HashSet;
@@ -55,7 +56,7 @@ public static Set<BlockPos> testAround(BlockPos pos, Function<BlockPos, Boolean>
5556
* @return A {@link Set} of {@link BlockPos} that are in the {@link IStorage} around the base {@link BlockPos}
5657
* @since 0.15.3.3
5758
*/
58-
public static <D extends StorageData> Set<D> storageCornerAdjacent(IStorage<D> storage, BlockPos pos) {
59+
public static <D extends IStorageData> Set<D> storageCornerAdjacent(IStorage<D> storage, BlockPos pos) {
5960
HashSet<D> set = new HashSet<>();
6061

6162
for (D data: storage.getInAdjacentChunks(new ChunkPos(pos))) {

0 commit comments

Comments
 (0)