Skip to content

Commit a890808

Browse files
committed
Update to 1.21.7
1 parent e4783b8 commit a890808

25 files changed

+209
-150
lines changed

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ license=MIT
1818
# Mod Version
1919
baseVersion=1.8.5
2020
# Branch Metadata
21-
branch=1.21
22-
tagBranch=1.21
23-
compatibleVersions= 1.21.1
21+
branch=1.21.7
22+
tagBranch=1.21.7
23+
compatibleVersions= 1.21.7
2424
compatibleLoaders=fabric, quilt, neoforge
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
7-
zipStorePath=wrapper/dists
7+
zipStorePath=wrapper/dists

libs.versions.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
[versions]
2-
loom = "1.7.+"
2+
loom = "1.11.+"
33
minotaur = "2.+"
44

55
kaleidoConfig = "0.3.1+1.3.1"
66

7-
mc = "1.21.1"
8-
fl = "0.16.7"
9-
yarn = "1.21.1+build.3"
10-
fapi = "0.104.0+1.21.1"
7+
mc = "1.21.7"
8+
fl = "0.16.14"
9+
yarn = "1.21.7+build.2"
10+
fapi = "0.128.2+1.21.7"
1111

12-
fpapi = "0.3.1"
13-
libgui = "11.0.0+1.21"
12+
fpapi = "0.4.0"
13+
libgui = "14.0.0+1.21.6"
1414

1515
[plugins]
1616
loom = { id = "fabric-loom", version.ref = "loom" }

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

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,75 @@
22

33
import net.fabricmc.api.EnvType;
44
import net.fabricmc.api.Environment;
5+
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
6+
import net.minecraft.block.AbstractBlock;
57
import net.minecraft.block.Block;
8+
import net.minecraft.block.entity.BlockEntity;
69
import net.minecraft.block.entity.BlockEntityType;
710
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
811
import net.minecraft.component.ComponentType;
912
import net.minecraft.item.BlockItem;
1013
import net.minecraft.item.Item;
14+
import net.minecraft.item.Items;
1115
import net.minecraft.registry.Registries;
1216
import net.minecraft.registry.Registry;
17+
import net.minecraft.registry.RegistryKey;
18+
import net.minecraft.registry.RegistryKeys;
1319
import net.minecraft.util.Identifier;
1420
import net.modfest.scatteredshards.block.ShardBlock;
1521
import net.modfest.scatteredshards.block.ShardBlockEntity;
1622
import net.modfest.scatteredshards.client.render.ShardBlockEntityRenderer;
1723
import net.modfest.scatteredshards.item.ShardItem;
1824
import net.modfest.scatteredshards.item.ShardTablet;
1925

20-
public class ScatteredShardsContent {
21-
public static final Identifier SHARD_BLOCK_ID = ScatteredShards.id("shard_block");
22-
public static final Identifier SHARD_TABLET_ID = ScatteredShards.id("shard_tablet");
23-
public static final Identifier SHARD_ITEM_ID = ScatteredShards.id("shard_item");
26+
import java.util.function.Function;
2427

25-
public static final Block SHARD_BLOCK = new ShardBlock();
26-
public static final Item SHARD_BLOCK_ITEM = new BlockItem(SHARD_BLOCK, new Item.Settings());
28+
public class ScatteredShardsContent {
29+
public static final Block SHARD_BLOCK = registerBlock(ShardBlock::new, ShardBlock.SETTINGS, "shard_block", true);
2730

28-
public static final Item SHARD_TABLET = new ShardTablet(new Item.Settings());
29-
public static final Item SHARD_ITEM = new ShardItem(new Item.Settings());
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");
3033

31-
public static final BlockEntityType<ShardBlockEntity> SHARD_BLOCKENTITY = BlockEntityType.Builder.create(ShardBlockEntity::new, SHARD_BLOCK).build();
34+
public static final BlockEntityType<ShardBlockEntity> SHARD_BLOCKENTITY = registerBlockEntity("shard_block", ShardBlockEntity::new, SHARD_BLOCK);
3235

3336
public static final ComponentType<Identifier> SHARD_ID_COMPONENT = Registry.register(
3437
Registries.DATA_COMPONENT_TYPE,
3538
ScatteredShards.id("shard_id"),
3639
ComponentType.<Identifier>builder().codec(Identifier.CODEC).build()
3740
);
3841

42+
43+
private static Item registerItem(Function<Item.Settings, Item> factory, Item.Settings settings, String path) {
44+
var location = ScatteredShards.id(path);
45+
var key = RegistryKey.of(RegistryKeys.ITEM, location);
46+
47+
return Items.register(key, factory, settings);
48+
}
49+
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));
53+
54+
if (shouldRegisterItem) {
55+
var itemKey = RegistryKey.of(RegistryKeys.ITEM, ScatteredShards.id(path));
56+
57+
var blockItem = new BlockItem(block, new Item.Settings().registryKey(itemKey));
58+
Registry.register(Registries.ITEM, itemKey, blockItem);
59+
}
60+
61+
return Registry.register(Registries.BLOCK, blockKey, block);
62+
}
63+
64+
private static <T extends BlockEntity> BlockEntityType<T> registerBlockEntity(
65+
String path,
66+
FabricBlockEntityTypeBuilder.Factory<? extends T> entityFactory,
67+
Block... blocks
68+
) {
69+
var location = ScatteredShards.id(path);
70+
return Registry.register(Registries.BLOCK_ENTITY_TYPE, location, FabricBlockEntityTypeBuilder.<T>create(entityFactory, blocks).build());
71+
}
72+
3973
public static void register() {
40-
Registry.register(Registries.BLOCK, SHARD_BLOCK_ID, SHARD_BLOCK);
41-
Registry.register(Registries.ITEM, SHARD_BLOCK_ID, SHARD_BLOCK_ITEM);
42-
Registry.register(Registries.BLOCK_ENTITY_TYPE, SHARD_BLOCK_ID, SHARD_BLOCKENTITY);
43-
Registry.register(Registries.ITEM, SHARD_TABLET_ID, SHARD_TABLET);
44-
Registry.register(Registries.ITEM, SHARD_ITEM_ID, SHARD_ITEM);
4574
}
4675

4776
@Environment(EnvType.CLIENT)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ShardDisplaySettings {
2626
).apply(instance, ShardDisplaySettings::new));
2727

2828
public static final PacketCodec<RegistryByteBuf, ShardDisplaySettings> PACKET_CODEC = PacketCodec.tuple(
29-
PacketCodecs.BOOL, ShardDisplaySettings::drawMiniIcons,
29+
PacketCodecs.BOOLEAN, ShardDisplaySettings::drawMiniIcons,
3030
PacketCodecs.INTEGER, ShardDisplaySettings::libraryColor,
3131
PacketCodecs.INTEGER, ShardDisplaySettings::librarySetNameColor,
3232
PacketCodecs.INTEGER, ShardDisplaySettings::viewerTopColor,

src/main/java/net/modfest/scatteredshards/api/impl/ShardCollectionPersistentState.java

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

3+
import com.mojang.serialization.Codec;
34
import net.minecraft.nbt.NbtCompound;
45
import net.minecraft.nbt.NbtElement;
56
import net.minecraft.nbt.NbtList;
67
import net.minecraft.nbt.NbtString;
7-
import net.minecraft.registry.RegistryWrapper;
88
import net.minecraft.server.MinecraftServer;
99
import net.minecraft.util.Identifier;
1010
import net.minecraft.world.PersistentState;
11+
import net.minecraft.world.PersistentStateType;
1112
import net.modfest.scatteredshards.ScatteredShards;
1213
import net.modfest.scatteredshards.api.ScatteredShardsAPI;
1314
import net.modfest.scatteredshards.api.ShardCollection;
@@ -16,20 +17,23 @@
1617
import java.util.UUID;
1718

1819
public class ShardCollectionPersistentState extends PersistentState {
19-
20-
public static PersistentState.Type<ShardCollectionPersistentState> TYPE = new PersistentState.Type<>(
21-
ShardCollectionPersistentState::new,
20+
public static final Codec<ShardCollectionPersistentState> CODEC = NbtCompound.CODEC.xmap(
2221
ShardCollectionPersistentState::createFromNbt,
23-
null
22+
ShardCollectionPersistentState::writeNbt
2423
);
2524

25+
private static final PersistentStateType<ShardCollectionPersistentState> TYPE = new PersistentStateType<>(ScatteredShards.ID + "_collections",
26+
ShardCollectionPersistentState::new,
27+
ShardCollectionPersistentState.CODEC,
28+
null);
29+
2630
public static ShardCollectionPersistentState get(MinecraftServer server) {
27-
ShardCollectionPersistentState result = server.getOverworld().getPersistentStateManager().getOrCreate(TYPE, ScatteredShards.ID + "_collections");
31+
ShardCollectionPersistentState result = server.getOverworld().getPersistentStateManager().getOrCreate(TYPE);
2832
ScatteredShardsAPI.register(result);
2933
return result;
3034
}
3135

32-
public static ShardCollectionPersistentState createFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup lookup) {
36+
public static ShardCollectionPersistentState createFromNbt(NbtCompound tag) {
3337
ShardCollectionPersistentState state = new ShardCollectionPersistentState();
3438
ScatteredShards.LOGGER.info("Loading shard collections for {} players...", tag.getSize());
3539

@@ -39,9 +43,9 @@ public static ShardCollectionPersistentState createFromNbt(NbtCompound tag, Regi
3943
ShardCollection coll = ScatteredShardsAPI.getServerCollection(uuid);
4044
coll.clear();
4145

42-
for (NbtElement elem : tag.getList(s, NbtElement.STRING_TYPE)) {
46+
for (NbtElement elem : tag.getList(s).get()) {
4347
if (elem instanceof NbtString str) {
44-
Identifier shardId = Identifier.of(str.asString());
48+
Identifier shardId = Identifier.of(str.asString().get());
4549
coll.add(shardId);
4650
}
4751
}
@@ -57,8 +61,8 @@ public static ShardCollectionPersistentState createFromNbt(NbtCompound tag, Regi
5761
return state;
5862
}
5963

60-
@Override
61-
public NbtCompound writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
64+
public NbtCompound writeNbt() {
65+
NbtCompound tag = new NbtCompound();
6266
Map<UUID, ShardCollection> collections = ScatteredShardsAPI.exportServerCollections();
6367
ScatteredShards.LOGGER.info("Saving ShardCollections for {} players...", collections.size());
6468

src/main/java/net/modfest/scatteredshards/api/impl/ShardLibraryPersistentState.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
package net.modfest.scatteredshards.api.impl;
22

3+
import com.mojang.serialization.Codec;
34
import net.minecraft.nbt.NbtCompound;
45
import net.minecraft.registry.RegistryWrapper;
56
import net.minecraft.server.MinecraftServer;
67
import net.minecraft.util.Identifier;
78
import net.minecraft.world.PersistentState;
9+
import net.minecraft.world.PersistentStateType;
810
import net.modfest.scatteredshards.ScatteredShards;
911
import net.modfest.scatteredshards.api.ScatteredShardsAPI;
1012
import net.modfest.scatteredshards.api.ShardLibrary;
1113
import net.modfest.scatteredshards.api.shard.Shard;
1214

1315
public class ShardLibraryPersistentState extends PersistentState {
14-
public static PersistentState.Type<ShardLibraryPersistentState> TYPE = new PersistentState.Type<>(
15-
ShardLibraryPersistentState::new,
16+
public static final Codec<ShardLibraryPersistentState> CODEC = NbtCompound.CODEC.xmap(
1617
ShardLibraryPersistentState::createFromNbt,
17-
null
18+
ShardLibraryPersistentState::writeNbt
1819
);
1920

21+
private static final PersistentStateType<ShardLibraryPersistentState> TYPE = new PersistentStateType<>(ScatteredShards.ID + "_library",
22+
ShardLibraryPersistentState::new,
23+
ShardLibraryPersistentState.CODEC,
24+
null);
25+
2026
public static final String SHARDS_KEY = "Shards";
2127

2228
public static ShardLibraryPersistentState get(MinecraftServer server) {
23-
return server.getOverworld().getPersistentStateManager().getOrCreate(TYPE, ScatteredShards.ID + "_library");
29+
return server.getOverworld().getPersistentStateManager().getOrCreate(TYPE);
2430
}
2531

2632
public ShardLibraryPersistentState() {
2733
}
2834

29-
public static ShardLibraryPersistentState createFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup lookup) {
35+
public static ShardLibraryPersistentState createFromNbt(NbtCompound tag) {
3036
ScatteredShards.LOGGER.info("Loading shard library...");
3137
ShardLibraryPersistentState state = new ShardLibraryPersistentState();
3238
// This is just a placeholder - all the data lives in the serverLibrary below
@@ -35,10 +41,10 @@ public static ShardLibraryPersistentState createFromNbt(NbtCompound tag, Registr
3541
library.shards().clear();
3642
library.shardSets().clear();
3743

38-
NbtCompound shards = tag.getCompound(SHARDS_KEY);
44+
NbtCompound shards = tag.getCompound(SHARDS_KEY).get();
3945
for (String id : shards.getKeys()) {
4046
try {
41-
NbtCompound shardNbt = shards.getCompound(id);
47+
NbtCompound shardNbt = shards.getCompound(id).get();
4248
Identifier shardId = Identifier.of(id);
4349
Shard shard = Shard.fromNbt(shardNbt);
4450

@@ -54,8 +60,9 @@ public static ShardLibraryPersistentState createFromNbt(NbtCompound tag, Registr
5460
return state;
5561
}
5662

57-
@Override
58-
public NbtCompound writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
63+
public NbtCompound writeNbt() {
64+
NbtCompound tag = new NbtCompound();
65+
5966
ShardLibrary library = ScatteredShardsAPI.getServerLibrary();
6067
ScatteredShards.LOGGER.info("Saving the ShardLibrary with {} shards and {} shardSets...", library.shards().size(), library.shardSets().size());
6168

src/main/java/net/modfest/scatteredshards/api/shard/ShardType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public static ShardType fromJson(JsonObject obj) {
103103
}
104104

105105
public static void register() {
106-
Registry.register(Registries.SOUND_EVENT, COLLECT_VISITOR_SOUND.getId(), COLLECT_VISITOR_SOUND);
107-
Registry.register(Registries.SOUND_EVENT, COLLECT_CHALLENGE_SOUND.getId(), COLLECT_CHALLENGE_SOUND);
108-
Registry.register(Registries.SOUND_EVENT, COLLECT_SECRET_SOUND.getId(), COLLECT_SECRET_SOUND);
106+
Registry.register(Registries.SOUND_EVENT, COLLECT_VISITOR_SOUND.id(), COLLECT_VISITOR_SOUND);
107+
Registry.register(Registries.SOUND_EVENT, COLLECT_CHALLENGE_SOUND.id(), COLLECT_CHALLENGE_SOUND);
108+
Registry.register(Registries.SOUND_EVENT, COLLECT_SECRET_SOUND.id(), COLLECT_SECRET_SOUND);
109109
}
110110
}

src/main/java/net/modfest/scatteredshards/block/ShardBlock.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.minecraft.component.type.LoreComponent;
1414
import net.minecraft.component.type.NbtComponent;
1515
import net.minecraft.entity.Entity;
16+
import net.minecraft.entity.EntityCollisionHandler;
1617
import net.minecraft.entity.player.PlayerEntity;
1718
import net.minecraft.item.ItemStack;
1819
import net.minecraft.nbt.NbtCompound;
@@ -28,6 +29,7 @@
2829
import net.minecraft.world.BlockView;
2930
import net.minecraft.world.World;
3031
import net.minecraft.world.WorldView;
32+
import net.modfest.scatteredshards.ScatteredShards;
3133
import net.modfest.scatteredshards.ScatteredShardsContent;
3234
import net.modfest.scatteredshards.api.ScatteredShardsAPI;
3335
import net.modfest.scatteredshards.api.ShardLibrary;
@@ -40,16 +42,16 @@
4042

4143
public class ShardBlock extends Block implements BlockEntityProvider {
4244
public static final VoxelShape SHAPE = VoxelShapes.cuboid(4 / 16f, 3 / 16f, 4 / 16f, 12 / 16f, 13 / 16f, 12 / 16f);
43-
private static final Block.Settings SETTINGS = Block.Settings.create()
45+
public static final Block.Settings SETTINGS = Block.Settings.create()
4446
.dropsNothing()
4547
.noCollision()
4648
.nonOpaque()
4749
.luminance(state -> 3)
4850
.strength(-1)
4951
.mapColor(MapColor.EMERALD_GREEN);
5052

51-
public ShardBlock() {
52-
super(SETTINGS);
53+
public ShardBlock(Block.Settings settings) {
54+
super(settings);
5355
}
5456

5557
@Override
@@ -107,7 +109,7 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player
107109
}
108110

109111
@Override
110-
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
112+
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, EntityCollisionHandler handler) {
111113
if (world.isClient || !(entity instanceof PlayerEntity player)) {
112114
return;
113115
}
@@ -117,21 +119,20 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit
117119
}
118120

119121
@Override
120-
public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) {
121-
122+
protected ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state, boolean includeData) {
122123
BlockEntity entity = world.getBlockEntity(pos);
123124
if (world.isClient() && entity instanceof ShardBlockEntity shardEntity) {
124125
Identifier shardId = shardEntity.getShardId();
125126
ShardLibrary library = ScatteredShardsAPI.getClientLibrary();
126127

127128
if (shardId == null || library == null) {
128-
return super.getPickStack(world, pos, state);
129+
return super.getPickStack(world, pos, state, includeData);
129130
}
130131

131132
return createShardBlock(library, shardId, shardEntity.canInteract(), shardEntity.getGlowSize(), shardEntity.getGlowStrength());
132133
} else {
133134

134-
return super.getPickStack(world, pos, state);
135+
return super.getPickStack(world, pos, state, includeData);
135136
}
136137
}
137138

@@ -175,7 +176,7 @@ public static ItemStack createShardBlock(ShardType shardType, Identifier shardId
175176
ItemStack stack = new ItemStack(ScatteredShardsContent.SHARD_BLOCK);
176177

177178
NbtCompound blockEntityTag = new NbtCompound();
178-
blockEntityTag.putString("id", ScatteredShardsContent.SHARD_BLOCK_ID.toString()); // required, see NbtComponent.CODEC_WITH_ID
179+
blockEntityTag.putString("id", ScatteredShards.id("shard_block").toString()); // required, see NbtComponent.CODEC_WITH_ID
179180
blockEntityTag.putString("Shard", shardId.toString());
180181

181182
//Fill in name / lore

0 commit comments

Comments
 (0)