1
0

refactor: 支持 Minecraft 1.21.1 版本

This commit is contained in:
2025-04-11 23:45:17 +08:00
parent fc6e38b1f1
commit f2c6cf78e8
142 changed files with 972571 additions and 75187 deletions
+136 -114
View File
@@ -1,119 +1,5 @@
// priority: 100
global.defaults = function (v, d) {
(typeof d === 'undefined') && (d = null);
return ((typeof v === 'undefined' || v === null) ? d : v);
};
global.setBlockProps = function (block, opts) {
if (!block) {
console.error(`${LOG_PREFIX} 设置方块属性失败:缺少“block”参数`);
return false;
}
if (!opts) {
opts = {};
}
const boxConfig = defaults(opts.boxConfig, null);
const boxType = defaults(opts.boxType, '');
const collision = defaults(opts.collision, true);
const displayName = defaults(opts.displayName, '');
const hardness = defaults(opts.hardness, 8);
const isSolid = defaults(opts.isSolid, true);
const lightLevel = defaults(opts.lightLevel, 0);
const material = defaults(opts.material, 'stone');
const modelPath = defaults(opts.modelPath, '');
const renderType = defaults(opts.renderType, 'solid');
const resistance = defaults(opts.resistance, 16);
if (boxConfig) {
block.box.apply(block, boxConfig);
} else if (boxType === 'full') {
block.box(0, 0, 0, 16, 16, 16, true);
} else if (boxType === 'half') {
block.box(0, 0, 0, 16, 8, 16, true);
}
if (!collision) {
block.noCollision();
}
if (displayName) {
block.displayName(displayName);
}
if (!isSolid) {
block.notSolid();
}
if (modelPath) {
block.model(modelPath);
}
block.hardness(hardness);
block.lightLevel(lightLevel);
block.material(material);
block.renderType(renderType);
block.resistance(resistance);
return true;
};
global.setHorizontalFacing = function (block, type, model) {
const prop = BlockProperties.HORIZONTAL_FACING;
// 设置模型旋转
block.blockstateJson = {
'variants': {
'facing=north': { model: model, y: 0 },
'facing=east': { model: model, y: 90 },
'facing=south': { model: model, y: 180 },
'facing=west': { model: model, y: 270 }
}
};
// 添加属性
block.property(prop);
// 处理默认状态
block.defaultState((ev) => {
ev.set(prop, 'north');
});
// 处理放置状态
switch (type) {
// 与玩家朝向相反
case 'revert':
block.placementState((ev) => {
const d = ev.getHorizontalDirection().getOpposite().toString();
ev.set(prop, d);
});
break;
// 与玩家朝向相同
case 'same':
block.placementState((ev) => {
const d = ev.getHorizontalDirection().toString();
ev.set(prop, d);
});
break;
// 其他
default:
console.error(`${LOG_PREFIX} 设置旋转属性失败:参数“type”错误`);
return false;
}
return true;
};
global.writeJSON = function (path, data) {
JsonIO.write(path, data);
};
global.COLORS = {
WHITE: {
CODE: 'white',
@@ -216,4 +102,140 @@ global.COLORS = {
global.JSON_ASSETS = [];
global.LOG_PREFIX = '[KubeJS]';
global.defaults = function (v, d) {
(typeof d === 'undefined') && (d = null);
return ((typeof v === 'undefined' || v === null) ? d : v);
};
global.setBlockProps = function (block, opts) {
if (!block) {
console.error(`${LOG_PREFIX} 设置方块属性失败:缺少“block”参数`);
return false;
}
if (!opts) {
opts = {};
}
const boxConfig = defaults(opts.boxConfig, null);
const boxType = defaults(opts.boxType, 'full');
const displayName = defaults(opts.displayName, '');
const hardness = defaults(opts.hardness, 8);
const hasCollision = defaults(opts.hasCollision, true);
const isSolid = defaults(opts.isSolid, true);
const lightLevel = defaults(opts.lightLevel, 0);
const mapColor = defaults(opts.mapColor, 'none');
const modelPath = defaults(opts.modelPath, null);
const renderType = defaults(opts.renderType, 'solid');
const resistance = defaults(opts.resistance, 16);
const soundType = defaults(opts.soundType, 'stone');
const textureAll = defaults(opts.textureAll, '');
if (boxType === 'custom') {
boxConfig && block.box.apply(block, boxConfig);
} else if (boxType === 'full') {
block.box(0, 0, 0, 16, 16, 16, true);
} else if (boxType === 'half') {
block.box(0, 0, 0, 16, 8, 16, true);
}
if (displayName) {
block.displayName(displayName);
}
if (!hasCollision) {
block.noCollision();
}
if (!isSolid) {
block.notSolid();
}
if (modelPath) {
// 生成模型 JSON 文件
JSON_ASSETS.push({
path: `${modelPath.blockNamespace}:models/block/${modelPath.blockName}`,
data: { parent: modelPath.filePath },
});
// // 注:不完全有效,无法使用,会导致方块显示为黑紫方块
// block.parentModel(modelPath.filePath);
}
if (textureAll) {
block.texture(textureAll);
// block.texture(Direction.UP, textureAll);
// block.texture(Direction.DOWN, textureAll);
// block.texture(Direction.NORTH, textureAll);
// block.texture(Direction.SOUTH, textureAll);
// block.texture(Direction.WEST, textureAll);
// block.texture(Direction.EAST, textureAll);
}
block.hardness(hardness);
block.lightLevel(lightLevel);
block.mapColor(mapColor);
block.soundType(soundType);
block.renderType(renderType);
block.resistance(resistance);
return true;
};
global.setHorizontalFacing = function (block, type, model) {
const prop = BlockProperties.HORIZONTAL_FACING;
// // 设置模型旋转
// block.blockstateJson = {
// 'variants': {
// 'facing=north': { model: model, y: 0 },
// 'facing=east': { model: model, y: 90 },
// 'facing=south': { model: model, y: 180 },
// 'facing=west': { model: model, y: 270 }
// }
// };
// 添加属性
block.property(prop);
// 处理默认状态
block.defaultState((ev) => {
ev.set(prop, 'north');
});
// 处理放置状态
switch (type) {
// 与玩家朝向相反
case 'revert':
block.placementState((ev) => {
const d = ev.getHorizontalDirection().getOpposite().toString();
ev.set(prop, d);
});
break;
// 与玩家朝向相同
case 'same':
block.placementState((ev) => {
const d = ev.getHorizontalDirection().toString();
ev.set(prop, d);
});
break;
// 其他
default:
console.error(`${LOG_PREFIX} 设置旋转属性失败:参数“type”错误`);
return false;
}
return true;
};
global.writeJSON = function (path, data) {
JsonIO.write(path, data);
};
console.info(`${global.LOG_PREFIX} 启动`);
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2015",
"lib": [
"ES5",
"ES2015"
],
"rootDir": ".",
"typeRoots": [
"../../.probe/startup/probe-types"
],
"baseUrl": "../../.probe/startup/probe-types",
"skipLibCheck": true
},
"files": [
"../constants.d.ts"
],
"include": [
"./**/*.js",
"./**/*.ts",
null
]
}
+183 -189
View File
@@ -2,7 +2,6 @@
const defaults = global.defaults;
const setBlockProps = global.setBlockProps;
const setHorizontalFacing = global.setHorizontalFacing;
const COLORS = global.COLORS;
const JSON_ASSETS = global.JSON_ASSETS;
@@ -17,6 +16,9 @@ const P_BLOCK = `${MOD_ID}:block`;
/** 方块模型文件基础长路径 */
const P_BLOCK_MODEL = `${MOD_ID}:models/block`;
/** 方块透明纹理文件路径 */
const P_BLOCK_TRANSPARENT = `${P_BLOCK}/common/transparent`;
/** 物品模型、纹理文件基础短路径*/
const P_ITEM = `${MOD_ID}:item`;
@@ -27,7 +29,7 @@ console.info(`${LOG_PREFIX} 处理 ${MOD_ID} 相关内容`);
/**
* @description 注册方块 - 砖块
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockBrick(event) {
@@ -43,15 +45,13 @@ function regBlockBrick(event) {
blocks.forEach((config) => {
const id = `${MOD_ID}:${config.name}`;
const block = event.create(id, 'basic');
const block = event.create(id);
setBlockProps(block, {
displayName: '砖块',
material: 'stone',
textureAll: `${P_BLOCK}/${config.texture}`,
});
block.textureAll(`${P_BLOCK}/${config.texture}`);
});
console.info(`${LOG_PREFIX} 注册方块 - 砖块 - 完成`);
@@ -60,13 +60,13 @@ function regBlockBrick(event) {
/**
* @description 注册方块 - 建筑和家具
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockBuildingAndFurniture(event) {
console.info(`${LOG_PREFIX} 注册方块 - 建筑和家具 - 开始`);
const blocks = [
const blockList = [
// 建筑方块
{
name: 'building_brick_a',
@@ -543,48 +543,52 @@ function regBlockBuildingAndFurniture(event) {
},
];
blocks.forEach((config) => {
blockList.forEach((config) => {
const id = `${MOD_ID}:${config.name}`;
const block = event.create(id, 'basic');
const box = config.box;
const label = config.label;
const mPath = config.model;
const tPath = config.texture;
const blockBox = config.box;
const blockLabel = config.label;
const blockName = config.name;
const blockId = `${MOD_ID}:${blockName}`;
const block = config.orientable ? event.create(blockId, 'cardinal') : event.create(blockId);
const modelPath0 = config.model;
const modelPath1 = modelPath0 ? `${P_BLOCK}/${modelPath0}` : '';
const texturePath0 = config.texture;
const texturePath1 = texturePath0 ? `${P_BLOCK}/${texturePath0}` : '';
// 设置基础属性
if (box) {
if (blockBox) {
setBlockProps(block, {
boxConfig: box,
boxConfig: blockBox,
boxType: 'custom',
displayName: label,
displayName: blockLabel,
isSolid: false,
material: 'stone',
modelPath: modelPath1 ? {
blockName: blockName,
blockNamespace: MOD_ID,
filePath: modelPath1,
} : null,
renderType: 'cutout',
textureAll: texturePath1,
});
} else {
setBlockProps(block, {
boxConfig: null,
boxType: 'full',
displayName: label,
displayName: blockLabel,
isSolid: true,
material: 'stone',
modelPath: modelPath1 ? {
blockName: blockName,
blockNamespace: MOD_ID,
filePath: modelPath1,
} : null,
renderType: 'solid',
textureAll: texturePath1,
});
}
// 设置模型或纹理文件路径
if (mPath) {
block.model(`${P_BLOCK}/${mPath}`);
} else if (tPath) {
block.textureAll(`${P_BLOCK}/${tPath}`);
}
// 设置方块旋转
if (config.orientable) {
setHorizontalFacing(block, 'revert', `${P_BLOCK}/${mPath}`);
}
});
console.info(`${LOG_PREFIX} 注册方块 - 建筑和家具 - 完成`);
@@ -593,7 +597,7 @@ function regBlockBuildingAndFurniture(event) {
/**
* @description 注册方块 - 纯色方块
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockColor(event) {
@@ -728,13 +732,13 @@ function regBlockColor(event) {
},
];
const tGrow = `${P_BLOCK}/common/color_grow`;
const tNormal = `${P_BLOCK}/common/color_normal`;
const textureGrow = `${P_BLOCK}/common/color_grow`;
const textureNormal = `${P_BLOCK}/common/color_normal`;
blocks.forEach((config) => {
const id = `${MOD_ID}:${config.name}`;
const block = event.create(id, 'basic');
const block = event.create(id);
const colorCfg = config.color;
const isGrow = config.grow;
@@ -742,10 +746,9 @@ function regBlockColor(event) {
displayName: config.label,
isSolid: false,
lightLevel: (isGrow ? 1 : 0),
material: 'stone',
textureAll: (isGrow ? textureGrow : textureNormal),
});
block.textureAll(isGrow ? tGrow : tNormal);
block.color(0, Color.rgba.apply(Color, colorCfg));
block.item((item) => {
item.color(0, Color.rgba.apply(Color, colorCfg));
@@ -759,44 +762,49 @@ function regBlockColor(event) {
/**
* @description 注册方块 - 灯(现代)
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockLampModern(event) {
console.info(`${LOG_PREFIX} 注册方块 - 现代灯 - 开始`);
/** 颜色 key 列表 */
const keys = Object.keys(COLORS);
/** 父模型路径 */
const parent = `${P_BLOCK}/lamp/modern`;
const parentModel = `${P_BLOCK}/lamp/modern`;
keys.forEach((key) => {
const color = COLORS[key];
const id = `${MOD_ID}:lamp_modern_${color.CODE}`;
const block = event.create(id, 'basic');
const blockName = `lamp_modern_${color.CODE}`;
const blockId = `${MOD_ID}:${blockName}`;
const block = event.create(blockId);
// 纹理文件路径前缀
// wheat_plus:block/lamp_modern/color_
const tBase = `${P_BLOCK}/lamp_modern/${color.CODE}`;
const textureBase = `${P_BLOCK}/lamp_modern/${color.CODE}`;
setBlockProps(block, {
boxType: 'full',
displayName: `现代${color.LABEL_CN}`,
isSolid: false,
lightLevel: 1,
material: 'glass',
renderType: 'translucent',
soundType: 'glass',
});
block.modelJson = {
parent: parent,
textures: {
glow: `${tBase}_glow`,
core: `${tBase}_core`,
particle: `${tBase}_core`
}
};
JSON_ASSETS.push({
path: `${P_BLOCK_MODEL}/${blockName}`,
data: {
parent: parentModel,
textures: {
glow: `${textureBase}_glow`,
core: `${textureBase}_core`,
particle: `${textureBase}_core`,
},
},
});
});
@@ -806,7 +814,7 @@ function regBlockLampModern(event) {
/**
* @description 注册方块 - 灯(简约)
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockLampSimple(event) {
@@ -839,7 +847,7 @@ function regBlockLampSimple(event) {
const blockName = config.name;
const blockId = `${MOD_ID}:${blockName}`;
const block = event.create(blockId, 'stone_button');
const block = event.create(blockId, 'button');
// 用于替换默认模型
const modelJSON = { parent: `${P_BLOCK}/${config.model}` };
@@ -847,26 +855,26 @@ function regBlockLampSimple(event) {
setBlockProps(block, {
displayName: config.label,
lightLevel: 0.8,
material: 'glass',
renderType: 'translucent',
soundType: 'glass',
});
// 按钮方块默认状态
JSON_ASSETS.push({
PATH: `${P_BLOCK_MODEL}/${blockName}`,
DATA: modelJSON,
path: `${P_BLOCK_MODEL}/${blockName}`,
data: modelJSON,
});
// 按钮方块按下状态
JSON_ASSETS.push({
PATH: `${P_BLOCK_MODEL}/${blockName}_pressed`,
DATA: modelJSON,
path: `${P_BLOCK_MODEL}/${blockName}_pressed`,
data: modelJSON,
});
// 按钮物品状态
JSON_ASSETS.push({
PATH: `${P_ITEM_MODEL}/${blockName}`,
DATA: modelJSON,
path: `${P_ITEM_MODEL}/${blockName}`,
data: modelJSON,
});
});
@@ -877,7 +885,7 @@ function regBlockLampSimple(event) {
/**
* @description 注册方块 - 矿车方块
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockMinecart(event) {
@@ -889,7 +897,7 @@ function regBlockMinecart(event) {
/** 纹理文件路径前缀 */
const texturePrefix = `${P_BLOCK}/minecart/`;
const blocks = [
const blockList = [
{ name: 'mtr_gz_gf_1', label: '广州地铁 - 广佛线' },
{ name: 'mtr_gz_gf_2', label: '广州地铁 - 广佛线' },
{ name: 'mtr_gz_l1_1', label: '广州地铁 - 一号线' },
@@ -942,39 +950,37 @@ function regBlockMinecart(event) {
{ name: 'cr_yz25z_wh', label: '中国铁路 - YZ25Z_WH' },
];
blocks.forEach((config) => {
blockList.forEach((config) => {
const blockName = config.name;
const blockId = `${MOD_ID}:minecart_${blockName}`;
const block = event.create(blockId, 'basic');
const block = event.create(blockId, 'cardinal');
const modelPathL = `${P_BLOCK_MODEL}/minecart/${blockName}`;
const modelPathS = `${P_BLOCK}/minecart/${blockName}`;
const modelJSON = {
parent: modelParent,
textures: {
main: `${texturePrefix}${blockName}`
}
};
const modelPathL = `${P_BLOCK_MODEL}/minecart_${blockName}`;
const modelPathS = `${P_BLOCK}/minecart_${blockName}`;
// 生成模型 JSON 文件
JSON_ASSETS.push({ PATH: modelPathL, DATA: modelJSON });
JSON_ASSETS.push({
path: modelPathL,
data: {
parent: modelParent,
textures: {
main: `${texturePrefix}${blockName}`,
},
},
});
// 设置基础属性
setBlockProps(block, {
boxConfig: [-3, 0, -6, 19, 16, 22],
boxConfig: [-3, 0, -6, 19, 16, 22, true],
boxType: 'custom',
collision: false,
displayName: config.label,
hasCollision: false,
isSolid: false,
material: 'metal',
modelPath: modelPathS,
renderType: 'cutout',
soundType: 'metal',
});
// 设置旋转属性
setHorizontalFacing(block, 'same', modelPathS);
});
console.info(`${LOG_PREFIX} 注册方块 - 矿车方块 - 完成`);
@@ -983,7 +989,7 @@ function regBlockMinecart(event) {
/**
* @description 注册方块 - 强化混凝土
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockReinforcedConcrete(event) {
@@ -995,22 +1001,21 @@ function regBlockReinforcedConcrete(event) {
const color = COLORS[key];
const id = `${MOD_ID}:reinforced_concrete_${color.CODE}`;
const block = event.create(id, 'basic');
const block = event.create(id);
const texture = `${P_BLOCK}/reinforced_concrete/${color.CODE}`;
setBlockProps(block, {
boxType: 'full',
displayName: `${color.LABEL_CN}强化混凝土`,
textureAll: texture,
});
block.textureAll(texture);
});
// // 覆盖默认语言(en_US
// JSON_ASSETS.push({
// PATH: 'minecraft:lang/en_us',
// DATA: {
// path: 'minecraft:lang/en_us',
// data: {
// 'block.minecraft.ancient_debris': 'White Reinforced Concrete',
// 'block.minecraft.raw_copper_block': 'Gray Reinforced Concrete',
// 'block.minecraft.raw_iron_block': 'Light Gray Reinforced Concrete',
@@ -1019,8 +1024,8 @@ function regBlockReinforcedConcrete(event) {
// // 覆盖默认语言(zh_CN
// JSON_ASSETS.push({
// PATH: 'minecraft:lang/zh_cn',
// DATA: {
// path: 'minecraft:lang/zh_cn',
// data: {
// 'block.minecraft.ancient_debris': '白色强化混凝土',
// 'block.minecraft.raw_copper_block': '灰色强化混凝土',
// 'block.minecraft.raw_iron_block': '淡灰色强化混凝土',
@@ -1033,7 +1038,7 @@ function regBlockReinforcedConcrete(event) {
/**
* @description 注册方块 - 路
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockRoad(event) {
@@ -1114,35 +1119,33 @@ function regBlockRoad(event) {
const label = (config.label || 'Unknown');
/** 纹理文件相对路径 */
const tPath = config.texturePath;
const texturePath = config.texturePath;
/** 是否存在侧边纹理 */
const tSide = config.hasSide;
const textureSide = config.hasSide;
// 完整,普通 / 直线
if (config.hasNormal) {
const blockId = `${blockName}_full`;
const fullId = `${MOD_ID}:${blockId}`;
const block = event.create(fullId, 'basic');
const block = event.create(fullId);
const suffix = (config.isBlank ? '' : ',直线');
const modelPathL = `${P_BLOCK_MODEL}/${blockId}`;
const modelPathS = `${P_BLOCK}/${blockId}`;
const modelJSON = {
parent: `${P_BLOCK}/road/base_full`,
textures: {
content: `${P_BLOCK}/${tPath}`,
side: tSide ? `${P_BLOCK}/${tPath}` : undefined
}
};
JSON_ASSETS.push({ PATH: modelPathL, DATA: modelJSON });
JSON_ASSETS.push({
path: `${P_BLOCK_MODEL}/${blockId}`,
data: {
parent: `${P_BLOCK}/road/base_full`,
textures: {
content: `${P_BLOCK}/${texturePath}`,
side: textureSide ? `${P_BLOCK}/${texturePath}` : P_BLOCK_TRANSPARENT,
},
},
});
setBlockProps(block, {
boxType: 'full',
displayName: `${label},完整${suffix}`,
modelPath: modelPathS,
renderType: 'cutout',
});
@@ -1153,30 +1156,26 @@ function regBlockRoad(event) {
const blockId = `${blockName}_full_slant`;
const fullId = `${MOD_ID}:${blockId}`;
const block = event.create(fullId, 'basic');
const block = event.create(fullId, 'cardinal');
const suffix = ',斜线';
const modelPathL = `${P_BLOCK_MODEL}/${blockId}`;
const modelPathS = `${P_BLOCK}/${blockId}`;
const modelJSON = {
parent: `${P_BLOCK}/road/base_full`,
textures: {
content: `${P_BLOCK}/${tPath}_slant`,
side: tSide ? `${P_BLOCK}/${tPath}` : undefined
}
};
JSON_ASSETS.push({ PATH: modelPathL, DATA: modelJSON });
JSON_ASSETS.push({
path: `${P_BLOCK_MODEL}/${blockId}`,
data: {
parent: `${P_BLOCK}/road/base_full`,
textures: {
content: `${P_BLOCK}/${texturePath}_slant`,
side: textureSide ? `${P_BLOCK}/${texturePath}` : P_BLOCK_TRANSPARENT,
},
},
});
setBlockProps(block, {
boxType: 'full',
displayName: `${label},完整${suffix}`,
modelPath: modelPathS,
renderType: 'cutout',
});
setHorizontalFacing(block, 'same', modelPathS);
}
// 一半,普通 / 直线
@@ -1184,25 +1183,23 @@ function regBlockRoad(event) {
const blockId = `${blockName}_half`;
const fullId = `${MOD_ID}:${blockId}`;
const block = event.create(fullId, 'basic');
const block = event.create(fullId);
const suffix = (config.isBlank ? '' : ',直线');
const modelPathL = `${P_BLOCK_MODEL}/${blockId}`;
const modelPathS = `${P_BLOCK}/${blockId}`;
const modelJSON = {
parent: `${P_BLOCK}/road/base_half`,
textures: {
content: `${P_BLOCK}/${tPath}`,
side: tSide ? `${P_BLOCK}/${tPath}` : undefined
}
};
JSON_ASSETS.push({ PATH: modelPathL, DATA: modelJSON });
JSON_ASSETS.push({
path: `${P_BLOCK_MODEL}/${blockId}`,
data: {
parent: `${P_BLOCK}/road/base_half`,
textures: {
content: `${P_BLOCK}/${texturePath}`,
side: textureSide ? `${P_BLOCK}/${texturePath}` : P_BLOCK_TRANSPARENT,
},
},
});
setBlockProps(block, {
boxType: 'half',
displayName: `${label},一半${suffix}`,
modelPath: modelPathS,
renderType: 'cutout',
});
@@ -1213,30 +1210,26 @@ function regBlockRoad(event) {
const blockId = `${blockName}_half_slant`;
const fullId = `${MOD_ID}:${blockId}`;
const block = event.create(fullId, 'basic');
const block = event.create(fullId, 'cardinal');
const suffix = ',斜线';
const modelPathL = `${P_BLOCK_MODEL}/${blockId}`;
const modelPathS = `${P_BLOCK}/${blockId}`;
const modelJSON = {
parent: `${P_BLOCK}/road/base_half`,
textures: {
content: `${P_BLOCK}/${tPath}_slant`,
side: tSide ? `${P_BLOCK}/${tPath}` : undefined
}
};
JSON_ASSETS.push({ PATH: modelPathL, DATA: modelJSON });
JSON_ASSETS.push({
path: `${P_BLOCK_MODEL}/${blockId}`,
data: {
parent: `${P_BLOCK}/road/base_half`,
textures: {
content: `${P_BLOCK}/${texturePath}_slant`,
side: textureSide ? `${P_BLOCK}/${texturePath}` : P_BLOCK_TRANSPARENT,
},
},
});
setBlockProps(block, {
boxType: 'half',
displayName: `${label},一半${suffix}`,
modelPath: modelPathS,
renderType: 'cutout',
});
setHorizontalFacing(block, 'same', modelPathS);
}
});
@@ -1247,7 +1240,7 @@ function regBlockRoad(event) {
/**
* @description 注册方块 - 其他 - 基础
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockOtherBasic(event) {
@@ -1306,46 +1299,50 @@ function regBlockOtherBasic(event) {
blocks.forEach((config) => {
const id = `${MOD_ID}:${config.name}`;
const block = event.create(id, 'basic');
const box = config.box;
const label = config.label;
const mPath = config.model;
const tPath = config.texture;
const blockBox = config.box;
const blockLabel = config.label;
const blockName = config.name;
const blockId = `${MOD_ID}:${blockName}`;
const block = config.orientable ? event.create(blockId, 'cardinal') : event.create(blockId);
const modelPath0 = config.model;
const modelPath1 = modelPath0 ? `${P_BLOCK}/${modelPath0}` : '';
const texturePath0 = config.texture;
const texturePath1 = texturePath0 ? `${P_BLOCK}/${texturePath0}` : '';
// 设置基础属性
if (box) {
if (blockBox) {
setBlockProps(block, {
boxConfig: box,
boxConfig: blockBox,
boxType: 'custom',
displayName: label,
displayName: blockLabel,
isSolid: false,
material: 'stone',
modelPath: modelPath1 ? {
blockName: blockName,
blockNamespace: MOD_ID,
filePath: modelPath1,
} : null,
renderType: 'cutout',
textureAll: texturePath1,
});
} else {
setBlockProps(block, {
boxConfig: null,
boxType: 'full',
displayName: label,
displayName: blockLabel,
isSolid: true,
material: 'stone',
modelPath: modelPath1 ? {
blockName: blockName,
blockNamespace: MOD_ID,
filePath: modelPath1,
} : null,
renderType: 'solid',
textureAll: texturePath1,
});
}
// 设置模型或纹理文件路径
if (mPath) {
block.model(`${P_BLOCK}/${mPath}`);
} else if (tPath) {
block.textureAll(`${P_BLOCK}/${tPath}`);
}
// 设置方块旋转
if (config.orientable) {
setHorizontalFacing(block, 'revert', `${P_BLOCK}/${mPath}`);
}
});
console.info(`${LOG_PREFIX} 注册方块 - 其他 - 基础 - 完成`);
@@ -1354,7 +1351,7 @@ function regBlockOtherBasic(event) {
/**
* @description 注册方块 - 其他 - 特殊
* @param {Registry.Block} event
* @param {_RegistryBlock} event
*/
function regBlockOtherShaped(event) {
@@ -1389,13 +1386,10 @@ function regBlockOtherShaped(event) {
// 设置基础属性
setBlockProps(block, {
displayName: config.label,
material: 'stone',
renderType: 'cutout_mipped',
textureAll: config.texture,
});
// 设置方块纹理
block.textureAll(config.texture);
});
console.info(`${LOG_PREFIX} 注册方块 - 其他 - 特殊 - 完成`);
@@ -1403,16 +1397,16 @@ function regBlockOtherShaped(event) {
}
// 注册方块
onEvent('block.registry', regBlockBrick);
onEvent('block.registry', regBlockBuildingAndFurniture);
onEvent('block.registry', regBlockColor);
onEvent('block.registry', regBlockLampModern);
onEvent('block.registry', regBlockLampSimple);
onEvent('block.registry', regBlockMinecart);
onEvent('block.registry', regBlockRoad);
onEvent('block.registry', regBlockReinforcedConcrete);
onEvent('block.registry', regBlockOtherBasic);
onEvent('block.registry', regBlockOtherShaped);
StartupEvents.registry('block', regBlockBrick);
StartupEvents.registry('block', regBlockBuildingAndFurniture);
StartupEvents.registry('block', regBlockColor);
StartupEvents.registry('block', regBlockLampModern);
StartupEvents.registry('block', regBlockLampSimple);
StartupEvents.registry('block', regBlockMinecart);
StartupEvents.registry('block', regBlockRoad);
StartupEvents.registry('block', regBlockReinforcedConcrete);
StartupEvents.registry('block', regBlockOtherBasic);
StartupEvents.registry('block', regBlockOtherShaped);
// 注册物品
// onEvent('item.registry', function (event) {