hytale-custom-blocks

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Creating Custom Hytale Blocks

为Hytale创建自定义方块

Complete guide for defining custom block types with all available properties and configurations.
本指南完整介绍了如何定义带有所有可用属性和配置的自定义方块类型。

When to use this skill

何时使用本技能

Use this skill when:
  • Creating new block types
  • Configuring block rendering (textures, models)
  • Setting up block physics (support, bouncy, climbable)
  • Making blocks farmable with growth stages
  • Adding crafting benches
  • Defining block interactions
  • Setting up block sounds and particles
  • Managing block states
在以下场景使用本技能:
  • 创建新的方块类型
  • 配置方块渲染(纹理、模型)
  • 设置方块物理特性(支撑、弹性、可攀爬)
  • 制作带有生长阶段的可种植方块
  • 添加工作台
  • 定义方块交互
  • 设置方块音效与粒子效果
  • 管理方块状态

Block Asset Structure

方块资源结构

Blocks are defined as JSON assets in your plugin's asset pack:
my-plugin/
└── assets/
    └── Server/
        └── Content/
            └── BlockTypes/
                ├── my_custom_block.blocktype
                ├── my_crop.blocktype
                └── my_bench.blocktype
方块在插件资源包中以JSON资源的形式定义:
my-plugin/
└── assets/
    └── Server/
        └── Content/
            └── BlockTypes/
                ├── my_custom_block.blocktype
                ├── my_crop.blocktype
                └── my_bench.blocktype

Basic Block Definition

基础方块定义

File:
my_custom_block.blocktype
json
{
  "DisplayName": {
    "en-US": "Custom Block"
  },
  "Description": {
    "en-US": "A custom block with special properties"
  },
  "DrawType": "Cube",
  "Texture": "MyPlugin/Textures/custom_block",
  "Material": "Stone",
  "Tags": {
    "Category": ["Building", "Decorative"]
  }
}
文件
my_custom_block.blocktype
json
{
  "DisplayName": {
    "en-US": "Custom Block"
  },
  "Description": {
    "en-US": "A custom block with special properties"
  },
  "DrawType": "Cube",
  "Texture": "MyPlugin/Textures/custom_block",
  "Material": "Stone",
  "Tags": {
    "Category": ["Building", "Decorative"]
  }
}

Block Properties Reference

方块属性参考

Core Properties

核心属性

PropertyTypeDescription
DisplayName
LocalizedStringLocalized display name
Description
LocalizedStringLocalized description
Parent
StringInherit from another block type
Tags
ObjectCategory tags for filtering
属性类型说明
DisplayName
LocalizedString多语言显示名称
Description
LocalizedString多语言描述
Parent
String继承自其他方块类型
Tags
Object用于筛选的分类标签

Rendering Properties

渲染属性

PropertyTypeDefaultDescription
DrawType
Enum
Cube
Cube
,
Model
,
Empty
Texture
String-Texture path for cube rendering
TextureTop
String-Top face texture
TextureSide
String-Side faces texture
TextureBottom
String-Bottom face texture
Model
String-Model asset for DrawType=Model
Shader
String-Custom shader
Opacity
Float1.0Block opacity (0-1)
AlphaBlend
BooleanfalseEnable alpha blending
RandomRotation
BooleanfalseRandom Y rotation on place
VariantRotation
Enum-Rotation variant mode
FlipType
Enum-Random flipping mode
RotationOffset
Float0Rotation offset in degrees
属性类型默认值说明
DrawType
Enum
Cube
可选值:
Cube
Model
Empty
Texture
String-立方体渲染的纹理路径
TextureTop
String-顶面纹理
TextureSide
String-侧面纹理
TextureBottom
String-底面纹理
Model
String-当DrawType=Model时使用的模型资源
Shader
String-自定义着色器
Opacity
Float1.0方块透明度(0-1)
AlphaBlend
Booleanfalse是否启用透明度混合
RandomRotation
Booleanfalse放置时随机Y轴旋转
VariantRotation
Enum-旋转变体模式
FlipType
Enum-随机翻转模式
RotationOffset
Float0旋转偏移角度(度)

Physics Properties

物理属性

PropertyTypeDefaultDescription
Material
String-Physics material type
IsSolid
BooleantrueCollision enabled
IsReplaceable
BooleanfalseCan be replaced when placing
HasGravity
BooleanfalseFalls like sand
BlockFaceSupport
Object-Support provided to neighbors
RequiredBlockFaceSupport
Object-Support needed from neighbors
属性类型默认值说明
Material
String-物理材质类型
IsSolid
Booleantrue是否启用碰撞
IsReplaceable
Booleanfalse放置时是否可被替换
HasGravity
Booleanfalse是否像沙子一样下落
BlockFaceSupport
Object-向相邻方块提供的支撑
RequiredBlockFaceSupport
Object-自身需要从相邻方块获得的支撑

Movement Properties

移动属性

PropertyTypeDefaultDescription
Climbable
BooleanfalseCan be climbed (ladders)
Bouncy
Float0Bounce factor (0-1)
Drag
Float0Movement drag
Friction
Float1Surface friction
SpeedMultiplier
Float1Walk speed multiplier
属性类型默认值说明
Climbable
Booleanfalse是否可攀爬(如梯子)
Bouncy
Float0弹跳系数(0-1)
Drag
Float0移动阻力
Friction
Float1表面摩擦力
SpeedMultiplier
Float1行走速度倍率

Behavior Properties

行为属性

PropertyTypeDefaultDescription
IsUsable
BooleanfalseRight-click interaction
IsStackable
BooleantrueCan be placed adjacent
ItemId
String-Item dropped when broken
LightLevel
Integer0Light emission (0-15)
LightColor
ColorwhiteLight color
Flammable
BooleanfalseCan catch fire
FlammableSpread
Integer0Fire spread rate
属性类型默认值说明
IsUsable
Booleanfalse是否支持右键交互
IsStackable
Booleantrue是否可相邻放置
ItemId
String-破坏后掉落的物品ID
LightLevel
Integer0发光等级(0-15)
LightColor
Colorwhite发光颜色
Flammable
Booleanfalse是否可燃
FlammableSpread
Integer0火焰传播速度

Draw Types

渲染类型

Cube (Default)

Cube(默认)

Standard voxel block with 6-sided textures:
json
{
  "DrawType": "Cube",
  "Texture": "MyPlugin/Textures/stone",
  "TextureTop": "MyPlugin/Textures/stone_top"
}
标准体素方块,支持6面纹理:
json
{
  "DrawType": "Cube",
  "Texture": "MyPlugin/Textures/stone",
  "TextureTop": "MyPlugin/Textures/stone_top"
}

Model

Model

Custom 3D model:
json
{
  "DrawType": "Model",
  "Model": "MyPlugin/Models/custom_model",
  "BoundingBox": "MyPlugin/BoundingBoxes/custom_box"
}
自定义3D模型:
json
{
  "DrawType": "Model",
  "Model": "MyPlugin/Models/custom_model",
  "BoundingBox": "MyPlugin/BoundingBoxes/custom_box"
}

Empty

Empty

Invisible block (air-like, for logic):
json
{
  "DrawType": "Empty",
  "IsSolid": false
}
不可见方块(类似空气,用于逻辑实现):
json
{
  "DrawType": "Empty",
  "IsSolid": false
}

Block Physics System

方块物理系统

Block Face Support

方块面支撑

Define which faces provide support:
json
{
  "BlockFaceSupport": {
    "Top": {
      "Type": "Full",
      "SupportStrength": 100
    },
    "Bottom": {
      "Type": "Full",
      "SupportStrength": 100
    },
    "North": { "Type": "Full" },
    "South": { "Type": "Full" },
    "East": { "Type": "Full" },
    "West": { "Type": "Full" }
  }
}
Support Types:
Full
,
Partial
,
None
,
Center
定义方块各面可提供的支撑:
json
{
  "BlockFaceSupport": {
    "Top": {
      "Type": "Full",
      "SupportStrength": 100
    },
    "Bottom": {
      "Type": "Full",
      "SupportStrength": 100
    },
    "North": { "Type": "Full" },
    "South": { "Type": "Full" },
    "East": { "Type": "Full" },
    "West": { "Type": "Full" }
  }
}
支撑类型
Full
Partial
None
Center

Required Support

所需支撑

Define what support the block needs:
json
{
  "RequiredBlockFaceSupport": {
    "Bottom": [
      {
        "Type": "Full",
        "Match": "REQUIRED"
      }
    ]
  }
}
Match Types:
  • REQUIRED
    - Must have this support
  • IGNORED
    - Don't care
  • DISALLOWED
    - Must NOT have this support
定义方块自身需要的支撑:
json
{
  "RequiredBlockFaceSupport": {
    "Bottom": [
      {
        "Type": "Full",
        "Match": "REQUIRED"
      }
    ]
  }
}
匹配类型:
  • REQUIRED
    - 必须具备该支撑
  • IGNORED
    - 无要求
  • DISALLOWED
    - 必须不具备该支撑

Gravity Blocks

受重力影响的方块

json
{
  "HasGravity": true,
  "GravityDelay": 5,
  "PhysicsDrop": {
    "GatherType": "Shovel",
    "Drops": [
      {
        "Item": "minecraft:sand",
        "Quantity": 1
      }
    ]
  }
}
json
{
  "HasGravity": true,
  "GravityDelay": 5,
  "PhysicsDrop": {
    "GatherType": "Shovel",
    "Drops": [
      {
        "Item": "minecraft:sand",
        "Quantity": 1
      }
    ]
  }
}

Block Gathering/Breaking

方块采集/破坏

Breaking Configuration

破坏配置

json
{
  "Gathering": {
    "Breaking": {
      "GatherType": "Pickaxe",
      "Power": 2,
      "Quality": 1,
      "Drops": [
        {
          "Item": "my_plugin:custom_ore",
          "Quantity": {
            "Min": 1,
            "Max": 3
          },
          "Chance": 1.0
        }
      ]
    },
    "Harvest": {
      "GatherType": "Hoe",
      "Quality": 1,
      "Drops": [
        {
          "Item": "my_plugin:seeds",
          "Quantity": 1
        }
      ]
    },
    "SoftBlock": {
      "Enabled": true,
      "Drops": [
        {
          "Item": "my_plugin:dust",
          "Quantity": 1
        }
      ]
    }
  }
}
Gather Types:
Hand
,
Pickaxe
,
Axe
,
Shovel
,
Hoe
,
Sword
json
{
  "Gathering": {
    "Breaking": {
      "GatherType": "Pickaxe",
      "Power": 2,
      "Quality": 1,
      "Drops": [
        {
          "Item": "my_plugin:custom_ore",
          "Quantity": {
            "Min": 1,
            "Max": 3
          },
          "Chance": 1.0
        }
      ]
    },
    "Harvest": {
      "GatherType": "Hoe",
      "Quality": 1,
      "Drops": [
        {
          "Item": "my_plugin:seeds",
          "Quantity": 1
        }
      ]
    },
    "SoftBlock": {
      "Enabled": true,
      "Drops": [
        {
          "Item": "my_plugin:dust",
          "Quantity": 1
        }
      ]
    }
  }
}
采集工具类型
Hand
Pickaxe
Axe
Shovel
Hoe
Sword

Block States

方块状态

Define different visual/behavioral states:
json
{
  "States": {
    "powered": {
      "Values": ["true", "false"],
      "Default": "false"
    },
    "facing": {
      "Values": ["north", "south", "east", "west"],
      "Default": "north"
    }
  },
  "StateData": {
    "powered=true,facing=north": {
      "Model": "MyPlugin/Models/powered_north"
    },
    "powered=true,facing=south": {
      "Model": "MyPlugin/Models/powered_south"
    },
    "powered=false": {
      "Model": "MyPlugin/Models/unpowered"
    }
  }
}
定义不同的视觉/行为状态:
json
{
  "States": {
    "powered": {
      "Values": ["true", "false"],
      "Default": "false"
    },
    "facing": {
      "Values": ["north", "south", "east", "west"],
      "Default": "north"
    }
  },
  "StateData": {
    "powered=true,facing=north": {
      "Model": "MyPlugin/Models/powered_north"
    },
    "powered=true,facing=south": {
      "Model": "MyPlugin/Models/powered_south"
    },
    "powered=false": {
      "Model": "MyPlugin/Models/unpowered"
    }
  }
}

Farming Blocks

可种植方块

Create crops with growth stages:
json
{
  "DisplayName": { "en-US": "Wheat" },
  "DrawType": "Model",
  "FarmingData": {
    "Stages": [
      {
        "Model": "Hytale/Models/Crops/wheat_stage_0",
        "GrowthTime": 300,
        "LightRequired": 8
      },
      {
        "Model": "Hytale/Models/Crops/wheat_stage_1",
        "GrowthTime": 300,
        "LightRequired": 8
      },
      {
        "Model": "Hytale/Models/Crops/wheat_stage_2",
        "GrowthTime": 300,
        "LightRequired": 8
      },
      {
        "Model": "Hytale/Models/Crops/wheat_stage_3",
        "GrowthTime": 0,
        "LightRequired": 0,
        "IsFinalStage": true
      }
    ],
    "Modifiers": {
      "Biome": {
        "Plains": 1.2,
        "Desert": 0.5
      },
      "Weather": {
        "Rain": 1.3
      }
    },
    "SpreadSettings": {
      "Enabled": true,
      "Chance": 0.1,
      "Radius": 2
    },
    "RequiredSoil": ["Hytale:Farmland", "Hytale:Dirt"]
  }
}
创建带有生长阶段的农作物:
json
{
  "DisplayName": { "en-US": "Wheat" },
  "DrawType": "Model",
  "FarmingData": {
    "Stages": [
      {
        "Model": "Hytale/Models/Crops/wheat_stage_0",
        "GrowthTime": 300,
        "LightRequired": 8
      },
      {
        "Model": "Hytale/Models/Crops/wheat_stage_1",
        "GrowthTime": 300,
        "LightRequired": 8
      },
      {
        "Model": "Hytale/Models/Crops/wheat_stage_2",
        "GrowthTime": 300,
        "LightRequired": 8
      },
      {
        "Model": "Hytale/Models/Crops/wheat_stage_3",
        "GrowthTime": 0,
        "LightRequired": 0,
        "IsFinalStage": true
      }
    ],
    "Modifiers": {
      "Biome": {
        "Plains": 1.2,
        "Desert": 0.5
      },
      "Weather": {
        "Rain": 1.3
      }
    },
    "SpreadSettings": {
      "Enabled": true,
      "Chance": 0.1,
      "Radius": 2
    },
    "RequiredSoil": ["Hytale:Farmland", "Hytale:Dirt"]
  }
}

Crafting Benches

工作台

Create blocks that open crafting interfaces:
创建可打开 crafting 界面的方块:

Standard Crafting Bench

标准工作台

json
{
  "DisplayName": { "en-US": "Workbench" },
  "DrawType": "Model",
  "Model": "MyPlugin/Models/workbench",
  "IsUsable": true,
  "Bench": {
    "Type": "Crafting",
    "Categories": ["MyPlugin:BasicCrafting", "MyPlugin:AdvancedCrafting"],
    "GridSize": {
      "Width": 3,
      "Height": 3
    },
    "OutputSlots": 1
  }
}
json
{
  "DisplayName": { "en-US": "Workbench" },
  "DrawType": "Model",
  "Model": "MyPlugin/Models/workbench",
  "IsUsable": true,
  "Bench": {
    "Type": "Crafting",
    "Categories": ["MyPlugin:BasicCrafting", "MyPlugin:AdvancedCrafting"],
    "GridSize": {
      "Width": 3,
      "Height": 3
    },
    "OutputSlots": 1
  }
}

Processing Bench

加工工作台

json
{
  "Bench": {
    "Type": "Processing",
    "Categories": ["MyPlugin:Smelting"],
    "InputSlots": 1,
    "FuelSlots": 1,
    "OutputSlots": 1,
    "ProcessingTime": 200,
    "FuelTypes": ["Hytale:Coal", "Hytale:Charcoal"]
  }
}
json
{
  "Bench": {
    "Type": "Processing",
    "Categories": ["MyPlugin:Smelting"],
    "InputSlots": 1,
    "FuelSlots": 1,
    "OutputSlots": 1,
    "ProcessingTime": 200,
    "FuelTypes": ["Hytale:Coal", "Hytale:Charcoal"]
  }
}

Diagram Crafting Bench

蓝图工作台

json
{
  "Bench": {
    "Type": "DiagramCrafting",
    "Categories": ["MyPlugin:BlueprintCrafting"],
    "DiagramSlot": true,
    "MaterialSlots": 6,
    "OutputSlots": 1
  }
}
json
{
  "Bench": {
    "Type": "DiagramCrafting",
    "Categories": ["MyPlugin:BlueprintCrafting"],
    "DiagramSlot": true,
    "MaterialSlots": 6,
    "OutputSlots": 1
  }
}

Block Sounds

方块音效

json
{
  "BlockSound": "MyPlugin/BlockSounds/metal",
  "AmbientSound": {
    "Sound": "MyPlugin/Sounds/machine_hum",
    "Volume": 0.5,
    "Radius": 8
  }
}
Standard BlockSound sets:
Stone
,
Wood
,
Metal
,
Glass
,
Dirt
,
Sand
,
Grass
,
Gravel
,
Snow
,
Wool
json
{
  "BlockSound": "MyPlugin/BlockSounds/metal",
  "AmbientSound": {
    "Sound": "MyPlugin/Sounds/machine_hum",
    "Volume": 0.5,
    "Radius": 8
  }
}
标准BlockSound集合
Stone
Wood
Metal
Glass
Dirt
Sand
Grass
Gravel
Snow
Wool

Block Particles

方块粒子效果

json
{
  "BreakParticle": "MyPlugin/Particles/stone_break",
  "AmbientParticle": {
    "Particle": "MyPlugin/Particles/sparkle",
    "SpawnRate": 2,
    "Radius": 0.5
  },
  "FootstepParticle": "MyPlugin/Particles/dust"
}
json
{
  "BreakParticle": "MyPlugin/Particles/stone_break",
  "AmbientParticle": {
    "Particle": "MyPlugin/Particles/sparkle",
    "SpawnRate": 2,
    "Radius": 0.5
  },
  "FootstepParticle": "MyPlugin/Particles/dust"
}

Block Interactions

方块交互

Define custom interactions via the Interaction system:
json
{
  "Interactions": {
    "Use": "MyPlugin:MyBlockInteraction",
    "Attack": "MyPlugin:MyBlockAttackInteraction"
  }
}
通过交互系统定义自定义交互:
json
{
  "Interactions": {
    "Use": "MyPlugin:MyBlockInteraction",
    "Attack": "MyPlugin:MyBlockAttackInteraction"
  }
}

Interaction Types

交互类型

TypeTrigger
Use
Right-click
Attack
Left-click
Look
Look at block
Touch
Walk into block
类型触发条件
Use
右键点击
Attack
左键点击
Look
注视方块
Touch
走进方块

Complete Example: Custom Ore

完整示例:自定义矿石

json
{
  "DisplayName": {
    "en-US": "Mythril Ore"
  },
  "Description": {
    "en-US": "A rare ore found deep underground"
  },
  "DrawType": "Cube",
  "Texture": "MyPlugin/Textures/mythril_ore",
  "Material": "Stone",
  "LightLevel": 3,
  "LightColor": { "R": 0.5, "G": 0.8, "B": 1.0 },
  "Tags": {
    "Category": ["Ore", "Mining"]
  },
  "Gathering": {
    "Breaking": {
      "GatherType": "Pickaxe",
      "Power": 4,
      "Quality": 3,
      "Drops": [
        {
          "Item": "MyPlugin:RawMythril",
          "Quantity": { "Min": 1, "Max": 2 }
        }
      ]
    }
  },
  "BlockFaceSupport": {
    "Top": { "Type": "Full" },
    "Bottom": { "Type": "Full" },
    "North": { "Type": "Full" },
    "South": { "Type": "Full" },
    "East": { "Type": "Full" },
    "West": { "Type": "Full" }
  },
  "BlockSound": "Hytale/BlockSounds/Stone",
  "BreakParticle": "MyPlugin/Particles/mythril_break",
  "AmbientParticle": {
    "Particle": "MyPlugin/Particles/mythril_sparkle",
    "SpawnRate": 0.5
  }
}
json
{
  "DisplayName": {
    "en-US": "Mythril Ore"
  },
  "Description": {
    "en-US": "A rare ore found deep underground"
  },
  "DrawType": "Cube",
  "Texture": "MyPlugin/Textures/mythril_ore",
  "Material": "Stone",
  "LightLevel": 3,
  "LightColor": { "R": 0.5, "G": 0.8, "B": 1.0 },
  "Tags": {
    "Category": ["Ore", "Mining"]
  },
  "Gathering": {
    "Breaking": {
      "GatherType": "Pickaxe",
      "Power": 4,
      "Quality": 3,
      "Drops": [
        {
          "Item": "MyPlugin:RawMythril",
          "Quantity": { "Min": 1, "Max": 2 }
        }
      ]
    }
  },
  "BlockFaceSupport": {
    "Top": { "Type": "Full" },
    "Bottom": { "Type": "Full" },
    "North": { "Type": "Full" },
    "South": { "Type": "Full" },
    "East": { "Type": "Full" },
    "West": { "Type": "Full" }
  },
  "BlockSound": "Hytale/BlockSounds/Stone",
  "BreakParticle": "MyPlugin/Particles/mythril_break",
  "AmbientParticle": {
    "Particle": "MyPlugin/Particles/mythril_sparkle",
    "SpawnRate": 0.5
  }
}

Complete Example: Door Block

完整示例:门方块

json
{
  "DisplayName": { "en-US": "Wooden Door" },
  "DrawType": "Model",
  "Material": "Wood",
  "IsUsable": true,
  "States": {
    "open": {
      "Values": ["true", "false"],
      "Default": "false"
    },
    "facing": {
      "Values": ["north", "south", "east", "west"],
      "Default": "north"
    },
    "half": {
      "Values": ["upper", "lower"],
      "Default": "lower"
    }
  },
  "StateData": {
    "open=false,facing=north,half=lower": {
      "Model": "MyPlugin/Models/door_closed_lower_n"
    },
    "open=true,facing=north,half=lower": {
      "Model": "MyPlugin/Models/door_open_lower_n"
    }
  },
  "IsSolid": false,
  "Interactions": {
    "Use": "MyPlugin:DoorInteraction"
  },
  "PlacementSettings": {
    "RotationMode": "PlayerFacing",
    "MultiBlock": {
      "Pattern": [
        { "Offset": [0, 1, 0], "State": "half=upper" }
      ]
    }
  },
  "BlockSound": "Hytale/BlockSounds/Wood",
  "RequiredBlockFaceSupport": {
    "Bottom": [
      { "Type": "Full", "Match": "REQUIRED" }
    ]
  }
}
json
{
  "DisplayName": { "en-US": "Wooden Door" },
  "DrawType": "Model",
  "Material": "Wood",
  "IsUsable": true,
  "States": {
    "open": {
      "Values": ["true", "false"],
      "Default": "false"
    },
    "facing": {
      "Values": ["north", "south", "east", "west"],
      "Default": "north"
    },
    "half": {
      "Values": ["upper", "lower"],
      "Default": "lower"
    }
  },
  "StateData": {
    "open=false,facing=north,half=lower": {
      "Model": "MyPlugin/Models/door_closed_lower_n"
    },
    "open=true,facing=north,half=lower": {
      "Model": "MyPlugin/Models/door_open_lower_n"
    }
  },
  "IsSolid": false,
  "Interactions": {
    "Use": "MyPlugin:DoorInteraction"
  },
  "PlacementSettings": {
    "RotationMode": "PlayerFacing",
    "MultiBlock": {
      "Pattern": [
        { "Offset": [0, 1, 0], "State": "half=upper" }
      ]
    }
  },
  "BlockSound": "Hytale/BlockSounds/Wood",
  "RequiredBlockFaceSupport": {
    "Bottom": [
      { "Type": "Full", "Match": "REQUIRED" }
    ]
  }
}

Registering Blocks from Plugin Code

从插件代码注册方块

For dynamic block registration:
java
@Override
protected void setup() {
    // Listen for block type loading
    getEventRegistry().register(
        LoadedAssetsEvent.class, 
        BlockType.class, 
        this::onBlockTypesLoaded
    );
}

private void onBlockTypesLoaded(LoadedAssetsEvent<BlockType> event) {
    // Access loaded block types
    BlockType myBlock = event.getAssetStore().get("MyPlugin:my_custom_block");
    if (myBlock != null) {
        getLogger().atInfo().log("Custom block loaded: %s", myBlock.getDisplayName());
    }
}
动态注册方块的方法:
java
@Override
protected void setup() {
    // 监听方块类型加载事件
    getEventRegistry().register(
        LoadedAssetsEvent.class, 
        BlockType.class, 
        this::onBlockTypesLoaded
    );
}

private void onBlockTypesLoaded(LoadedAssetsEvent<BlockType> event) {
    // 获取已加载的方块类型
    BlockType myBlock = event.getAssetStore().get("MyPlugin:my_custom_block");
    if (myBlock != null) {
        getLogger().atInfo().log("Custom block loaded: %s", myBlock.getDisplayName());
    }
}

Block Events

方块事件

Handle block-related events:
java
@Override
protected void setup() {
    // Block break event
    getEntityStoreRegistry().registerSystem(new BreakBlockHandler());
    
    // Block place event  
    getEntityStoreRegistry().registerSystem(new PlaceBlockHandler());
    
    // Block use event
    getEntityStoreRegistry().registerSystem(new UseBlockHandler());
}

public class BreakBlockHandler extends EntityEventSystem<EntityStore, BreakBlockEvent> {
    public BreakBlockHandler() {
        super(BreakBlockEvent.class);
    }
    
    @Override
    public void handle(int index, ArchetypeChunk<EntityStore> chunk, 
                       Store<EntityStore> store, CommandBuffer<EntityStore> buffer,
                       BreakBlockEvent event) {
        BlockType blockType = event.getBlockType();
        Vector3i position = event.getPosition();
        
        // Custom logic here
        if (blockType.getId().equals("MyPlugin:protected_block")) {
            event.setCancelled(true);
        }
    }
}
处理与方块相关的事件:
java
@Override
protected void setup() {
    // 方块破坏事件
    getEntityStoreRegistry().registerSystem(new BreakBlockHandler());
    
    // 方块放置事件  
    getEntityStoreRegistry().registerSystem(new PlaceBlockHandler());
    
    // 方块使用事件
    getEntityStoreRegistry().registerSystem(new UseBlockHandler());
}

public class BreakBlockHandler extends EntityEventSystem<EntityStore, BreakBlockEvent> {
    public BreakBlockHandler() {
        super(BreakBlockEvent.class);
    }
    
    @Override
    public void handle(int index, ArchetypeChunk<EntityStore> chunk, 
                       Store<EntityStore> store, CommandBuffer<EntityStore> buffer,
                       BreakBlockEvent event) {
        BlockType blockType = event.getBlockType();
        Vector3i position = event.getPosition();
        
        // 自定义逻辑
        if (blockType.getId().equals("MyPlugin:protected_block")) {
            event.setCancelled(true);
        }
    }
}

Troubleshooting

故障排除

Block Not Rendering

方块无法渲染

  1. Verify
    DrawType
    is correct
  2. Check texture path exists
  3. Ensure asset pack is registered in manifest
  1. 确认
    DrawType
    设置正确
  2. 检查纹理路径是否存在
  3. 确保资源包已在清单中注册

Block Breaking Instantly

方块被瞬间破坏

  1. Check
    Material
    property
  2. Verify
    GatherType
    and
    Power
    settings
  3. Ensure tool requirements are set
  1. 检查
    Material
    属性设置
  2. 验证
    GatherType
    Power
    配置
  3. 确保工具要求已正确设置
查看
references/block-materials.md
获取材质属性详情。 查看
references/block-states.md
获取高级状态管理指南。

Physics Not Working

  1. Verify
    BlockFaceSupport
    configuration
  2. Check
    RequiredBlockFaceSupport
    matches
  3. Ensure
    IsSolid
    is true
See
references/block-materials.md
for material properties. See
references/block-states.md
for advanced state management.