本文整理汇总了Java中net.minecraft.entity.EntityLivingBase.setHeldItem方法的典型用法代码示例。如果您正苦于以下问题:Java EntityLivingBase.setHeldItem方法的具体用法?Java EntityLivingBase.setHeldItem怎么用?Java EntityLivingBase.setHeldItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.entity.EntityLivingBase
的用法示例。
在下文中一共展示了EntityLivingBase.setHeldItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performEffect
import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
if (rtrace.typeOfHit == Type.ENTITY && rtrace.entityHit instanceof EntityLivingBase) {
EntityLivingBase entity = (EntityLivingBase) rtrace.entityHit;
EnumHand hand = null;
if (!entity.getHeldItemMainhand().isEmpty()) hand = EnumHand.MAIN_HAND;
else if (!entity.getHeldItemOffhand().isEmpty()) hand = EnumHand.OFF_HAND;
if (hand != null) {
ItemStack stack = entity.getHeldItem(hand).copy();
entity.setHeldItem(hand, ItemStack.EMPTY);
if (!(entity instanceof EntityPlayer) && stack.isItemStackDamageable() && stack.getItemDamage() == 0) {
stack.setItemDamage((int) (stack.getMaxDamage() * (0.5D + 0.5D * Math.random())));
}
EntityItem ei = new EntityItem(world, entity.posX, entity.posY, entity.posZ, stack);
ei.setPickupDelay(200);
ei.setNoDespawn();
if (!world.isRemote) world.spawnEntity(ei);
}
}
}
示例2: itemInteractionForEntity
import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target,
EnumHand hand) {
if (target instanceof EntityZombie) {
target.setHeldItem(EnumHand.MAIN_HAND, stack);
}
return false;
}
示例3: altUse
import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@Override
public void altUse(ItemStack stack, EntityLivingBase living, World world) {
if (TF2Attribute.getModifier("Ball Release", stack, 0, living) > 0) {
ItemStack ballStack = getNewStack("sandmanball");
if (!ItemAmmo.searchForAmmo(living, ballStack).isEmpty()) {
if (living instanceof EntityPlayer)
((EntityPlayer)living).getCooldownTracker().setCooldown(this, this.getFiringSpeed(ballStack, living)/50);
ItemStack oldHeldItem = living.getHeldItemMainhand();
living.setHeldItem(EnumHand.MAIN_HAND, ballStack);
((ItemProjectileWeapon) ballStack.getItem()).use(ballStack, living, world, EnumHand.MAIN_HAND, null);
living.setHeldItem(EnumHand.MAIN_HAND, oldHeldItem);
}
}
}