feat: 支持创建旋转方块
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
- [BlockBuilder.java](https://github.com/KubeJS-Mods/KubeJS/blob/1.18/main/common/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java)
|
- [BlockBuilder.java](https://github.com/KubeJS-Mods/KubeJS/blob/1.18/main/common/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java)
|
||||||
- [BasicBlockJS.java](https://github.com/KubeJS-Mods/KubeJS/blob/1.18/main/common/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java)
|
- [BasicBlockJS.java](https://github.com/KubeJS-Mods/KubeJS/blob/1.18/main/common/src/main/java/dev/latvian/mods/kubejs/block/custom/BasicBlockJS.java)
|
||||||
- [WoodenButtonBlockBuilder.java](https://github.com/KubeJS-Mods/KubeJS/blob/1.18/main/common/src/main/java/dev/latvian/mods/kubejs/block/custom/WoodenButtonBlockBuilder.java)
|
- [WoodenButtonBlockBuilder.java](https://github.com/KubeJS-Mods/KubeJS/blob/1.18/main/common/src/main/java/dev/latvian/mods/kubejs/block/custom/WoodenButtonBlockBuilder.java)
|
||||||
|
- [Cardinally Orientable Blocks and Shuffle Asset Generation](https://github.com/KubeJS-Mods/KubeJS/pull/459)
|
||||||
|
- [Basic BlockState Support and Misc Delegate Methods](https://github.com/KubeJS-Mods/KubeJS/pull/464)
|
||||||
|
|
||||||
### 颜色列表
|
### 颜色列表
|
||||||
|
|
||||||
|
|||||||
Vendored
+12
@@ -62,6 +62,18 @@ declare const global: {
|
|||||||
*/
|
*/
|
||||||
setBlockProps(block: B_Builder, opts: SetBlockPropsOpts): boolean;
|
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 文件
|
* @desc 写入 JSON 文件
|
||||||
* @param path 文件路径,相对于 `.minecraft`
|
* @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) {
|
global.writeJSON = function (path, data) {
|
||||||
JsonIO.write(path, data);
|
JsonIO.write(path, data);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const defaults = global.defaults;
|
const defaults = global.defaults;
|
||||||
const setBlockProps = global.setBlockProps;
|
const setBlockProps = global.setBlockProps;
|
||||||
|
const setHorizontalFacing = global.setHorizontalFacing;
|
||||||
|
|
||||||
const COLORS = global.COLORS;
|
const COLORS = global.COLORS;
|
||||||
const JSON_ASSETS = global.JSON_ASSETS;
|
const JSON_ASSETS = global.JSON_ASSETS;
|
||||||
@@ -454,18 +455,21 @@ onEvent('block.registry', (event) => {
|
|||||||
box: [5, 0, 5, 11, 16, 11, true],
|
box: [5, 0, 5, 11, 16, 11, true],
|
||||||
label: '隔离桩',
|
label: '隔离桩',
|
||||||
model: 'common/isolation_pile_a',
|
model: 'common/isolation_pile_a',
|
||||||
|
orientable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'statue_player_alex',
|
name: 'statue_player_alex',
|
||||||
box: [4, 0, 6, 12, 31, 10, true],
|
box: [4, 0, 6, 12, 31, 10, true],
|
||||||
label: '模型(Alex)',
|
label: '模型(Alex)',
|
||||||
model: 'statue/player_alex',
|
model: 'statue/player_alex',
|
||||||
|
orientable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'statue_player_steve',
|
name: 'statue_player_steve',
|
||||||
box: [4, 0, 6, 12, 31, 10, true],
|
box: [4, 0, 6, 12, 31, 10, true],
|
||||||
label: '模型(Steve)',
|
label: '模型(Steve)',
|
||||||
model: 'statue/player_steve',
|
model: 'statue/player_steve',
|
||||||
|
orientable: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -473,6 +477,7 @@ onEvent('block.registry', (event) => {
|
|||||||
|
|
||||||
const id = `${MOD_ID}:${config.name}`;
|
const id = `${MOD_ID}:${config.name}`;
|
||||||
const block = event.create(id, 'basic');
|
const block = event.create(id, 'basic');
|
||||||
|
const model = `${P_BLOCK}/${config.model}`;
|
||||||
|
|
||||||
setBlockProps(block, {
|
setBlockProps(block, {
|
||||||
boxConfig: config.box,
|
boxConfig: config.box,
|
||||||
@@ -480,10 +485,14 @@ onEvent('block.registry', (event) => {
|
|||||||
displayName: config.label,
|
displayName: config.label,
|
||||||
isSolid: false,
|
isSolid: false,
|
||||||
material: 'stone',
|
material: 'stone',
|
||||||
modelPath: `${P_BLOCK}/${config.model}`,
|
modelPath: model,
|
||||||
renderType: 'cutout',
|
renderType: 'cutout',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (config.orientable) {
|
||||||
|
setHorizontalFacing(block, 'revert', model);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.info(`${LOG_PREFIX} 注册方块 - 其它 - 完成`);
|
console.info(`${LOG_PREFIX} 注册方块 - 其它 - 完成`);
|
||||||
@@ -495,3 +504,9 @@ onEvent('block.registry', (event) => {
|
|||||||
// console.info(`${LOG_PREFIX} 注册物品 - 开始`);
|
// console.info(`${LOG_PREFIX} 注册物品 - 开始`);
|
||||||
// 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