ItemBuilder
Link to itembuilder
The item builder is to... build items (surprise!)
It allows you to set various properties that will change how the item behaves and what it can do. You can also use this#withType to switch to a more specialized builder, if there exist any.
To tell CoT that you want the item to appear in-game you need to call this#build(String) and specify a valid resource location path.
This class was added by a mod with mod-id contenttweaker
. 因此,如果要使用此功能,则需要安装此mod。
导入类
Link to 导入类
It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.
ZenScript Copyimport mods.contenttweaker.item.ItemBuilder;
已实现的接口
Link to 已实现的接口
ItemBuilder implements the following interfaces. That means all methods defined in these interfaces are also available in ItemBuilder
Constructor #构造函数
Link to constructor-构造函数
Creates a new ItemBuilder.
Remember that this will not create a new block in the game, you need to call this#build(String) for that.
ZenScript Copynew ItemBuilder() as ItemBuilder
new ItemBuilder();
使用方式
Link to 使用方式
Name: build
Instructs CoT to actually build whatever this builder is supposed to be building.
Return Type: void
ZenScript Copy// ItemBuilder.build(resourceLocation as string) as void
new ItemBuilder().build("my_awesome_block");
参数 | 类型 | 描述 |
---|---|---|
参数 resourceLocation | 类型 string | 描述 The resource path to give this block |
Name: isImmuneToFire
Sets that this item is immune to fire
Returns: The builder, used for method chaining
Return Type: ItemBuilder
ZenScript Copy// ItemBuilder.isImmuneToFire() as ItemBuilder
new ItemBuilder().isImmuneToFire();
Name: withFood
Sets that this item is a food
Returns: The builder, used for method chaining
Return Type: ItemBuilder
ZenScript CopyItemBuilder.withFood(food as MCFood) as ItemBuilder
参数 | 类型 | 描述 |
---|---|---|
参数 food | 类型 MCFood | 描述 the food |
Name: withItemGroup
Allows you to set the item group that this item will appear in. By default, items will land in misc
Returns: This builder, used for method chaining
Return Type: ItemBuilder
ZenScript Copy// ItemBuilder.withItemGroup(itemGroup as ItemGroup) as ItemBuilder
new ItemBuilder().withItemGroup(<itemGroup:misc>);
参数 | 类型 | 描述 |
---|---|---|
参数 itemGroup | 类型 ItemGroup | 描述 The item group this item should appear in |
Name: withMaxDamage
Allows you to set the maximum damage for this item.
Be warned that this cannot be used in combination with this#withMaxStackSize!
Returns: This builder, used for method chaining
Return Type: ItemBuilder
ZenScript Copy// ItemBuilder.withMaxDamage(maxDamage as int) as ItemBuilder
new ItemBuilder().withMaxDamage(250);
参数 | 类型 | 描述 |
---|---|---|
参数 maxDamage | 类型 int | 描述 The maximum stack size |
Name: withMaxStackSize
Allows you to set the maximum stack size for this item.
Be warned that this cannot be used in combination with this#withMaxDamage!
Returns: This builder, used for method chaining
Return Type: ItemBuilder
ZenScript Copy// ItemBuilder.withMaxStackSize(maxStackSize as int) as ItemBuilder
new ItemBuilder().withMaxStackSize(16);
参数 | 类型 | 描述 |
---|---|---|
参数 maxStackSize | 类型 int | 描述 The maximum stack size |
Name: withNoRepair
Sets that this item may not be repaired in an anvil
Returns: This builder, used for method chaining
Return Type: ItemBuilder
ZenScript Copy// ItemBuilder.withNoRepair() as ItemBuilder
new ItemBuilder().withNoRepair();
Name: withRarity
Allows you to set the item's rarity
Returns: This builder, used for method chaining
Return Type: ItemBuilder
ZenScript Copy// ItemBuilder.withRarity(rarity as string) as ItemBuilder
new ItemBuilder().withRarity("EPIC");
参数 | 类型 | 描述 |
---|---|---|
参数 rarity | 类型 string | 描述 The rarity |
Name: withType
Sets the specific type of this item. After this method is called the builder's context will switch to the more provided type builder. That means that the methods of this builder will no longer be available, so any properties you wish to set should be set before you call this method.
Returns: A builder with the given item.
Return Type: T
ZenScript CopyItemBuilder.withType<T : ItemTypeBuilder>() as T
参数 | 类型 | 描述 |
---|---|---|
参数 T | 类型 ItemTypeBuilder | 描述 The Type of item that this should become |