9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

添加翻译键

This commit is contained in:
XiaoMoMi
2025-12-18 19:26:24 +08:00
parent 9606c17406
commit 31c1dc59e3
7 changed files with 22 additions and 8 deletions

View File

@@ -1,7 +1,5 @@
import net.minecrell.pluginyml.paper.PaperPluginDescription import net.minecrell.pluginyml.paper.PaperPluginDescription
import xyz.jpenilla.runpaper.task.RunServer import xyz.jpenilla.runpaper.task.RunServer
import xyz.jpenilla.runtask.pluginsapi.DownloadPluginsSpec
import java.net.URI
plugins { plugins {
id("com.gradleup.shadow") version "9.3.0" id("com.gradleup.shadow") version "9.3.0"

View File

@@ -20,6 +20,12 @@ public interface CustomBlock {
@Nullable @Nullable
LootTable<?> lootTable(); LootTable<?> lootTable();
@NotNull
default String translationKey() {
Key id = id();
return "block." + id.namespace() + "." + id.value();
}
void execute(Context context, EventTrigger trigger); void execute(Context context, EventTrigger trigger);
@NotNull @NotNull

View File

@@ -22,6 +22,11 @@ public interface CustomFurniture {
FurnitureSettings settings(); FurnitureSettings settings();
default String translationKey() {
Key id = this.id();
return "furniture." + id.namespace() + "." + id.value();
}
@Nullable @Nullable
LootTable<?> lootTable(); LootTable<?> lootTable();

View File

@@ -26,6 +26,11 @@ public interface CustomItem<I> extends BuildableItem<I> {
UniqueKey uniqueId(); UniqueKey uniqueId();
default String translationKey() {
Key id = this.id();
return "item." + id.namespace() + "." + id.value();
}
Key material(); Key material();
Key clientBoundMaterial(); Key clientBoundMaterial();

View File

@@ -211,6 +211,7 @@ public abstract class AbstractPackManager implements PackManager {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
VANILLA_TEXTURES.add(Key.of("minecraft", "font/unicode_page_" + String.format("%02x", i))); VANILLA_TEXTURES.add(Key.of("minecraft", "font/unicode_page_" + String.format("%02x", i)));
} }
VANILLA_TEXTURES.add(Key.of("minecraft", "missingno"));
loadInternalList("internal/textures/processed.json", VANILLA_TEXTURES::add); loadInternalList("internal/textures/processed.json", VANILLA_TEXTURES::add);
loadInternalList("internal/sounds/processed.json", VANILLA_SOUNDS::add); loadInternalList("internal/sounds/processed.json", VANILLA_SOUNDS::add);

View File

@@ -1,7 +1,6 @@
package net.momirealms.craftengine.core.pack.mcmeta.overlay; package net.momirealms.craftengine.core.pack.mcmeta.overlay;
import net.momirealms.craftengine.core.pack.mcmeta.Overlay; import net.momirealms.craftengine.core.pack.mcmeta.Overlay;
import net.momirealms.craftengine.core.util.MinecraftVersion;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View File

@@ -19,18 +19,18 @@ public class LangData {
if (id.contains("[") && id.contains("]")) { if (id.contains("[") && id.contains("]")) {
ImmutableBlockState parsed = BlockStateParser.deserialize(id); ImmutableBlockState parsed = BlockStateParser.deserialize(id);
if (parsed == null) return List.of(id); if (parsed == null) return List.of(id);
return List.of("block." + stateToRealBlockId(parsed)); return List.of(translationKey(parsed));
} else { } else {
Key blockId = Key.of(id); Key blockId = Key.of(id);
Optional<CustomBlock> blockOptional = CraftEngine.instance().blockManager().blockById(blockId); Optional<CustomBlock> blockOptional = CraftEngine.instance().blockManager().blockById(blockId);
if (blockOptional.isPresent()) { if (blockOptional.isPresent()) {
List<ImmutableBlockState> states = blockOptional.get().variantProvider().states(); List<ImmutableBlockState> states = blockOptional.get().variantProvider().states();
if (states.size() == 1) { if (states.size() == 1) {
return List.of("block." + stateToRealBlockId(states.getFirst())); return List.of(translationKey(states.getFirst()));
} else { } else {
ArrayList<String> processed = new ArrayList<>(); ArrayList<String> processed = new ArrayList<>();
for (ImmutableBlockState state : states) { for (ImmutableBlockState state : states) {
processed.add("block." + stateToRealBlockId(state)); processed.add(translationKey(state));
} }
return processed; return processed;
} }
@@ -91,7 +91,7 @@ public class LangData {
}); });
} }
private static String stateToRealBlockId(ImmutableBlockState state) { public static String translationKey(ImmutableBlockState state) {
String id = state.customBlockState().literalObject().toString(); String id = state.customBlockState().literalObject().toString();
int first = -1, last = -1; int first = -1, last = -1;
for (int i = 0; i < id.length(); i++) { for (int i = 0; i < id.length(); i++) {
@@ -113,6 +113,6 @@ public class LangData {
chars[i] = '.'; chars[i] = '.';
} }
} }
return new String(chars); return "block." + new String(chars);
} }
} }