1
0

feat: 斜线路方块支持旋转(不借助连接纹理)

This commit is contained in:
2022-11-13 19:26:24 +08:00
parent 1d671bbd13
commit f9136d583f
5 changed files with 75 additions and 52 deletions

View File

@@ -30,8 +30,7 @@ onEvent('block.registry', (event) => {
console.info(`${LOG_PREFIX} 注册方块 - 路 - 开始`); console.info(`${LOG_PREFIX} 注册方块 - 路 - 开始`);
/** 普通路方块 */ const blockList = [
const roadBlocksNormal = [
{ {
name: 'road_blank', name: 'road_blank',
label: '路 - 空白', label: '路 - 空白',
@@ -97,12 +96,12 @@ onEvent('block.registry', (event) => {
}, },
]; ];
roadBlocksNormal.forEach((config) => { blockList.forEach((config) => {
/** 方块 ID包含模组 ID */ /** 方块名称 */
const id = `${MOD_ID}:${config.name}`; const blockName = config.name;
/** 方块名称文本 */ /** 方块文本 */
const label = (config.label || 'Unknown'); const label = (config.label || 'Unknown');
/** 纹理文件相对路径 */ /** 纹理文件相对路径 */
@@ -111,99 +110,123 @@ onEvent('block.registry', (event) => {
/** 是否存在侧边纹理 */ /** 是否存在侧边纹理 */
const tSide = config.hasSide; const tSide = config.hasSide;
// 完整,直线 // 完整,普通 / 直线
if (config.hasNormal) { if (config.hasNormal) {
const block = event.create(`${id}_full`, 'basic'); const blockId = `${blockName}_full`;
const fullId = `${MOD_ID}:${blockId}`;
const block = event.create(fullId, 'basic');
const suffix = (config.isBlank ? '' : ',直线'); 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 });
setBlockProps(block, { setBlockProps(block, {
boxType: 'full', boxType: 'full',
displayName: `${label},完整${suffix}`, displayName: `${label},完整${suffix}`,
modelPath: modelPathS,
renderType: 'cutout', renderType: 'cutout',
}); });
if (tPath) {
block.modelJson = {
parent: `${P_BLOCK}/road/base_full`,
textures: {
content: `${P_BLOCK}/${tPath}`,
side: tSide ? `${P_BLOCK}/${tPath}` : undefined
}
};
}
} }
// 完整,斜线 // 完整,斜线
if (config.hasSlant) { if (config.hasSlant) {
const block = event.create(`${id}_full_slant`, 'basic'); const blockId = `${blockName}_full_slant`;
const suffix = (config.isBlank ? '' : ',斜线'); const fullId = `${MOD_ID}:${blockId}`;
const block = event.create(fullId, 'basic');
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 });
setBlockProps(block, { setBlockProps(block, {
boxType: 'full', boxType: 'full',
displayName: `${label},完整${suffix}`, displayName: `${label},完整${suffix}`,
modelPath: modelPathS,
renderType: 'cutout', renderType: 'cutout',
}); });
if (tPath) { setHorizontalFacing(block, 'same', modelPathS);
block.modelJson = {
parent: `${P_BLOCK}/road/base_full`,
textures: {
content: `${P_BLOCK}/${tPath}_slant`,
side: tSide ? `${P_BLOCK}/${tPath}` : undefined
}
};
}
} }
// 一半,直线 // 一半,普通 / 直线
if (config.hasNormal) { if (config.hasNormal) {
const block = event.create(`${id}_half`, 'basic'); const blockId = `${blockName}_half`;
const fullId = `${MOD_ID}:${blockId}`;
const block = event.create(fullId, 'basic');
const suffix = (config.isBlank ? '' : ',直线'); 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 });
setBlockProps(block, { setBlockProps(block, {
boxType: 'half', boxType: 'half',
displayName: `${label},一半${suffix}`, displayName: `${label},一半${suffix}`,
modelPath: modelPathS,
renderType: 'cutout', renderType: 'cutout',
}); });
if (tPath) {
block.modelJson = {
parent: `${P_BLOCK}/road/base_half`,
textures: {
content: `${P_BLOCK}/${tPath}`,
side: tSide ? `${P_BLOCK}/${tPath}` : undefined
}
};
}
} }
// 一半,斜线 // 一半,斜线
if (config.hasSlant) { if (config.hasSlant) {
const block = event.create(`${id}_half_slant`, 'basic'); const blockId = `${blockName}_half_slant`;
const suffix = (config.isBlank ? '' : ',斜线'); const fullId = `${MOD_ID}:${blockId}`;
const block = event.create(fullId, 'basic');
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 });
setBlockProps(block, { setBlockProps(block, {
boxType: 'half', boxType: 'half',
displayName: `${label},一半${suffix}`, displayName: `${label},一半${suffix}`,
modelPath: modelPathS,
renderType: 'cutout', renderType: 'cutout',
}); });
if (tPath) { setHorizontalFacing(block, 'same', modelPathS);
block.modelJson = {
parent: `${P_BLOCK}/road/base_half`,
textures: {
content: `${P_BLOCK}/${tPath}_slant`,
side: tSide ? `${P_BLOCK}/${tPath}` : undefined
}
};
}
} }