Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit 3fd8a1b

Browse files
author
Andrei Hava
committed
use data components
1 parent b9925c4 commit 3fd8a1b

11 files changed

Lines changed: 218 additions & 111 deletions

File tree

.idea/runConfigurations/Fabric_Server___fabric__fabric.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/generated/resources/assets/minecraft/models/item/air.json renamed to common/src/generated/resources/assets/buildersvoid/models/item/linked_void_pearl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"parent": "minecraft:item/generated",
33
"textures": {
4-
"layer0": "minecraft:item/air"
4+
"layer0": "buildersvoid:item/linked_void_pearl"
55
}
66
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"parent": "minecraft:recipes/root",
3+
"criteria": {
4+
"has_ender_pearl": {
5+
"conditions": {
6+
"items": [
7+
{
8+
"items": "minecraft:ender_pearl"
9+
}
10+
]
11+
},
12+
"trigger": "minecraft:inventory_changed"
13+
},
14+
"has_pink_dye": {
15+
"conditions": {
16+
"items": [
17+
{
18+
"items": "minecraft:pink_dye"
19+
}
20+
]
21+
},
22+
"trigger": "minecraft:inventory_changed"
23+
},
24+
"has_the_recipe": {
25+
"conditions": {
26+
"recipe": "buildersvoid:linked_void_pearl"
27+
},
28+
"trigger": "minecraft:recipe_unlocked"
29+
}
30+
},
31+
"requirements": [
32+
[
33+
"has_the_recipe",
34+
"has_pink_dye",
35+
"has_ender_pearl"
36+
]
37+
],
38+
"rewards": {
39+
"recipes": [
40+
"buildersvoid:linked_void_pearl"
41+
]
42+
}
43+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"type": "minecraft:crafting_shaped",
3+
"category": "misc",
4+
"key": {
5+
"d": {
6+
"item": "minecraft:pink_dye"
7+
},
8+
"p": {
9+
"item": "minecraft:ender_pearl"
10+
}
11+
},
12+
"pattern": [
13+
" d ",
14+
"dpd",
15+
" d "
16+
],
17+
"result": {
18+
"count": 1,
19+
"id": "buildersvoid:linked_void_pearl"
20+
}
21+
}

common/src/main/java/dev/detpikachu/buildersvoid/ModCommon.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.detpikachu.buildersvoid;
22

33
import dev.detpikachu.buildersvoid.command.ModCommands;
4+
import dev.detpikachu.buildersvoid.data.ModDataComponents;
45
import dev.detpikachu.buildersvoid.item.ModItems;
56
import dev.detpikachu.buildersvoid.network.ModNetwork;
67
import net.blay09.mods.balm.api.Balm;
@@ -9,6 +10,7 @@ public class ModCommon {
910
public static void initialize() {
1011
ModConfig.initialize(Balm.getConfig());
1112
ModNetwork.initialize(Balm.getNetworking());
13+
ModDataComponents.initialize(Balm.getComponents());
1214
ModItems.initialize(Balm.getItems());
1315
ModCommands.initialize(Balm.getCommands());
1416
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package dev.detpikachu.buildersvoid.data;
2+
3+
import net.blay09.mods.balm.api.component.BalmComponents;
4+
import net.minecraft.core.component.DataComponentType;
5+
6+
import static dev.detpikachu.buildersvoid.ModConstants.id;
7+
8+
public class ModDataComponents {
9+
public static DataComponentType<UserIdentifier> USER_IDENTIFIER;
10+
11+
public static void initialize(BalmComponents components) {
12+
components.registerComponent(() -> USER_IDENTIFIER = DataComponentType.<UserIdentifier>builder().
13+
persistent(UserIdentifier.CODEC).
14+
networkSynchronized(UserIdentifier.STREAM_CODEC).
15+
build(),
16+
id("user_identifier"));
17+
}
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dev.detpikachu.buildersvoid.data;
2+
3+
import com.mojang.serialization.Codec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import io.netty.buffer.ByteBuf;
6+
import net.minecraft.network.codec.ByteBufCodecs;
7+
import net.minecraft.network.codec.StreamCodec;
8+
9+
import java.util.UUID;
10+
11+
public record UserIdentifier(UUID uuid, String name) {
12+
public static final Codec<UserIdentifier> CODEC = RecordCodecBuilder.create(instance -> instance
13+
.group(
14+
Codec.STRING.fieldOf("uuid").forGetter((obj) -> obj.uuid.toString()),
15+
Codec.STRING.fieldOf("name").forGetter(UserIdentifier::name)
16+
)
17+
.apply(instance, (uuid, name) -> new UserIdentifier(UUID.fromString(uuid), name))
18+
);
19+
20+
public static final StreamCodec<ByteBuf, UserIdentifier> STREAM_CODEC = StreamCodec.composite(
21+
ByteBufCodecs.STRING_UTF8, (obj) -> obj.uuid.toString(),
22+
ByteBufCodecs.STRING_UTF8, UserIdentifier::name,
23+
(uuid, name) -> new UserIdentifier(UUID.fromString(uuid), name)
24+
);
25+
}

0 commit comments

Comments
 (0)