feat: 支持创建旋转方块
This commit is contained in:
12
kubejs/probe/user/constants.d.ts
vendored
12
kubejs/probe/user/constants.d.ts
vendored
@@ -62,6 +62,18 @@ declare const global: {
|
||||
*/
|
||||
setBlockProps(block: B_Builder, opts: SetBlockPropsOpts): boolean;
|
||||
|
||||
/**
|
||||
* @desc 设置方块水平旋转属性
|
||||
* @param block 方块
|
||||
* @param type 旋转类型
|
||||
* @param model 模型路径
|
||||
*/
|
||||
setHorizontalFacing(
|
||||
block: B_Builder,
|
||||
type: 'revert' | 'same',
|
||||
model: string
|
||||
): boolean;
|
||||
|
||||
/**
|
||||
* @desc 写入 JSON 文件
|
||||
* @param path 文件路径,相对于 `.minecraft`
|
||||
|
||||
@@ -62,6 +62,54 @@ global.setBlockProps = function (block, opts) {
|
||||
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const defaults = global.defaults;
|
||||
const setBlockProps = global.setBlockProps;
|
||||
const setHorizontalFacing = global.setHorizontalFacing;
|
||||
|
||||
const COLORS = global.COLORS;
|
||||
const JSON_ASSETS = global.JSON_ASSETS;
|
||||
@@ -454,18 +455,21 @@ onEvent('block.registry', (event) => {
|
||||
box: [5, 0, 5, 11, 16, 11, true],
|
||||
label: '隔离桩',
|
||||
model: 'common/isolation_pile_a',
|
||||
orientable: false,
|
||||
},
|
||||
{
|
||||
name: 'statue_player_alex',
|
||||
box: [4, 0, 6, 12, 31, 10, true],
|
||||
label: '模型(Alex)',
|
||||
model: 'statue/player_alex',
|
||||
orientable: true,
|
||||
},
|
||||
{
|
||||
name: 'statue_player_steve',
|
||||
box: [4, 0, 6, 12, 31, 10, true],
|
||||
label: '模型(Steve)',
|
||||
model: 'statue/player_steve',
|
||||
orientable: true,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -473,6 +477,7 @@ onEvent('block.registry', (event) => {
|
||||
|
||||
const id = `${MOD_ID}:${config.name}`;
|
||||
const block = event.create(id, 'basic');
|
||||
const model = `${P_BLOCK}/${config.model}`;
|
||||
|
||||
setBlockProps(block, {
|
||||
boxConfig: config.box,
|
||||
@@ -480,10 +485,14 @@ onEvent('block.registry', (event) => {
|
||||
displayName: config.label,
|
||||
isSolid: false,
|
||||
material: 'stone',
|
||||
modelPath: `${P_BLOCK}/${config.model}`,
|
||||
modelPath: model,
|
||||
renderType: 'cutout',
|
||||
});
|
||||
|
||||
if (config.orientable) {
|
||||
setHorizontalFacing(block, 'revert', model);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
console.info(`${LOG_PREFIX} 注册方块 - 其它 - 完成`);
|
||||
@@ -495,3 +504,9 @@ onEvent('block.registry', (event) => {
|
||||
// console.info(`${LOG_PREFIX} 注册物品 - 开始`);
|
||||
// console.info(`${LOG_PREFIX} 注册物品 - 完成`);
|
||||
// });
|
||||
|
||||
// 注册声音
|
||||
// onEvent('sound.registry', (event) => {
|
||||
// console.info(`${LOG_PREFIX} 注册声音 - 开始`);
|
||||
// console.info(`${LOG_PREFIX} 注册声音 - 完成`);
|
||||
// });
|
||||
|
||||
Reference in New Issue
Block a user