refactor: 优化方块属性设置代码
This commit is contained in:
@@ -14,7 +14,7 @@ const LOG_PREFIX = global.LOG_PREFIX;
|
||||
/**
|
||||
* @desc 方块碰撞箱类型
|
||||
* @typedef B.BoxType
|
||||
* @type {'full'|'half'}
|
||||
* @type {'custom'|'full'|'half'}
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -50,17 +50,20 @@ const P_ITEM_MODEL = `${MOD_ID}:models/item`;
|
||||
* @description 设置方块基础属性
|
||||
* @param {B.Builder} block
|
||||
* @param {object} options
|
||||
* @param {B.BoxType} options.boxType 碰撞箱类型
|
||||
* @param {boolean} options.collision 开启碰撞箱
|
||||
* @param {string} options.displayName
|
||||
* @param {number} options.hardness
|
||||
* @param {boolean} options.isFull 是否完整方块
|
||||
* @param {boolean} options.isOpaque 是否不透明
|
||||
* @param {number} options.lightLevel 范围 0 ~ 1
|
||||
* @param {B.Material} options.material
|
||||
* @param {number[]} options.boxConfig 碰撞箱配置(自定义)
|
||||
* @param {B.BoxType} options.boxType 碰撞箱类型(内置)
|
||||
* @param {boolean} options.collision 开启碰撞箱,默认:true
|
||||
* @param {string} options.displayName 方块显示名称
|
||||
* @param {number} options.hardness 默认:8
|
||||
* @param {boolean} options.isSolid 是否为完整方块,默认:true
|
||||
* @param {number} options.lightLevel 范围:0 ~ 1
|
||||
* @param {B.Material} options.material 默认:stone
|
||||
* @param {string} options.modelPath 模型文件路径
|
||||
* @param {B.RenderType} options.renderType
|
||||
* @param {number} options.resistance
|
||||
* @param {B.RenderType} options.renderType 默认:solid
|
||||
* @param {number} options.resistance 默认:16
|
||||
* @param {boolean} options.isFull fullBlock(未使用)
|
||||
* @param {boolean} options.isOpaque opaque(未使用)
|
||||
* @param {boolean} options.transparent transparent(未使用)
|
||||
*/
|
||||
const setBlockProps = function (block, options) {
|
||||
|
||||
@@ -73,23 +76,21 @@ const setBlockProps = function (block, options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
const boxConfig = defaults(options.boxConfig, null);
|
||||
const boxType = defaults(options.boxType, '');
|
||||
const collision = defaults(options.collision, true);
|
||||
const displayName = defaults(options.displayName, '');
|
||||
const hardness = defaults(options.hardness, 8);
|
||||
const isFull = defaults(options.isFull, true);
|
||||
const isOpaque = defaults(options.isOpaque, true);
|
||||
const isSolid = defaults(options.isSolid, true);
|
||||
const lightLevel = defaults(options.lightLevel, 0);
|
||||
const material = defaults(options.material, 'stone');
|
||||
const modelPath = defaults(options.modelPath, '');
|
||||
const renderType = defaults(options.renderType, 'solid');
|
||||
const resistance = defaults(options.resistance, 16);
|
||||
|
||||
if (displayName) {
|
||||
block.displayName(displayName);
|
||||
}
|
||||
|
||||
if (boxType === 'full') {
|
||||
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);
|
||||
@@ -99,14 +100,20 @@ const setBlockProps = function (block, options) {
|
||||
block.noCollision();
|
||||
}
|
||||
|
||||
if (displayName) {
|
||||
block.displayName(displayName);
|
||||
}
|
||||
|
||||
if (!isSolid) {
|
||||
block.notSolid();
|
||||
}
|
||||
|
||||
if (modelPath) {
|
||||
block.model(modelPath);
|
||||
}
|
||||
|
||||
block.fullBlock(isFull);
|
||||
block.hardness(hardness);
|
||||
block.lightLevel(lightLevel);
|
||||
block.opaque(isOpaque);
|
||||
block.material(material);
|
||||
block.renderType(renderType);
|
||||
block.resistance(resistance);
|
||||
@@ -324,10 +331,7 @@ onEvent('block.registry', (event) => {
|
||||
displayName: `${color.LABEL_CN}强化混凝土`,
|
||||
});
|
||||
|
||||
block.modelJson = {
|
||||
parent: 'minecraft:block/cube_all',
|
||||
textures: { all: texture },
|
||||
};
|
||||
block.textureAll(texture);
|
||||
|
||||
});
|
||||
|
||||
@@ -378,6 +382,7 @@ onEvent('block.registry', (event) => {
|
||||
setBlockProps(block, {
|
||||
boxType: 'full',
|
||||
displayName: `现代${color.LABEL_CN}灯`,
|
||||
isSolid: false,
|
||||
lightLevel: 1,
|
||||
material: 'glass',
|
||||
renderType: 'translucent',
|
||||
|
||||
Reference in New Issue
Block a user