Add Chinese translation to the Addon

@wed150
This commit is contained in:
2025-12-20 18:39:45 +08:00
Unverified
parent 668ae3185e
commit 874eff29d4
7 changed files with 1005 additions and 16 deletions
+23 -8
View File
@@ -1,7 +1,7 @@
import { GameMode, system, world } from '@minecraft/server';
import { Raycaster } from '../classes/Raycaster';
import { Raycaster } from './Raycaster';
import { fetchMatchingItemSlot } from '../utils';
import { Block_state, chinese_text, State_values } from './zh_CN';
class BlockInfo {
static shownToLastTick = new Set();
@@ -12,7 +12,9 @@ class BlockInfo {
this.showStructureBlockInfo(player);
}
}
/**
* @param {import('@minecraft/server').Player} player
* */
static showStructureBlockInfo(player) {
const block = Raycaster.getTargetedStructureBlock(player, { isFirst: true, collideWithWorldBlocks: true, useActiveLayer: true });
if (!block && this.shownToLastTick.has(player.id)) {
@@ -25,14 +27,14 @@ class BlockInfo {
}
if (!block)
return;
player.onScreenDisplay.setActionBar(this.getFormattedBlockInfo(player, block.permutation));
player.onScreenDisplay.setActionBar(this.getFormattedBlockInfo(player, block));
this.shownToLastTick.add(player.id);
}
static getFormattedBlockInfo(player, block) {
return { rawtext: [
{ translate: 'construct.blockinfo.header' },
this.getSupplyMessage(player, block),
this.getSupplyMessage(player, block.permutation),
{ text: '\n' },
this.getBlockMessage(block)
] };
@@ -41,8 +43,14 @@ class BlockInfo {
static getBlockMessage(block) {
if (!block)
return { translate: 'construct.blockinfo.unknown' };
const message = { rawtext: [{ text: '§a' }, { translate: block.type.id }]};
const states = block.getAllStates();
const message = { rawtext: [{ text: '§a' }]};
if (chinese_text[block.permutation.type.id] !== undefined) {
message.rawtext.push({ text: chinese_text[block.permutation.type.id] });
} else {
message.rawtext.push({ translate: block.permutation.getItemStack().localizationKey });
}
const states = block.permutation.getAllStates();
if (Object.keys(states).length > 0)
message.rawtext.push({ text: `\n§7${this.getFormattedStates(states)}` });
if (block.isWaterlogged)
@@ -54,7 +62,14 @@ class BlockInfo {
}
static getFormattedStates(states) {
return Object.entries(states).map(([key, value]) => `§7${key}: §3${value}`).join('\n');
return Object.entries(states)
.map(([stateName, stateValue]) => {
if (State_values[stateName] || Block_state[stateName]) {
return (`\n§7${Block_state[stateName]}`)
.replaceAll('%1', `§a${State_values[stateName][String(stateValue)]}§7`);
}
})
.join('');
}
static getSupplyMessage(player, block) {