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