Skip to content

Commit f311f45

Browse files
committed
remap to mojmaps
1 parent 1cbb217 commit f311f45

66 files changed

Lines changed: 1181 additions & 1168 deletions

File tree

Some content is hidden

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

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies {
2020
include libs.kaleidoConfig
2121

2222
minecraft libs.mc
23-
mappings variantOf(libs.yarn) { classifier "v2" }
23+
mappings loom.officialMojangMappings()
2424

2525
modImplementation libs.fl
2626
modImplementation libs.fapi

src/main/java/net/modfest/scatteredshards/ScatteredShards.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import net.fabricmc.api.ModInitializer;
44
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
55
import net.fabricmc.loader.api.FabricLoader;
6-
import net.minecraft.util.Identifier;
6+
import net.minecraft.resources.ResourceLocation;
77
import net.modfest.scatteredshards.api.ScatteredShardsAPI;
88
import net.modfest.scatteredshards.api.shard.ShardType;
99
import net.modfest.scatteredshards.command.ShardCommand;
@@ -20,8 +20,8 @@ public class ScatteredShards implements ModInitializer {
2020

2121
public static final ScatteredShardsConfig CONFIG = ScatteredShardsConfig.createToml(FabricLoader.getInstance().getConfigDir(), "", ID, ScatteredShardsConfig.class);
2222

23-
public static Identifier id(String path) {
24-
return Identifier.of(ID, path);
23+
public static ResourceLocation id(String path) {
24+
return ResourceLocation.fromNamespaceAndPath(ID, path);
2525
}
2626

2727
public static String permission(String path) {

src/main/java/net/modfest/scatteredshards/ScatteredShardsContent.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
import net.fabricmc.api.EnvType;
44
import net.fabricmc.api.Environment;
55
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
6-
import net.minecraft.block.AbstractBlock;
7-
import net.minecraft.block.Block;
8-
import net.minecraft.block.entity.BlockEntity;
9-
import net.minecraft.block.entity.BlockEntityType;
10-
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
11-
import net.minecraft.component.ComponentType;
12-
import net.minecraft.item.BlockItem;
13-
import net.minecraft.item.Item;
14-
import net.minecraft.item.Items;
15-
import net.minecraft.registry.Registries;
16-
import net.minecraft.registry.Registry;
17-
import net.minecraft.registry.RegistryKey;
18-
import net.minecraft.registry.RegistryKeys;
19-
import net.minecraft.util.Identifier;
6+
import net.minecraft.world.level.block.state.BlockBehaviour;
7+
import net.minecraft.world.level.block.Block;
8+
import net.minecraft.world.level.block.entity.BlockEntity;
9+
import net.minecraft.world.level.block.entity.BlockEntityType;
10+
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
11+
import net.minecraft.core.component.DataComponentType;
12+
import net.minecraft.world.item.BlockItem;
13+
import net.minecraft.world.item.Item;
14+
import net.minecraft.world.item.Items;
15+
import net.minecraft.core.registries.BuiltInRegistries;
16+
import net.minecraft.core.Registry;
17+
import net.minecraft.resources.ResourceKey;
18+
import net.minecraft.core.registries.Registries;
19+
import net.minecraft.resources.ResourceLocation;
2020
import net.modfest.scatteredshards.block.ShardBlock;
2121
import net.modfest.scatteredshards.block.ShardBlockEntity;
2222
import net.modfest.scatteredshards.client.render.ShardBlockEntityRenderer;
@@ -28,53 +28,53 @@
2828
public class ScatteredShardsContent {
2929
public static final Block SHARD_BLOCK = registerBlock(ShardBlock::new, ShardBlock.SETTINGS, "shard_block", true);
3030

31-
public static final Item SHARD_TABLET = registerItem(ShardTablet::new, new Item.Settings(), "shard_tablet");
32-
public static final Item SHARD_ITEM = registerItem(ShardItem::new, new Item.Settings(), "shard_item");
31+
public static final Item SHARD_TABLET = registerItem(ShardTablet::new, new Item.Properties(), "shard_tablet");
32+
public static final Item SHARD_ITEM = registerItem(ShardItem::new, new Item.Properties(), "shard_item");
3333

3434
public static final BlockEntityType<ShardBlockEntity> SHARD_BLOCKENTITY = registerBlockEntity("shard_block", ShardBlockEntity::new, SHARD_BLOCK);
3535

36-
public static final ComponentType<Identifier> SHARD_ID_COMPONENT = Registry.register(
37-
Registries.DATA_COMPONENT_TYPE,
36+
public static final DataComponentType<ResourceLocation> SHARD_ID_COMPONENT = Registry.register(
37+
BuiltInRegistries.DATA_COMPONENT_TYPE,
3838
ScatteredShards.id("shard_id"),
39-
ComponentType.<Identifier>builder().codec(Identifier.CODEC).build()
39+
DataComponentType.<ResourceLocation>builder().persistent(ResourceLocation.CODEC).build()
4040
);
4141

4242

43-
private static Item registerItem(Function<Item.Settings, Item> factory, Item.Settings settings, String path) {
43+
private static Item registerItem(Function<Item.Properties, Item> factory, Item.Properties settings, String path) {
4444
var location = ScatteredShards.id(path);
45-
var key = RegistryKey.of(RegistryKeys.ITEM, location);
45+
var key = ResourceKey.create(Registries.ITEM, location);
4646

47-
return Items.register(key, factory, settings);
47+
return Items.registerItem(key, factory, settings);
4848
}
4949

50-
private static <T extends Block> T registerBlock(Function<AbstractBlock.Settings, T> blockFactory, AbstractBlock.Settings settings, String path, boolean shouldRegisterItem) {
51-
var blockKey = RegistryKey.of(RegistryKeys.BLOCK, ScatteredShards.id(path));
52-
var block = blockFactory.apply(settings.registryKey(blockKey));
50+
private static <T extends Block> T registerBlock(Function<net.minecraft.world.level.block.state.BlockBehaviour.Properties, T> blockFactory, net.minecraft.world.level.block.state.BlockBehaviour.Properties settings, String path, boolean shouldRegisterItem) {
51+
var blockKey = ResourceKey.create(Registries.BLOCK, ScatteredShards.id(path));
52+
var block = blockFactory.apply(settings.setId(blockKey));
5353

5454
if (shouldRegisterItem) {
55-
var itemKey = RegistryKey.of(RegistryKeys.ITEM, ScatteredShards.id(path));
55+
var itemKey = ResourceKey.create(Registries.ITEM, ScatteredShards.id(path));
5656

57-
var blockItem = new BlockItem(block, new Item.Settings().registryKey(itemKey));
58-
Registry.register(Registries.ITEM, itemKey, blockItem);
57+
var blockItem = new BlockItem(block, new Item.Properties().setId(itemKey));
58+
Registry.register(BuiltInRegistries.ITEM, itemKey, blockItem);
5959
}
6060

61-
return Registry.register(Registries.BLOCK, blockKey, block);
61+
return Registry.register(BuiltInRegistries.BLOCK, blockKey, block);
6262
}
6363

6464
private static <T extends BlockEntity> BlockEntityType<T> registerBlockEntity(
65-
String path,
66-
FabricBlockEntityTypeBuilder.Factory<? extends T> entityFactory,
67-
Block... blocks
65+
String path,
66+
FabricBlockEntityTypeBuilder.Factory<? extends T> entityFactory,
67+
Block... blocks
6868
) {
6969
var location = ScatteredShards.id(path);
70-
return Registry.register(Registries.BLOCK_ENTITY_TYPE, location, FabricBlockEntityTypeBuilder.<T>create(entityFactory, blocks).build());
70+
return Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, location, FabricBlockEntityTypeBuilder.<T>create(entityFactory, blocks).build());
7171
}
7272

7373
public static void register() {
7474
}
7575

7676
@Environment(EnvType.CLIENT)
7777
public static void registerClient() {
78-
BlockEntityRendererFactories.register(ScatteredShardsContent.SHARD_BLOCKENTITY, ShardBlockEntityRenderer::new);
78+
BlockEntityRenderers.register(ScatteredShardsContent.SHARD_BLOCKENTITY, ShardBlockEntityRenderer::new);
7979
}
8080
}

src/main/java/net/modfest/scatteredshards/api/GlobalCollection.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package net.modfest.scatteredshards.api;
22

3-
import net.minecraft.network.RegistryByteBuf;
4-
import net.minecraft.network.codec.PacketCodec;
5-
import net.minecraft.network.codec.PacketCodecs;
6-
import net.minecraft.util.Identifier;
3+
import net.minecraft.network.RegistryFriendlyByteBuf;
4+
import net.minecraft.network.codec.StreamCodec;
5+
import net.minecraft.network.codec.ByteBufCodecs;
6+
import net.minecraft.resources.ResourceLocation;
77

88
import java.util.HashMap;
99
import java.util.Objects;
1010

1111
public class GlobalCollection {
1212
int totalPlayers;
13-
HashMap<Identifier, Integer> collectionTracker;
13+
HashMap<ResourceLocation, Integer> collectionTracker;
1414

15-
public GlobalCollection(int totalPlayers, HashMap<Identifier, Integer> collectionTracker) {
15+
public GlobalCollection(int totalPlayers, HashMap<ResourceLocation, Integer> collectionTracker) {
1616
this.totalPlayers = totalPlayers;
1717
this.collectionTracker = collectionTracker;
1818
}
@@ -21,21 +21,21 @@ public int totalPlayers() {
2121
return totalPlayers;
2222
}
2323

24-
public HashMap<Identifier, Integer> collectionTracker() {
24+
public HashMap<ResourceLocation, Integer> collectionTracker() {
2525
return collectionTracker;
2626
}
2727

28-
public static final PacketCodec<RegistryByteBuf, GlobalCollection> PACKET_CODEC = PacketCodec.tuple(
29-
PacketCodecs.INTEGER, GlobalCollection::totalPlayers,
30-
PacketCodecs.map(HashMap::new, Identifier.PACKET_CODEC, PacketCodecs.VAR_INT), GlobalCollection::collectionTracker,
28+
public static final StreamCodec<RegistryFriendlyByteBuf, GlobalCollection> PACKET_CODEC = StreamCodec.composite(
29+
ByteBufCodecs.INT, GlobalCollection::totalPlayers,
30+
ByteBufCodecs.map(HashMap::new, ResourceLocation.STREAM_CODEC, ByteBufCodecs.VAR_INT), GlobalCollection::collectionTracker,
3131
GlobalCollection::new
3232
);
3333

34-
public int getCount(Identifier shard) {
34+
public int getCount(ResourceLocation shard) {
3535
return Objects.requireNonNullElse(collectionTracker.get(shard), 0);
3636
}
3737

38-
public void update(Identifier shard, int change, int playerCount) {
38+
public void update(ResourceLocation shard, int change, int playerCount) {
3939
collectionTracker.compute(shard, (k, count) -> count != null ? count + change : 1);
4040
totalPlayers = playerCount;
4141
}

src/main/java/net/modfest/scatteredshards/api/MiniMultiregistry.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import com.mojang.serialization.Codec;
88
import com.mojang.serialization.DynamicOps;
99
import com.mojang.serialization.JsonOps;
10-
import net.minecraft.nbt.NbtCompound;
10+
import net.minecraft.nbt.CompoundTag;
1111
import net.minecraft.nbt.NbtOps;
12-
import net.minecraft.util.Identifier;
12+
import net.minecraft.resources.ResourceLocation;
1313

1414
import java.util.Collection;
1515
import java.util.List;
@@ -20,43 +20,43 @@
2020
* Little wrap around Multimap to make it easier to manage as a registry
2121
*/
2222
public class MiniMultiregistry<T> {
23-
private final Multimap<Identifier, T> data = MultimapBuilder.hashKeys().hashSetValues(3).build();
24-
private final Codec<Map<Identifier, Collection<T>>> mapCodec;
23+
private final Multimap<ResourceLocation, T> data = MultimapBuilder.hashKeys().hashSetValues(3).build();
24+
private final Codec<Map<ResourceLocation, Collection<T>>> mapCodec;
2525

2626
public MiniMultiregistry(Codec<T> valueCodec) {
27-
mapCodec = Codec.unboundedMap(Identifier.CODEC, valueCodec.listOf().xmap(Functions.identity(), List::copyOf));
27+
mapCodec = Codec.unboundedMap(ResourceLocation.CODEC, valueCodec.listOf().xmap(Functions.identity(), List::copyOf));
2828
}
2929

30-
public Collection<T> get(Identifier id) {
30+
public Collection<T> get(ResourceLocation id) {
3131
return data.get(id);
3232
}
3333

34-
public void forEachMapping(BiConsumer<Identifier, T> consumer) {
34+
public void forEachMapping(BiConsumer<ResourceLocation, T> consumer) {
3535
data.forEach(consumer);
3636
}
3737

38-
public void forEachSet(BiConsumer<Identifier, Collection<T>> consumer) {
38+
public void forEachSet(BiConsumer<ResourceLocation, Collection<T>> consumer) {
3939
data.asMap().forEach(consumer);
4040
}
4141

42-
public void put(Identifier key, T value) {
42+
public void put(ResourceLocation key, T value) {
4343
data.put(key, value);
4444
}
4545

46-
public void removeValue(Identifier key, T value) {
46+
public void removeValue(ResourceLocation key, T value) {
4747
data.remove(key, value);
4848
}
4949

50-
public void removeKey(Identifier key) {
50+
public void removeKey(ResourceLocation key) {
5151
data.removeAll(key);
5252
}
5353

5454
public void clear() {
5555
data.clear();
5656
}
5757

58-
public NbtCompound toNbt() {
59-
return (NbtCompound) mapCodec.encodeStart(NbtOps.INSTANCE, data.asMap()).result().orElseThrow();
58+
public CompoundTag toNbt() {
59+
return (CompoundTag) mapCodec.encodeStart(NbtOps.INSTANCE, data.asMap()).result().orElseThrow();
6060
}
6161

6262
public JsonObject toJson() {
@@ -71,7 +71,7 @@ public <U> void syncFrom(DynamicOps<U> sourceDataType, U sourceData) {
7171
});
7272
}
7373

74-
public void syncFromNbt(NbtCompound tag) {
74+
public void syncFromNbt(CompoundTag tag) {
7575
syncFrom(NbtOps.INSTANCE, tag);
7676
}
7777

src/main/java/net/modfest/scatteredshards/api/MiniRegistry.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import com.mojang.serialization.DynamicOps;
88
import com.mojang.serialization.JsonOps;
99
import com.mojang.serialization.codecs.UnboundedMapCodec;
10-
import net.minecraft.nbt.NbtCompound;
10+
import net.minecraft.nbt.CompoundTag;
1111
import net.minecraft.nbt.NbtOps;
12-
import net.minecraft.network.RegistryByteBuf;
13-
import net.minecraft.network.codec.PacketCodec;
14-
import net.minecraft.network.codec.PacketCodecs;
15-
import net.minecraft.util.Identifier;
12+
import net.minecraft.network.RegistryFriendlyByteBuf;
13+
import net.minecraft.network.codec.StreamCodec;
14+
import net.minecraft.network.codec.ByteBufCodecs;
15+
import net.minecraft.resources.ResourceLocation;
1616

1717
import java.util.Collection;
1818
import java.util.HashMap;
@@ -25,42 +25,42 @@
2525
* Little wrapper around BiMap to optionalize some things
2626
*/
2727
public class MiniRegistry<T> {
28-
private final BiMap<Identifier, T> data = HashBiMap.create();
29-
private final UnboundedMapCodec<Identifier, T> mapCodec;
28+
private final BiMap<ResourceLocation, T> data = HashBiMap.create();
29+
private final UnboundedMapCodec<ResourceLocation, T> mapCodec;
3030

3131
public MiniRegistry(Codec<T> valueCodec) {
32-
this.mapCodec = Codec.unboundedMap(Identifier.CODEC, valueCodec);
32+
this.mapCodec = Codec.unboundedMap(ResourceLocation.CODEC, valueCodec);
3333
}
3434

35-
public Optional<T> get(Identifier id) {
35+
public Optional<T> get(ResourceLocation id) {
3636
return Optional.ofNullable(data.get(id));
3737
}
3838

39-
public Optional<Identifier> get(T value) {
39+
public Optional<ResourceLocation> get(T value) {
4040
return Optional.ofNullable(data.inverse().get(value));
4141
}
4242

43-
public void forEach(BiConsumer<Identifier, T> consumer) {
43+
public void forEach(BiConsumer<ResourceLocation, T> consumer) {
4444
data.forEach(consumer);
4545
}
4646

47-
public Stream<Identifier> streamKeys() {
47+
public Stream<ResourceLocation> streamKeys() {
4848
return data.keySet().stream();
4949
}
5050

51-
public void put(Identifier id, T value) {
51+
public void put(ResourceLocation id, T value) {
5252
data.put(id, value);
5353
}
5454

55-
public void putAll(Map<Identifier, T> values) {
55+
public void putAll(Map<ResourceLocation, T> values) {
5656
data.putAll(values);
5757
}
5858

59-
public void remove(Identifier id) {
59+
public void remove(ResourceLocation id) {
6060
data.remove(id);
6161
}
6262

63-
public void removeAll(Collection<Identifier> ids) {
63+
public void removeAll(Collection<ResourceLocation> ids) {
6464
data.keySet().removeAll(ids);
6565
}
6666

@@ -72,8 +72,8 @@ public int size() {
7272
return data.size();
7373
}
7474

75-
public NbtCompound toNbt() {
76-
return (NbtCompound) mapCodec.encodeStart(NbtOps.INSTANCE, data).result().orElseThrow();
75+
public CompoundTag toNbt() {
76+
return (CompoundTag) mapCodec.encodeStart(NbtOps.INSTANCE, data).result().orElseThrow();
7777
}
7878

7979
public JsonObject toJson() {
@@ -87,7 +87,7 @@ public <U> void syncFrom(DynamicOps<U> sourceDataFlavor, U sourceData) {
8787
});
8888
}
8989

90-
public void syncFromNbt(NbtCompound tag) {
90+
public void syncFromNbt(CompoundTag tag) {
9191
syncFrom(NbtOps.INSTANCE, tag);
9292
}
9393

@@ -96,8 +96,8 @@ public void syncFromJson(JsonObject obj) {
9696
}
9797

9898
// this is not great
99-
public static <T> PacketCodec<RegistryByteBuf, MiniRegistry<T>> createPacketCodec(Codec<T> valueCodec) {
100-
return PacketCodecs.map(HashMap::new, Identifier.PACKET_CODEC, PacketCodecs.codec(valueCodec)).xmap(
99+
public static <T> StreamCodec<RegistryFriendlyByteBuf, MiniRegistry<T>> createPacketCodec(Codec<T> valueCodec) {
100+
return ByteBufCodecs.map(HashMap::new, ResourceLocation.STREAM_CODEC, ByteBufCodecs.fromCodec(valueCodec)).map(
101101
map -> {
102102
MiniRegistry<T> registry = new MiniRegistry<>(valueCodec);
103103
registry.putAll(map);

0 commit comments

Comments
 (0)