MineCraft Forge如何阻止暴徒在击中后无法攻击(Java)1.10.2

时间:2017-05-04 17:10:10

标签: java minecraft minecraft-forge

我已经制作了一个可以快速射击的自定义弓,并且我已经了解到所有怪物在被击中之后的短时间内都是无懈可击的。这使得我的弓几乎没用。我想知道是否有任何方法可以改变怪物无懈可击的持续时间,甚至根本不删除它。

弓射击法的代码:

@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

1 个答案:

答案 0 :(得分:1)

你需要这个:

entityHit.hurtResistantTime = 0;

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

在你伤害实体之前调用它(绕过受到所有其他伤害来源造成的伤害抵抗定时器)或之后(如果有计时器则忽略你的伤害,但是如果造成伤害, next <由于计时器,/ em> source不会被忽略。此行必须位于箭头类中。如果您没有自定义箭头类,现在是制作它的好时机。

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