MineCraft Forge 如何阻止小怪在被击中后变得无敌 (Java) 1.10.2

MineCraft Forge How to stop mobs from being invulnerable after hit (Java) 1.10.2

我制作了一把发射速度非常快的定制弓,而且我了解到所有生物在被击中后的短时间内都是无敌的。这使我的弓几乎毫无用处。我想知道是否有任何方法可以改变生物无敌的持续时间,或者甚至完全删除它。

弓箭发射方式代码:

@Override
    public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    //  int charge = 1;
    //  charge = ForgeEventFactory.onArrowLoose(stack, worldIn, playerIn, charge, true);
        player123 = playerIn;
        if (!worldIn.isRemote) {
        final ItemArrow itemArrow = (ItemArrow) (Items.ARROW instanceof ItemArrow ? Items.ARROW : Items.ARROW);



        final ItemStack ammo = new ItemStack(Items.ARROW, 1);
        final float arrowVelocity = 1;
        final EntityArrow entityArrow = itemArrow.createArrow(worldIn, ammo, playerIn);
        entityArrow.setAim(playerIn, playerIn.rotationPitch, playerIn.rotationYawHead, 0.0F, arrowVelocity * 3.5F, 0F);
        entityArrow.setDamage(2);
        entityArrow.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
//      entityArrow.setVelocity(0.2F, 0.1F, 0.2F);
        final ItemStack magicarrow = new ItemStack(TheGalaxyMod.magicarrow, 1);
        EntityLivingBase living = (playerIn);

        if (FastMode.fastmode == 1){
            int index = GetItemSlot(playerIn, magicarrow);
            if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.creativequiver)))
            {
                entityArrow.setDamage(5000);
                worldIn.spawnEntityInWorld(entityArrow);
            }
            else if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.magicquiver)))
            {
                worldIn.spawnEntityInWorld(entityArrow);
            }
            else if (!(playerIn.inventory.getStackInSlot(index).getItem() == null) && playerIn.inventory.getStackInSlot(index).getItem() == TheGalaxyMod.magicarrow)
            {
                damageItem(playerIn, magicarrow, 1);
                worldIn.spawnEntityInWorld(entityArrow);
                ItemStack stack2 = playerIn.inventory.getStackInSlot(index);
                if(stack2.getItemDamage() > 500)
                {
                    playerIn.inventory.setInventorySlotContents(index, null);
                }
            }
            else if(playerIn.inventory.hasItemStack(ammo) ){
                worldIn.spawnEntityInWorld(entityArrow);
                removeItem(playerIn, ammo);
            }

        }
        else if
        (FastMode.fastmode == 2)
        {
            final ItemArrow itemArrow2 = (ItemArrow) (Items.ARROW instanceof ItemArrow ? Items.ARROW : Items.ARROW);
            final ItemStack ammo2 = new ItemStack(Items.ARROW);
            final float arrowVelocity2 = 1;
            final EntityArrow entityArrow2 = itemArrow2.createArrow(worldIn, ammo2, playerIn);
            entityArrow2.setAim(playerIn, playerIn.rotationPitch, playerIn.rotationYawHead, 0.0F, arrowVelocity2 * 3.5F, 0F);
            entityArrow2.setDamage(2);
            entityArrow2.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
            int index = GetItemSlot(playerIn, magicarrow);
            if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.creativequiver)))
            {
                entityArrow.setDamage(5000);
                worldIn.spawnEntityInWorld(entityArrow);
                entityArrow2.setDamage(5000);
                worldIn.spawnEntityInWorld(entityArrow2);
            }
            else if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.magicquiver)))
            {
                worldIn.spawnEntityInWorld(entityArrow);
                worldIn.spawnEntityInWorld(entityArrow2);
            }
            else if (!(playerIn.inventory.getStackInSlot(index).getItem() == null) && playerIn.inventory.getStackInSlot(index).getItem() == TheGalaxyMod.magicarrow)
            {

                damageItem(playerIn, magicarrow, 2);
                worldIn.spawnEntityInWorld(entityArrow);
                worldIn.spawnEntityInWorld(entityArrow2);
                ItemStack stack2 = playerIn.inventory.getStackInSlot(index);
                if(stack2.getItemDamage() > 500)
                {
                    playerIn.inventory.setInventorySlotContents(index, null);
                }
            }
            else if(playerIn.inventory.hasItemStack(ammo) ){
                worldIn.spawnEntityInWorld(entityArrow);
                worldIn.spawnEntityInWorld(entityArrow2);
                removeItem(playerIn, ammo);

            }
        }
        else if
        (FastMode.fastmode == 3)
        {
            entityArrow.setFire(50);
            int index = GetItemSlot(playerIn, magicarrow);
            if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.creativequiver)))
            {
                entityArrow.setDamage(5000);
                worldIn.spawnEntityInWorld(entityArrow);
            }
            else if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.magicquiver)))
            {
                worldIn.spawnEntityInWorld(entityArrow);

            }
            else if (!(playerIn.inventory.getStackInSlot(index).getItem() == null) && playerIn.inventory.getStackInSlot(index).getItem() == TheGalaxyMod.magicarrow)
            {
                damageItem(playerIn, magicarrow, 2);
                worldIn.spawnEntityInWorld(entityArrow);
                ItemStack stack2 = playerIn.inventory.getStackInSlot(index);
                if(stack2.getItemDamage() > 500)
                {
                    playerIn.inventory.setInventorySlotContents(index, null);
                }
            }
            else if(playerIn.inventory.hasItemStack(ammo) ){
                worldIn.spawnEntityInWorld(entityArrow);
                removeItem(playerIn, ammo);
            }

        }

        }
        return super.onItemRightClick(stack, worldIn, playerIn, hand);

}

编辑: 找到的解决方案: 感谢@Draco18s,我找到了解决方案。 我所要做的就是添加行

entityArrow.hurtResistantTime = 0

你需要这个:

entityHit.hurtResistantTime = 0;

注意:确切的字段名称可能会根据 Minecraft 版本和 Forge 的内部版本号而改变。

在你伤害实体之前调用它(绕过所有其他伤害来源造成的伤害抵抗计时器)或之后(如果有计时器你的伤害会被忽略,但如果它造成伤害,next 由于计时器的缘故,源不会被忽略)。此行需要在 箭头 class 中。如果您没有自定义箭头 class,现在是制作一个的好时机。

不幸的是,没有(好的)方法可以根据先前的损坏类型有条件地将计时器设置为 0。如果您使用的是 1.10 或更高版本,则可以使用功能,尽管可能很笨重。