高级运用
更多实例
请看 CrT 高级运用 虽然咕咕咕了
运用于 MaterialBuilder 对象的函数
ItemLocalizer 函数
导包
import mods.tconstruct.materials.ItemLocalizer;该函数用于计算材料名称
此函数需要返回 string
Material 类的
thisMaterialString 类型的
itemName
例子
myMat.itemLocalizer = function(thisMaterial, itemName) {
return "Cool " + itemName;
};游戏中 : 
运用于 TraitBuilder 对象的函数
CanApplyTogether 函数
导包
import mods.tconstruct.traits.CanApplyTogetherTrait;
import mods.tconstruct.traits.CanApplyTogetherEnchantment;此函数可以使特性或附魔不能同存
此函数需要返回 bool
Trait 类的
thisTraitString 类型的
otherTrait
例子1
myTrait.canApplyTogetherTrait = function(thisTrait, otherTrait) {
return otherTrait != 特性名称(也就是 identifier)
};IEnchantmentDefinition 类的
thisTraitString 类型的
enchantmentDefinition
例子2
myTrait.canApplyTogetherEnchantment = function(thisTrait, enchantmentDefinition) {
return enchant != 附魔名称(不要傻傻的填个 "附魔名称")
};ExtraInfo 函数
导包
import mods.tconstruct.traits.ExtraInfo;可以在工具装配台看到额外信息
此函数需要返回 string[]
Trait 类的
thisTraitIItemStack 类的
itemIData 类的
tag
例子 :
myTrait.extraInfo = function(thisTrait, item, tag){
var infos as string[] = ["Cool1", "Cool2"];
return infos;
};游戏中 : 
getMiningSpeed 函数
导包
import mods.tconstruct.traits.MiningSpeed;破坏方块时调用
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolPlayerBreakSpeedEvent 类型的
event
函数写法 :
myTrait.getMiningSpeed = function(thisTrait, tool, event) {
//Code
};beforeBlockBreak 函数
导包
import mods.tconstruct.traits.BeforeBlockBreak;方块被破坏之前调用
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolBlockBreakEvent 类型的
event
函数写法 :
myTrait.beforeBlockBreak = function(thisTrait, tool, event) {
//Code
};afterBlockBreak 函数
导包
import mods.tconstruct.traits.AfterBlockBreak;方块被破坏之后调用
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolIWorld 类的
worldIBlockState 类的
blockstateIBlockPos 类的
posIEntityLivingBase 类的
minerboolean 类型的
wasEffective
函数写法 :
myTrait.afterBlockBreak = function(thisTrait, tool, world, blockstate, pos, miner, wasEffective) {
//Code
};onBlockHarvestDrops 函数
导包
import mods.tconstruct.traits.BlockHarvestDrops;方块被破坏且将要生成掉落物时调用
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolBlockHarvestDropsEvent 类型的
event
函数写法 :
myTrait.onBlockHarvestDrops = function(thisTrait, tool, event) {
//Code
};onUpdate 函数
导包
import mods.tconstruct.traits.Update;此函数每 Tick 都会调用
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolIWorld 类的
worldIEntity 类的
entity(实际使用时这个对象可能是为 IPlayer, IEntityLivingBase, 只是被自动转型为 IEntity, 可以 instanceof 判断之后就向下强转)int 类型的
itemSlotboolean 类型的
isSelected
函数写法 :
myTrait.onUpdate = function(thisTrait, tool, world, entity, itemSlot, isSelected) {
//Code
};afterHit 函数
导包
import mods.tconstruct.traits.AfterHit;实体受到伤害后调用
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolIEntityLivingBase 类的
attackerIEntityLivingBase 类的
targetfloat 类型的
damageDealtboolean 类型的
wasCriticalboolean 类型的
wasHit
函数写法 :
mytrait.afterHit = function(trait, tool, attacker, target, damageDealt, wasCritical, wasHit) {
//Code
};onHit 函数
导包
import mods.tconstruct.traits.OnHit;即将对实体造成伤害之前调用, 在此函数调用时所有的伤害都计算完毕 (简单来说就是最后一步)
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolIEntityLivingBase 类的
attackerIEntityLivingBase 类的
targetfloat 类型的
damageboolean 类型的
isCritical
函数写法 :
myTrait.onHit = function(thisTrait, tool, attacker, target, damage, isCritical) {
//Code
};onBlock 函数
导包
import mods.tconstruct.traits.OnBlock;玩家阻挡攻击时调用, 否则调用 onPlayerHurt 函数
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolIPlayer 类的
attackerEntityLivingHurtEvent 类型的
event
函数写法 :
myTrait.onBlock = function(thisTrait, tool, attacker, event) {
//Code
};onPlayerHurt 函数
导包
import mods.tconstruct.traits.OnPlayerHurt;玩家未阻挡攻击时调用, 否则调用 onBlock 函数
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolIPlayer 类的
playerIEntityLivingBase 类的
attackerEntityLivingHurtEvent 类型的
event
函数写法 :
myTrait.onPlayerHurt = function(thisTrait, tool, player, attacker, event) {
//Code
};calcCrit 函数
导包
import mods.tconstruct.traits.IsCriticalHit;对实体造成伤害之前调用以确定此次攻击是否暴击,返回值为 false 并不会取消已经是暴击的伤害
此函数需要返回一个 bool
Trait 类的
thisTraitIItemStack 类的
toolIEntityLivingBase 类的
attackerIEntityLivingBase 类的
target
函数写法 :
myTrait.calcCrit = function(thisTrait, tool, attacker, target) {
//Code
return true; //或 false
};calcDamage 函数
导包
import mods.tconstruct.traits.Damage;攻击一个实体时调用,但在造成伤害和计算暴击加成之前调用, 此函数用于计算暴击伤害的加成
此函数需要返回一个 float 以确定伤害加成
Trait 类的
thisTraitIItemStack 类的
toolIEntityLivingBase 类的
attackerIEntityLivingBase 类的
targetfloat 类型的
originalDamagefloat 类型的
currentDamageboolean 类型的
isCritical
函数写法 :
myTrait.calcDamage = function(thisTrait, tool, attacker, target, originalDamage, currentDamage, isCritical) {
//Code
return currentDamage; //或者修改后的值
};calcKnockBack 函数
导包
import mods.tconstruct.traits.KnockBack;攻击实体后调用, 以修改实体受到的击退
此函数需要返回一个 float 以确定击退距离
Trait 类的
thisTraitIItemStack 类的
toolIEntityLivingBase 类的
attackerIEntityLivingBase 类的
targetfloat 类型的
damagefloat 类型的
knockbackfloat 类型的
newKnockbackboolean 类型的
isCritical
函数写法 :
myTrait.calcKnockBack = function(thisTrait, tool, attacker, target, damage, knockback, newKnockback, isCritical) {
//Code
return newKnockback; //或者修改后的值
};onToolDamage 函数
导包
import mods.tconstruct.traits.OnToolDamage;工具降低耐久度之前调用
此函数需要返回一个 int 以确定工具耐久
Trait 类的
thisTraitIItemStack 类的
toolint 类型的
damageint 类型的
newDamageIEntityLivingBase 类的
entity
函数写法 :
myTrait.onToolDamage = function(thisTrait, tool, damage, newDamage, entity) {
//Code
return newDamage; //或者修改后的值
};calcToolHeal 函数
导包
import mods.tconstruct.traits.OnToolHeal;工具提高耐久度之前调用
此函数需要返回一个 int 以确定工具耐久
Trait 类的
thisTraitIItemStack 类的
toolint 类型的
damageint 类型的
newDamageIEntityLivingBase 类的
entity
函数写法 :
myTrait.calcToolHeal = function(thisTrait, tool, damage, newDamage, entity) {
//Code
return newDamage; //或者修改后的值
};onToolRepair 函数
导包
import mods.tconstruct.traits.OnToolRepair;使用材料修复工具前调用, 请勿与 calcToolHeal 函数混淆, 如果不止一次修复这个物品,此函数将被调用多次
此函数不需要返回值
Trait 类的
thisTraitIItemStack 类的
toolint 类型的
amount
函数写法 :
myTrait.onToolRepair = function(thisTrait, tool, amount) {
//Code
};最后更新于
这有帮助吗?