mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
添加翻译键
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import net.minecrell.pluginyml.paper.PaperPluginDescription
|
||||
import xyz.jpenilla.runpaper.task.RunServer
|
||||
import xyz.jpenilla.runtask.pluginsapi.DownloadPluginsSpec
|
||||
import java.net.URI
|
||||
|
||||
plugins {
|
||||
id("com.gradleup.shadow") version "9.3.0"
|
||||
|
||||
@@ -20,6 +20,12 @@ public interface CustomBlock {
|
||||
@Nullable
|
||||
LootTable<?> lootTable();
|
||||
|
||||
@NotNull
|
||||
default String translationKey() {
|
||||
Key id = id();
|
||||
return "block." + id.namespace() + "." + id.value();
|
||||
}
|
||||
|
||||
void execute(Context context, EventTrigger trigger);
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -22,6 +22,11 @@ public interface CustomFurniture {
|
||||
|
||||
FurnitureSettings settings();
|
||||
|
||||
default String translationKey() {
|
||||
Key id = this.id();
|
||||
return "furniture." + id.namespace() + "." + id.value();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
LootTable<?> lootTable();
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ public interface CustomItem<I> extends BuildableItem<I> {
|
||||
|
||||
UniqueKey uniqueId();
|
||||
|
||||
default String translationKey() {
|
||||
Key id = this.id();
|
||||
return "item." + id.namespace() + "." + id.value();
|
||||
}
|
||||
|
||||
Key material();
|
||||
|
||||
Key clientBoundMaterial();
|
||||
|
||||
@@ -211,6 +211,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
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", "missingno"));
|
||||
loadInternalList("internal/textures/processed.json", VANILLA_TEXTURES::add);
|
||||
loadInternalList("internal/sounds/processed.json", VANILLA_SOUNDS::add);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package 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.Nullable;
|
||||
|
||||
|
||||
@@ -19,18 +19,18 @@ public class LangData {
|
||||
if (id.contains("[") && id.contains("]")) {
|
||||
ImmutableBlockState parsed = BlockStateParser.deserialize(id);
|
||||
if (parsed == null) return List.of(id);
|
||||
return List.of("block." + stateToRealBlockId(parsed));
|
||||
return List.of(translationKey(parsed));
|
||||
} else {
|
||||
Key blockId = Key.of(id);
|
||||
Optional<CustomBlock> blockOptional = CraftEngine.instance().blockManager().blockById(blockId);
|
||||
if (blockOptional.isPresent()) {
|
||||
List<ImmutableBlockState> states = blockOptional.get().variantProvider().states();
|
||||
if (states.size() == 1) {
|
||||
return List.of("block." + stateToRealBlockId(states.getFirst()));
|
||||
return List.of(translationKey(states.getFirst()));
|
||||
} else {
|
||||
ArrayList<String> processed = new ArrayList<>();
|
||||
for (ImmutableBlockState state : states) {
|
||||
processed.add("block." + stateToRealBlockId(state));
|
||||
processed.add(translationKey(state));
|
||||
}
|
||||
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();
|
||||
int first = -1, last = -1;
|
||||
for (int i = 0; i < id.length(); i++) {
|
||||
@@ -113,6 +113,6 @@ public class LangData {
|
||||
chars[i] = '.';
|
||||
}
|
||||
}
|
||||
return new String(chars);
|
||||
return "block." + new String(chars);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user