yg191203
本帖最后由 yg191203 于 2020-9-6 18:24 编辑

想要做一个和美味培根一样的效果,只不过掉落换成其他东西
从GitHub上找到这一段https://github.com/SlimeKnights/TinkersConstruct/blob/1.12/src/main/java/slimeknights/tconstruct/tools/traits/TraitBaconlicious.java怎么用ZenScript写
求魔改大神指点

努力半天终于写出来了


2021.12 数据,可能有更多内容想要做一个和美味培根一样的效果,只不过掉落换成其他东西
从GitHub上找到这一段https://github.com/SlimeKnights/TinkersConstruct/blob/1.12/src/main/java/slimeknights/tconstruct/tools/traits/TraitBaconlicious.java怎么用ZenScript写
求魔改大神指点


努力半天终于写出来了#loader contenttweaker
#modloaded tconstruct


import mods.contenttweaker.tconstruct.TraitBuilder;
import mods.contenttweaker.tconstruct.Trait;
import crafttweaker.item.IItemStack;
import crafttweaker.item.IIngredient;
import crafttweaker.world.IBlockPos;
import crafttweaker.block.IBlockState;
import crafttweaker.world.IWorld;
import crafttweaker.entity.IEntity;
import crafttweaker.entity.IEntityLivingBase;
import crafttweaker.entity.IEntityItem;
import mods.contenttweaker.Random;
import mods.ctutils.utils.Math;


val trait_nc = mods.contenttweaker.tconstruct.TraitBuilder.create("neutroniumcondense");
    trait_nc.color = 0x424443;
    trait_nc.localizedName = "中子凝聚";
    trait_nc.localizedDescription = "使用时有几率获得少量的中子素。";
    trait_nc.addItem(<item:avaritia:neutron_collector>);
    trait_nc.afterBlockBreak = function(thisTrait, tool, world, blockState, pos, miner, wasEffective) {
  if (!world.isRemote()) {
    var chance as double = Math.random();
    if (chance <= 0.05) {
    world.spawnEntity(<item:avaritia:resource>.createEntityItem(world, pos.getX(), pos.getY(), pos.getZ()));
    }
  }
    };
    trait_nc.afterHit = function(thisTrait, tool, attacker, target, damageDealt, wasCrit, wasHit) {
  if (!target.world.isRemote() & !target.isAlive()) {
    var chance as double = Math.random();
    if (chance <= 0.05) {
    target.world.spawnEntity(<item:avaritia:resource>.createEntityItem(target.world, target.posX, target.posY, target.posZ));
    }
  }
    };
trait_nc.register();

youyihj
random 变量哪里冒出来的?
想要搞随机数的话,请去加 CraftTweaker Utils 或者 Boson

CoT World,可以用 getRandom 获取这个 random 对象,但这里是 CrT 的 IWorld

第一页 上一页 下一页 最后一页