如何将MobEffects应用于实体命中

时间:2018-01-24 20:21:35

标签: minecraft minecraft-forge

我想当我使用我的Minecraft Forge 1.11.2自定义弓击中一名玩家时,它会给该击中玩家一个PotionEffect。

我试过这个

public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
        target.addPotionEffect(new PotionEffect(MobEffects.SPEED, Utils.SECS2TICKS(3), 1));
        return true;
        }

只有当我用弓箭击中实体时才有效。

我目前的代码是

package revdomain.mod.items;


import revdomain.mod.renders.RenderItems;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBow;

public class bowclass extends ItemBow {
    public bowclass(String Name) {
        this.setCreativeTab(CreativeTabs.COMBAT);
        this.setRegistryName(Name);
        this.setUnlocalizedName(Name);
        RenderItems.ITEMS.put(Name, this);
    }

}

1 个答案:

答案 0 :(得分:0)

我重写createArrow

package revdomain.mod.items;

import revdomain.mod.renders.RenderItems;
import revdomain.mod.Utils;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntityTippedArrow;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

        public class bowclass extends ItemBow {
            public bowclass(String Name) {
                this.setCreativeTab(CreativeTabs.COMBAT);
                this.setRegistryName(Name);
                this.setUnlocalizedName(Name);
                RenderItems.ITEMS.put(Name, this);
            }

        }
        // Bit to add
        public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter)
        {
            EntityTippedArrow entitytippedarrow = new EntityTippedArrow(worldIn, shooter);
            entitytippedarrow.setPotionEffect(stack);
            entitytippedarrow.addEffect(new PotionEffect(MobEffects.effectname, Utils.SECS2TICKS(10), 1)); // Add custom PotionEffect
            return entitytippedarrow;
        }

要转换刻度,这是我的工具

public static int MINS2TICKS(int mins) {
return mins * 1200;
}

public static int SECS2TICKS(int secs) {
return secs * 20;
}

如果有人需要帮助,请随时发表评论