Jump to content

LivingHurtEvent not working?


Heltrato

Recommended Posts

Hello im having an issue with my event, i want it to make that whenever my custom entity base class attacks my own custom armor base class it deals the damage based on the calculations shown in the code. but what happens is i think it does not work and the system print wont show.. i have registered the event btw.

 

@SubscribeEvent
    public static void onDamageDealtToArmor(LivingHurtEvent event) {
        ArmorBase armor = ArmorBase.instance;
        DamageSource damageSrc = event.getSource();
        double damage = event.getAmount();
        Entity ent = event.getEntity();
        if (ent != null && ent instanceof EntityPlayer) {
            if(damageSrc.getSourceOfDamage() instanceof EntityMHFCBase)
            if (ent.getArmorInventoryList() != null && ent.getArmorInventoryList() instanceof ArmorBase) {
                /** Refines the damage analyzer based from Monster Hunter Series but in a special case which
                 *  the default health is set to 20 for players. **/
                    float newDamage = (float) Math.abs(((damage * 80) / (armor.getInitialDefenseValue() + 80)) * 0.20);
                    event.setAmount(newDamage);
                    //event.getEntity().attackEntityFrom(damageSrc, newDamage);
                    System.out.println("Current AI Damage = " + damage + " Current New Damage = " + newDamage);
                    }
                }
            }    

 

Edited by Heltrato
Link to comment
Share on other sites

10 minutes ago, Heltrato said:

Hello im having an issue with my event, i want it to make that whenever my custom entity base class attacks my own custom armor base class it deals the damage based on the calculations shown in the code. but what happens is i think it does not work and the system print wont show.. i have registered the event btw.

 


@SubscribeEvent
    public static void onDamageDealtToArmor(LivingHurtEvent event) {
        ArmorBase armor = ArmorBase.instance;
        DamageSource damageSrc = event.getSource();
        double damage = event.getAmount();
        Entity ent = event.getEntity();
        if (ent != null && ent instanceof EntityPlayer) {
            if(damageSrc.getSourceOfDamage() instanceof EntityMHFCBase)
            if (ent.getArmorInventoryList() != null && ent.getArmorInventoryList() instanceof ArmorBase) {
                /** Refines the damage analyzer based from Monster Hunter Series but in a special case which
                 *  the default health is set to 20 for players. **/
                    float newDamage = (float) Math.abs(((damage * 80) / (armor.getInitialDefenseValue() + 80)) * 0.20);
                    event.setAmount(newDamage);
                    //event.getEntity().attackEntityFrom(damageSrc, newDamage);
                    System.out.println("Current AI Damage = " + damage + " Current New Damage = " + newDamage);
                    }
                }
            }    

 

 

Re-check your If statements. If the comment doesn't fire then your code doesn't reach the if statements. I also believe you're missing an bracket. I'm not sure if it'd make a difference here since Java should decide it belongs to the first applicable clause to which it could belong.  

 

I do believe you might not get past the ent.getArmorInventoryList() instanceof ArmorBase), since that'll return an Iterable of the Itemstack.  Again, I'm not 100% sure. But you could start to check by inserting comments to see where exactly you're not getting further.

 

 

Link to comment
Share on other sites

34 minutes ago, oldcheese said:

 

Re-check your If statements. If the comment doesn't fire then your code doesn't reach the if statements. I also believe you're missing an bracket. I'm not sure if it'd make a difference here since Java should decide it belongs to the first applicable clause to which it could belong.  

 

I do believe you might not get past the ent.getArmorInventoryList() instanceof ArmorBase), since that'll return an Iterable of the Itemstack.  Again, I'm not 100% sure. But you could start to check by inserting comments to see where exactly you're not getting further.

 

 

So i need to check per equipment slots?

Link to comment
Share on other sites

12 hours ago, oldcheese said:

The Iterable is basically just a list with one item from each of your armor slots, so yes. If you want to check if the player has every single part equipped then you'd want to check every armorslot to see if your armor was there. 

 

you could do this with a for loop. 

Well i just want to have a check whether a player is wearing any equipment with the instanceof my custom armor, no need to check if the player wears it all. I just want to make the armor equipments damage calculation same in my arithmetic :) 

Link to comment
Share on other sites

The point still stands that getArmorInventoryList returns an object of type Iterable, and will therefore never be an instanceof your armor class. You can instead begin iterating through the list and break out of the iteration as soon as you find one instance of your armor.

 

I'll also echo the advice you were already given to add println statements in between every if statement to make sure the statements are true at each step along the way.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.