ModTile 类

用于创建自定义图块、方块和家具的基类。

概述

ModTile 类允许您创建自定义可放置方块、家具和具有自定义行为的装饰图块。

简单方块示例

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;

namespace YourMod.Tiles
{
    public class ExampleTile : ModTile
    {
        public override void SetStaticDefaults()
        {
            Main.tileSolid[Type] = true; // Block is solid
            Main.tileMergeDirt[Type] = true; // Merges with dirt
            Main.tileBlockLight[Type] = true; // Blocks light
            TileID.Sets.Ore[Type] = true; // Ore type (optional)
            AddMapEntry(new Color(100, 100, 100)); // Map color
            DustType = DustID.Stone;
            HitSound = SoundID.Tink;
            MinPick = 50; // Requires 50+ pickaxe power
        }
    }
}

创建家具

家具图块更为复杂,有放置规则:

public class ExampleChair : ModTile
{
    public override void SetStaticDefaults()
    {
        Main.tileFrameImportant[Type] = true; // Critical for furniture
        Main.tileNoAttach[Type] = true;
        TileID.Sets.HasOutlines[Type] = true;
        TileObjectData.newTile.CopyFrom(TileObjectData.Style1x2);
        TileObjectData.newTile.CoordinateHeights = new[] { 16, 18 };
        TileObjectData.addTile(Type);
        AddMapEntry(new Color(120, 85, 60), "Example Chair");
        DustType = DustID.WoodFurniture;
        TileID.Sets.DisableSmartCursor[Type] = true;
    }
}

常用图块属性

tileSolid

方块为实心(无法穿过)

Main.tileSolid[Type] = true;

tileBlockLight

方块阻挡光线穿透

Main.tileBlockLight[Type] = true;

MinPick

挖掘所需的最低镐力

MinPick = 100;

DustType

挖掘时的粒子效果

DustType = DustID.Stone;

获取完整的 ModTile 文档:

查看完整文档