Skip to content

Commit eaad308

Browse files
Add language data generator
1 parent b55b77a commit eaad308

18 files changed

+396
-119
lines changed

build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@ publishing {
7272
loom {
7373
accessWidenerPath = file("src/main/resources/commandsplus.accesswidener")
7474
}
75+
76+
fabricApi {
77+
configureDataGeneration() {
78+
client = true
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// 1.21.4 -999999999-01-01T00:00:00 Commands+/Language (en_us)
2+
b42c4b6c1c9254c414a0561bef2cf6b85bbf5709 assets/commandsplus/lang/en_us.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"commands.clearspawnpoint.failed": "Failed to clear spawnpoint",
3+
"commands.clearspawnpoint.success": "Cleared spawnpoint of %s player(s)",
4+
"commands.cpride.evict_riders.failed": "Failed to evict rider(s)",
5+
"commands.cpride.evict_riders.success": "Evicted rider(s)",
6+
"commands.cpride.start_riding.failed": "Failed to ride the entity",
7+
"commands.cpride.start_riding.success": "Mounted entities",
8+
"commands.cpride.stop_riding.failed": "Failed to dismount the entity",
9+
"commands.cpride.stop_riding.success": "Dismounted entities",
10+
"commands.cpride.summon_ride.failed": "Failed to summon a ride",
11+
"commands.cpride.summon_ride.success": "Summoned and mounted to a %s",
12+
"commands.cpride.summon_rider.failed": "Failed to summon a rider",
13+
"commands.cpride.summon_rider.success": "Summoned and mounted a %s",
14+
"commands.cpstop.cancel.failed": "Failed to cancel server stop",
15+
"commands.cpstop.cancel.success": "Canceled server stop",
16+
"commands.cpstop.immediate": "Stopping server now",
17+
"commands.cpstop.stop": "Stopped server",
18+
"commands.cpstop.time": "Stopping server in %s second(s)...",
19+
"commands.daylock.disabled": "Disabled daylock",
20+
"commands.daylock.enabled": "Enabled daylock",
21+
"commands.gamerulepreset.load.changed": "Changed gamerule %s: %s -> %s",
22+
"commands.gamerulepreset.load.failed": "Failed to load gamerule preset: %s",
23+
"commands.gamerulepreset.load.success": "Loaded gamerule preset: %s",
24+
"commands.gamerulepreset.load.unchanged": "No gamerules were affected by: %s",
25+
"commands.gamerulepreset.save.success": "Saved gamerule preset: %s",
26+
"commands.head.give.failed": "Failed to give head to player",
27+
"commands.head.give.success": "Gave head to player",
28+
"commands.head.query.name.success": "The head belongs to %s",
29+
"commands.head.query.uuid.success": "The head's owner's UUID is %s",
30+
"commands.health.add.failed": "Failed to add health",
31+
"commands.health.add.success": "Added %s health",
32+
"commands.health.query.failed": "Failed to query health",
33+
"commands.health.query.success": "Health is %s",
34+
"commands.health.set.failed": "Failed to set health",
35+
"commands.health.set.success": "Set health to %s",
36+
"commands.hunger.add.exhaustion.failed": "Failed to add exhaustion",
37+
"commands.hunger.add.exhaustion.success": "Added %s exhaustion",
38+
"commands.hunger.add.food.failed": "Failed to add food",
39+
"commands.hunger.add.food.success": "Added %s food",
40+
"commands.hunger.add.saturation.failed": "Failed to add saturation",
41+
"commands.hunger.add.saturation.success": "Added %s saturation",
42+
"commands.hunger.query.exhaustion.failed": "Failed to query exhaustion",
43+
"commands.hunger.query.exhaustion.success": "Player's exhaustion is %s",
44+
"commands.hunger.query.food.failed": "Failed to query food",
45+
"commands.hunger.query.food.success": "Player's food is %s",
46+
"commands.hunger.query.saturation.failed": "Failed to query saturation",
47+
"commands.hunger.query.saturation.success": "Player's saturation is %s",
48+
"commands.hunger.set.exhaustion.failed": "Failed to set exhaustion",
49+
"commands.hunger.set.exhaustion.success": "Set exhaustion to %s",
50+
"commands.hunger.set.food.failed": "Failed to set food",
51+
"commands.hunger.set.food.success": "Set food to %s",
52+
"commands.hunger.set.saturation.failed": "Failed to set saturation",
53+
"commands.hunger.set.saturation.success": "Set saturation to %s",
54+
"commands.name.entity.failed": "Failed to name entity",
55+
"commands.name.entity.success": "Named entity to \"%s\"",
56+
"commands.name.item.failed": "Failed to name item",
57+
"commands.name.item.success": "Named item to \"%s\"",
58+
"commands.setowner.failed": "Failed to set pet's owner",
59+
"commands.setowner.success": "Set pet's owner to %s",
60+
"commands.toggledownfall.success": "Toggled downfall",
61+
"gamerule.doEndermanPickup": "Do Enderman Pickup",
62+
"gamerule.doEndermanPickup.description": "Allow Endermen to pickup blocks.",
63+
"gamerule.doEndermanPlace": "Do Enderman Place",
64+
"gamerule.doEndermanPlace.description": "Allow Endermen to place blocks.",
65+
"gamerule.itemDespawnAge": "Item Despawn Age",
66+
"gamerule.itemDespawnAge.description": "Controls how long it takes for an item to despawn."
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.thepinkhacker.commandsplus.data;
2+
3+
import com.thepinkhacker.commandsplus.CommandsPlus;
4+
import com.thepinkhacker.commandsplus.data.lang.LanguageProvider;
5+
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
6+
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
7+
8+
public class DataGenerator implements DataGeneratorEntrypoint {
9+
@Override
10+
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
11+
FabricDataGenerator.Pack pack = fabricDataGenerator.createPack();
12+
pack.addProvider(LanguageProvider::new);
13+
}
14+
15+
@Override
16+
public String getEffectiveModId() {
17+
return CommandsPlus.MOD_ID;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.thepinkhacker.commandsplus.data.lang;
2+
3+
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class GenericTranslationBuilder {
9+
private final FabricLanguageProvider.TranslationBuilder builder;
10+
private final List<Node> children = new ArrayList<>();
11+
12+
private GenericTranslationBuilder(FabricLanguageProvider.TranslationBuilder builder) {
13+
this.builder = builder;
14+
}
15+
16+
public static GenericTranslationBuilder of(FabricLanguageProvider.TranslationBuilder builder) {
17+
return new GenericTranslationBuilder(builder);
18+
}
19+
20+
public GenericTranslationBuilder child(Node child) {
21+
children.add(child);
22+
return this;
23+
}
24+
25+
public void build() {
26+
for (Node child : this.children) {
27+
child.build("", this.builder);
28+
}
29+
}
30+
31+
public static class Node {
32+
private final String value;
33+
private final List<Node> children = new ArrayList<>();
34+
35+
private Node(String value) {
36+
this.value = value;
37+
}
38+
39+
public static Node of(String value) {
40+
return new Node(value);
41+
}
42+
43+
public Node child(Node child) {
44+
this.children.add(child);
45+
return this;
46+
}
47+
48+
public Node child(String child, String subchild) {
49+
this.children.add(of(child).child(of(subchild)));
50+
return this;
51+
}
52+
53+
protected void build(String context, FabricLanguageProvider.TranslationBuilder builder) {
54+
if (this.children.isEmpty()) {
55+
builder.add(context, this.value);
56+
} else {
57+
if (!context.isEmpty()) context += ".";
58+
59+
for (Node child : this.children) {
60+
child.build(context + this.value, builder);
61+
}
62+
}
63+
}
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
package com.thepinkhacker.commandsplus.data.lang;
2+
3+
import com.thepinkhacker.commandsplus.world.GameRuleManager;
4+
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
5+
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;
6+
import net.minecraft.registry.RegistryWrapper;
7+
import net.minecraft.world.GameRules;
8+
9+
import java.util.concurrent.CompletableFuture;
10+
11+
public class LanguageProvider extends FabricLanguageProvider {
12+
public LanguageProvider(FabricDataOutput dataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
13+
super(dataOutput, registryLookup);
14+
}
15+
16+
@Override
17+
public void generateTranslations(RegistryWrapper.WrapperLookup lookup, TranslationBuilder builder) {
18+
addGamerule(
19+
builder,
20+
GameRuleManager.DO_ENDERMAN_PICKUP,
21+
"Do Enderman Pickup",
22+
"Allow Endermen to pickup blocks."
23+
);
24+
addGamerule(
25+
builder,
26+
GameRuleManager.DO_ENDERMAN_PLACE,
27+
"Do Enderman Place",
28+
"Allow Endermen to place blocks."
29+
);
30+
addGamerule(
31+
builder,
32+
GameRuleManager.ITEM_DESPAWN_AGE,
33+
"Item Despawn Age",
34+
"Controls how long it takes for an item to despawn."
35+
);
36+
37+
GenericTranslationBuilder.of(builder)
38+
.child(GenericTranslationBuilder.Node.of("commands")
39+
.child(GenericTranslationBuilder.Node.of("clearspawnpoint")
40+
.child("failed", "Failed to clear spawnpoint")
41+
.child("success", "Cleared spawnpoint of %s player(s)")
42+
)
43+
.child(GenericTranslationBuilder.Node.of("cpride")
44+
.child(GenericTranslationBuilder.Node.of("evict_riders")
45+
.child("failed", "Failed to evict rider(s)")
46+
.child("success", "Evicted rider(s)")
47+
)
48+
.child(GenericTranslationBuilder.Node.of("start_riding")
49+
.child("failed", "Failed to ride the entity")
50+
.child("success", "Mounted entities")
51+
)
52+
.child(GenericTranslationBuilder.Node.of("stop_riding")
53+
.child("failed", "Failed to dismount the entity")
54+
.child("success", "Dismounted entities")
55+
)
56+
.child(GenericTranslationBuilder.Node.of("summon_ride")
57+
.child("failed", "Failed to summon a ride")
58+
.child("success", "Summoned and mounted to a %s")
59+
)
60+
.child(GenericTranslationBuilder.Node.of("summon_rider")
61+
.child("failed", "Failed to summon a rider")
62+
.child("success", "Summoned and mounted a %s")
63+
)
64+
)
65+
.child(GenericTranslationBuilder.Node.of("cpstop")
66+
.child(GenericTranslationBuilder.Node.of("cancel")
67+
.child("failed", "Failed to cancel server stop")
68+
.child("success", "Canceled server stop")
69+
)
70+
.child("immediate", "Stopping server now")
71+
.child("stop", "Stopped server")
72+
.child("time", "Stopping server in %s second(s)...")
73+
)
74+
.child(GenericTranslationBuilder.Node.of("daylock")
75+
.child("enabled", "Enabled daylock")
76+
.child("disabled", "Disabled daylock")
77+
)
78+
.child(GenericTranslationBuilder.Node.of("gamerulepreset")
79+
.child(GenericTranslationBuilder.Node.of("load")
80+
.child("changed", "Changed gamerule %s: %s -> %s")
81+
.child("failed", "Failed to load gamerule preset: %s")
82+
.child("unchanged", "No gamerules were affected by: %s")
83+
.child("success", "Loaded gamerule preset: %s")
84+
)
85+
.child(GenericTranslationBuilder.Node.of("save")
86+
.child("success", "Saved gamerule preset: %s")
87+
)
88+
)
89+
.child(GenericTranslationBuilder.Node.of("head")
90+
.child(GenericTranslationBuilder.Node.of("give")
91+
.child("failed", "Failed to give head to player")
92+
.child("success", "Gave head to player")
93+
)
94+
.child(GenericTranslationBuilder.Node.of("query")
95+
.child(GenericTranslationBuilder.Node.of("name")
96+
.child("success", "The head belongs to %s")
97+
)
98+
.child(GenericTranslationBuilder.Node.of("uuid")
99+
.child("success", "The head's owner's UUID is %s")
100+
)
101+
)
102+
)
103+
.child(GenericTranslationBuilder.Node.of("health")
104+
.child(GenericTranslationBuilder.Node.of("add")
105+
.child("failed", "Failed to add health")
106+
.child("success", "Added %s health")
107+
)
108+
.child(GenericTranslationBuilder.Node.of("query")
109+
.child("failed", "Failed to query health")
110+
.child("success", "Health is %s")
111+
)
112+
.child(GenericTranslationBuilder.Node.of("set")
113+
.child("failed", "Failed to set health")
114+
.child("success", "Set health to %s")
115+
)
116+
)
117+
.child(GenericTranslationBuilder.Node.of("hunger")
118+
.child(GenericTranslationBuilder.Node.of("add")
119+
.child(GenericTranslationBuilder.Node.of("exhaustion")
120+
.child("failed", "Failed to add exhaustion")
121+
.child("success", "Added %s exhaustion")
122+
)
123+
.child(GenericTranslationBuilder.Node.of("food")
124+
.child("failed", "Failed to add food")
125+
.child("success", "Added %s food")
126+
)
127+
.child(GenericTranslationBuilder.Node.of("saturation")
128+
.child("failed", "Failed to add saturation")
129+
.child("success", "Added %s saturation")
130+
)
131+
)
132+
.child(GenericTranslationBuilder.Node.of("query")
133+
.child(GenericTranslationBuilder.Node.of("exhaustion")
134+
.child("failed", "Failed to query exhaustion")
135+
.child("success", "Player's exhaustion is %s")
136+
)
137+
.child(GenericTranslationBuilder.Node.of("food")
138+
.child("failed", "Failed to query food")
139+
.child("success", "Player's food is %s")
140+
)
141+
.child(GenericTranslationBuilder.Node.of("saturation")
142+
.child("failed", "Failed to query saturation")
143+
.child("success", "Player's saturation is %s")
144+
)
145+
)
146+
.child(GenericTranslationBuilder.Node.of("set")
147+
.child(GenericTranslationBuilder.Node.of("exhaustion")
148+
.child("failed", "Failed to set exhaustion")
149+
.child("success", "Set exhaustion to %s")
150+
)
151+
.child(GenericTranslationBuilder.Node.of("food")
152+
.child("failed", "Failed to set food")
153+
.child("success", "Set food to %s")
154+
)
155+
.child(GenericTranslationBuilder.Node.of("saturation")
156+
.child("failed", "Failed to set saturation")
157+
.child("success", "Set saturation to %s")
158+
)
159+
)
160+
)
161+
.child(GenericTranslationBuilder.Node.of("name")
162+
.child(GenericTranslationBuilder.Node.of("entity")
163+
.child("failed", "Failed to name entity")
164+
// TODO: Color name
165+
.child("success", "Named entity to \"%s\"")
166+
)
167+
.child(GenericTranslationBuilder.Node.of("item")
168+
.child("failed", "Failed to name item")
169+
// TODO: Color name
170+
.child("success", "Named item to \"%s\"")
171+
)
172+
)
173+
.child(GenericTranslationBuilder.Node.of("setowner")
174+
.child("failed", "Failed to set pet's owner")
175+
.child("success", "Set pet's owner to %s")
176+
)
177+
.child(GenericTranslationBuilder.Node.of("toggledownfall")
178+
.child("success", "Toggled downfall")
179+
)
180+
)
181+
.build();
182+
}
183+
184+
private static void addGamerule(
185+
TranslationBuilder builder,
186+
GameRules.Key<?> gamerule,
187+
String title,
188+
String description
189+
) {
190+
addGamerule(builder, gamerule, title);
191+
builder.add(gamerule.getTranslationKey() + ".description", description);
192+
}
193+
194+
private static void addGamerule(TranslationBuilder builder, GameRules.Key<?> gamerule, String title) {
195+
builder.add(gamerule.getTranslationKey(), title);
196+
}
197+
}

src/main/java/com/thepinkhacker/commandsplus/server/command/ClearSpawnPointCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private static int clearSpawnPoint(ServerCommandSource source, Collection<Server
4242
int finalI = i;
4343
source.sendFeedback(() -> Text.translatable("commands.clearspawnpoint.success", finalI), true);
4444
} else {
45-
throw new SimpleCommandExceptionType(Text.translatable("commands.clearspawnpoint.fail")).create();
45+
throw new SimpleCommandExceptionType(Text.translatable("commands.clearspawnpoint.failed")).create();
4646
}
4747

4848
return i;

0 commit comments

Comments
 (0)