Data Types and Enums
本篇描述的数据类型、枚举类型在所有的文件均可用。
Data Types
ObjectRef(抽象类)
维护指定类型对象的引用。
继承该抽象类的子类:BlockEntityRef。
属性 | 类型 | 描述 |
ObjectRef.ref | Object/nil | 读取时返回被引用的对象,若对象不存在则返回nil。 写入时将对象的引用覆盖到当前引用,写入nil表示写入空引用。 |
案例
例如,在如下范例中,self.modData.blockEntityRef
表示方块实体引用。blockEntity2
表示某个方块实体对象。
ArrayList<T>
TerraCraft内置的动态数组。
属性 | 类型 | 描述 |
ArrayList.length | int | 【只读】数组长度。 |
函数 | 返回值 | 描述 |
ArrayList:GetLength() | int | 返回数组长度。 |
ArrayList[index] | T | 读取或写入指定下标的数组元素。index有效区间为[1, 可用数量]。 |
遍历方案
ExData
拓展数据。在TerraCraft模组中拥有两种拓展数据。
局部拓展数据(ModData)为当前使用该数据的对象独有,整个游戏中该对象只拥有一个局部拓展数据。
全局拓展数据(GlobalData)为同一类对象均拥有的属性,整个游戏中该对象拥有所有模组的全局拓展数据。
属性 | 类型 | 描述 |
ExData.xxx | 由xxx的具体类型决定 | 读写拓展数据。 |
ExData.xxx[n] | 由xxx的具体类型决定 | 读写拓展数据数组。 |
函数 | 返回值 | 描述 |
ExData:DataOf(string dataSetName) | bool | 判断当前数据是否拥有指定数据集。 |
案例
某个模组的NPC拥有
GlobalData
,数据为bool isCold
和int coldTime
。npc1
拥有ModData
,数据为int timer
和double targetAngle
。npc2
拥有ModData
,数据为int magicLevel
。npc3
没有ModData
。
如下是访问这些数据的范例:
Point
Represents a point.
Member | Type | Description |
Point.x | double | The x coordinate of the point. |
Point.y | double | The y coordinate of the point. |
Rectangle
Represents an axis-aligned rectangle.
Member | Type | Description |
Rectangle.x | int | The x coordinate of the upper left corner of the rectangle. |
Rectangle.y | int | The y coordinate of the upper left corner of the rectangle. |
Rectangle.width | int | The width of the rectangle. |
Rectangle.height | int | The height of the rectangle. |
Function | Returns | Description |
Rectangle:Set(int x, int y, int width, int height) | void | Set a new rectangle. |
SpriteEx
Sprite extension information, has the relevant parameters of drawing.
Member | Type | Description |
SpriteEx.scaleRateX | float | [ default |
SpriteEx.scaleRateY | float | [ default |
SpriteEx.rotateX | float | The center point X of the sprite's rotation. If the drawing object is an entity, the default is the center of the entity, otherwise the default is 0.0. |
SpriteEx.rotateY | float | The center point Y of the sprite's rotation. If the drawing object is an entity, the default is the center of the entity, otherwise the default is 0.0. |
SpriteEx.angle | float | [ default |
SpriteEx.flipHorizontal | bool | [ default |
SpriteEx.flipVertical | bool | [ default |
Function | Returns | Description |
SpriteEx:SetDefault() | void | Restore Defaults. |
Hitbox
Represents a collision box. If the angle
attribute is 0, it means axis aligned collision box (AABB). Otherwise, it represents a collision box rotating around the center point.
Member | Type | Description |
Hitbox.x | double | The x coordinate of the upper left corner of the hitbox when the rotation angle is 0. |
Hitbox.y | double | The y coordinate of the upper left corner of the hitbox when the rotation angle is 0. |
Hitbox.width | int | The width of the hitbox. |
Hitbox.height | int | The height of the hitbox. |
Hitbox.centerX | double | [ Read-only ] Returns the center x coordinate of the hitbox. |
Hitbox.centerY | double | [ Read-only ] Returns the center y coordinate of the hitbox. |
Hitbox.angle | double | [ Read-only ] Returns the rotation angle of the collision box if the collision box can be rotated. |
Function | Returns | Description |
Hitbox:Overlap(Hitbox other) | bool | Returns whether the current hitbox overlaps with another hitbox. |
Hitbox:OverlapAABB(Hitbox other) | bool | Returns whether the current axis-aligned rectangle overlaps with another axis-aligned rectangle. |
Attack
表示一个攻击属性。
属性 | 类型 | 描述 |
Attack.attack | int | 攻击值。 |
Attack.knockBack | int | 攻击的击退值。 |
Attack.crit | int | 攻击的百分暴击率。1-100表示1-100%的概率产生双倍暴击伤害,大于100表示总是产生双倍暴击伤害,小于1表示不产生暴击伤害。 |
静态函数 | 返回值 | 描述 |
Attack:new_local(int attack, int knockBack, int crit) | Attack | 返回一个Attack对象。 |
Defense
表示一个防御属性。
属性 | 类型 | 描述 |
Defense.defense | int | 防御值。 |
Defense.blastDefense | int | 爆炸防御值。 |
Defense.flameDefense | int | 火焰防御值。 |
Defense.projectileDefense | int | 抛掷物防御值。 |
Defense.breathDefense | int | 呼吸防御值。 |
Defense.fallDefense | int | 摔落防御值。 |
Defense.knockBackDefense | int | 击退防御值。 |
EntityKey
表示一个实体在对应实体类型中的唯一键值。
Color
Represents a color with four channels of alpha (transparency), red, green, and blue.
Member | Type | Description |
Color.alpha | int | [ Read-only ] Transparent channel value, valid interval is [0,255]. |
Color.red | int | [ Read-only ] Red channel value, valid interval is [0,255]. |
Color.green | int | [ Read-only ] Green channel value, valid interval is [0,255]. |
Color.blue | int | [ Read-only ] Blue channel value, valid interval is [0,255]. |
Function | Returns | Description |
Color:Set(int alpha, int red, int green, int blue) | void | Set new color. |
Color:Set(DefaultColor defaultColor) | void | Set color by default. |
PlaceParameter
放置方块的参数类型。
属性 | 类型 | 描述 |
PlaceParameter.placeDir | Direction | 【只读】放置的朝向。 |
ClickParameter
点击方块的参数类型。
属性 | 类型 | 描述 |
ClickParameter.playerRef | PlayerRef | 【只读】发生点击的玩家引用。 |
DestroyParameter
破坏方块的参数类型。
属性 | 类型 | 描述 |
DestroyParameter.boom | bool | 【只读】是否为由爆炸产生的破坏。 |
DestroyParameter.silkTouch | int | 【只读】破坏时精准采集等级。 |
DestroyParameter.fortune | int | 【只读】破坏时时运等级。 |
Enums
注意,这里的枚举值直接当作全局常量使用,且枚举类型的变量只能使用对应枚举值。例如:
NetMode
Describe the runtime environment is the client or server.
Note that the client and built-in server are running at the same time in single mode.
Enum | Description |
NET_MODE_SERVER | The runtime environment is server. |
NET_MODE_CLIENT | The runtime environment is client. |
Direction
Represents what the direction is.
Enum | Description |
DIRECTION_LEFT | Left. |
DIRECTION_TOP | Top. |
DIRECTION_BOTTOM | Bottom. |
DIRECTION_RIGHT | Right. |
Shape
Represents a shape.
Enum | Description |
SHAPE_BOX | The shape of the hitbox is an axis-aligned rectangle. |
SHAPE_ROTATE_BOX | The shape of the hitbox is a rotating rectangle. |
ItemType
描述物品类型。
枚举值 | 描述 |
ITEM_TYPE_NONE | 无物品。 |
ITEM_TYPE_BLOCKS | 方块类型物品。 |
ITEM_TYPE_TOOLS | 工具类型物品。 |
ITEM_TYPE_MATERIALS | 材料类型物品。 |
ITEM_TYPE_WIRES | 红石电线类型物品。 |
ITEM_TYPE_PROJECTILES | 抛射物类型物品。 |
ITEM_TYPE_CHESTS | 容器类型物品。 |
ToolType
描述工具类型。
枚举值 | 描述 |
TOOL_TYPE_NONE | 无有效工具类型。 |
TOOL_TYPE_AXE | 斧头。 |
TOOL_TYPE_PICKAXE | 镐子。 |
TOOL_TYPE_SWORD | 剑。 |
TOOL_TYPE_BOW | 弓/枪械。 |
TOOL_TYPE_HELMET | 头盔。 |
TOOL_TYPE_CHESTPLATE | 胸甲。 |
TOOL_TYPE_LEGGINGS | 裤腿。 |
TOOL_TYPE_BOOK | 书本。 |
TOOL_TYPE_SHEARS | 剪刀。 |
TOOL_TYPE_HOE | 锄。 |
TOOL_TYPE_WIRE_CUTTER | 剪线钳。 |
TOOL_TYPE_DRILL | 钻头。 |
TOOL_TYPE_SAW | 锯子。 |
TOOL_TYPE_STAFF | 法杖。 |
NpcType
描述NPC类型。
枚举值 | 描述 |
NPC_TYPE_NORMAL | 普通NPC。 |
NPC_TYPE_ANIMAL | 动物类NPC。 |
NPC_TYPE_VILLAGER | 村民类NPC。 |
NPC_TYPE_ARTHROPODS | 节肢类NPC。 |
NPC_TYPE_SMITE | 亡灵类NPC。 |
NPC_TYPE_BOSS | BOSS类NPC。 |
DefaultColor
Represents default color.
Enum | Description |
COLOR_BLACK | ARGB=(255, 0, 0, 0) |
COLOR_WHITE | ARGB=(255, 255, 255, 255) |
COLOR_GRAY | ARGB=(255, 128, 128, 128) |
COLOR_RED | ARGB=(255, 255, 0, 0) |
COLOR_GREEN | ARGB=(255, 0, 255, 0) |
COLOR_BLUE | ARGB=(255, 0, 0, 255) |
COLOR_YELLOW | ARGB=(255, 255, 255, 0) |
LightingState
描述客户端光照状态。
枚举值 | 描述 |
LIGHTING_STATE_NORMAL | 普通光照状态。 |
LIGHTING_STATE_NIGHT_VISION | 夜视光照状态。 |
LIGHTING_STATE_BLINDNESS | 失明光照状态。 |
DeathReason
描述玩家的死亡原因。
枚举值 | 描述 |
DEATH_REASON_UNKNOWN | 未知原因死亡。 |
DEATH_REASON_SUICIDE | 自杀。 |
DEATH_REASON_FALL | 摔死。 |
DEATH_REASON_DROWN | 淹死。 |
DEATH_REASON_BOOM | 炸死。 |
DEATH_REASON_BURN | 烧死。 |
DEATH_REASON_LAVA | 在岩浆中游泳。 |
DEATH_REASON_STARVE | 饿死。 |
DEATH_REASON_BUFF | 状态效果作用而死。 |
DEATH_REASON_POISON | 毒死。 |
GameMode
描述玩家或地图的游戏模式。
枚举值 | 描述 |
GAME_MODE_SURVIVAL | 生存模式。 |
GAME_MODE_CREATIVE | 创造模式。 |
GAME_MODE_ADVANTURE | 冒险模式。 |
OP
描述玩家的权限等级。
枚举值 | 描述 |
OP_ANY | 任何人。 |
OP_ADMIN | 管理员。 |
OP_MASTER | 游戏拥有者(服主)。 |
OP_DEVELOPER | 开发者。 |
Last updated