我的世界锻造如何阻止暴徒在命中后变得无懈可击(Java)1.10.2

2022-04-18 00:00:00 minecraft java 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);

}

编辑: 找到解决方案: 多亏了@Draco18,我找到了解决方案。 我所要做的就是添加行

entityArrow.hurtResistantTime = 0

解决方案

您需要这个:

entityHit.hurtResistantTime = 0;

注意:确切的字段名称可能会因"我的世界"版本和Forge的内部版本号而异。

在你伤害实体之前(绕过所有其他伤害来源施加的伤害抗性计时器)或之后(如果有计时器,你的伤害被忽略,但如果它造成伤害,下一个来源不会因为计时器而被忽略)。此行需要位于箭头类中。如果您没有自定义Arrow类,现在是创建一个类的好时机。

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

相关文章