Is there a way to make certain types of mobs weak to a certain types of weapons?

Started by QB on

Topic category: Help with Minecraft modding (Java Edition)

Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is there a way to make certain types of mobs weak to a certain types of weapons?

The title of this forum is kinda self-explanatory. Is there a way to make certain types of mobs weak to a certain type of weapons? Is this possible? Thanks a lot!

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is absolutely possible…
Mon, 06/01/2020 - 14:05

This is absolutely possible since I have no idea what you want. In the code I provide for you I am making giving an entity more damage.

    @SubscribeEvent
    public void livingDamage(LivingDamageEvent event)
    {
        DamageSource source = event.getSource();
        LivingEntity entity = event.getEntityLiving();

        if (entity instanceof YourMob && source.isProjectile())
        {
            entity.attackEntityFrom(DamageSource.GENERIC, 50F);
        }
    }

50 is A LOT if you couldn't guess. Also if you play around with the code, don't use a projectile as the damage source, otherwise, you will loop the code and crash. You will obviously change, "YourMob" to your mob. But otherwise, the principle is the same. You can do the opposite (make your entity strong) by simply healing the entity or canceling the event. If you want that let me know. Good luck 😁.

Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks for the quick reply,…
Mon, 06/01/2020 - 14:14

Thanks for the quick reply, but how can I apply the code you've sent me to the weapon? Sorry, because I know nothing about custom coding without the help of Mcreator :(

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ya no problem, I believe…
Mon, 06/01/2020 - 14:21

Ya no problem, I believe that MCreator registers all of their classes to an event bus. Can you send over all of your code?

 

Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The codes of the weapons I…
Mon, 06/01/2020 - 14:33

The codes of the weapons I made? If so they are not finished yet, can I send over once the codes and the weapons are finished? It will take a while, but I'll send you when they are finished

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Do you want the entities to…
Mon, 06/01/2020 - 14:56

Do you want the entities to be weak to your sword? Because this code only works for projectiles unless we specify it for your sword.

Basically, what do you want your mob to be weak to?

Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well, I wanted the mobs to…
Mon, 06/01/2020 - 14:58

Well, I wanted the mobs to be weak to silver(my custom ore) melee weapons so is there anything that needs to change?

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes, some things need to…
Mon, 06/01/2020 - 15:14

Yes, some things need to change. But this also allows us to do some really cool things.

So here is something simple (if the player used a diamond sword),

    @SubscribeEvent
    public void livingDamage(LivingDamageEvent event)
    {
        DamageSource source = event.getSource();
        LivingEntity entity = event.getEntityLiving();
        if (entity instanceof AnbuEntity && source.getTrueSource() instanceof PlayerEntity)
        {
            PlayerEntity player = (PlayerEntity) source.getTrueSource();
            if (player.getItemStackFromSlot(EquipmentSlotType.MAINHAND).getItem() == Items.DIAMOND_SWORD)
            {
                entity.attackEntityFrom(DamageSource.GENERIC, 50F);
            }
        }
    }

Or alternatively, we can make so the mob is weak to all of your weapons,

    @SubscribeEvent
    public void livingDamage(LivingDamageEvent event)
    {
        DamageSource source = event.getSource();
        LivingEntity entity = event.getEntityLiving();
        if (entity instanceof AnbuEntity && source.getTrueSource() instanceof PlayerEntity)
        {
            PlayerEntity player = (PlayerEntity) source.getTrueSource();
            if (player.getItemStackFromSlot(EquipmentSlotType.MAINHAND).getItem() instanceof SwordItem)
            {
                SwordItem item = (SwordItem) player.getItemStackFromSlot(EquipmentSlotType.MAINHAND).getItem();
                if (item.getGroup() == Main.TAB) {
                    entity.attackEntityFrom(DamageSource.GENERIC, 50F);
                }
            }
        }
    }

We can do some other things but this is a start.

Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm messing around a bit…
Mon, 06/01/2020 - 15:19

I'm messing around a bit with Mcreator, I was wondering if this would work

messing with codes

Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
So how can I apply this to…
Mon, 06/01/2020 - 15:23

So how can I apply this to Mcreator? If you don't mind, can you also screenshot the procedure with Mcreator procedure blocks? Because I really really sorry but tbh I don't understand T_T

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well, I don't know if…
Mon, 06/01/2020 - 15:29

Well, I don't know if MCreator even has a LivingDamageEvent. But you can just put that code in your mob class. For an MCreator procedure, I will check and get back to you.

And no, your procedure will not work for these reasons;

1. You're not calling an event. You need this procedure to execute when a mob gets damaged.

2. There are not enough conditions, even if you had the procedure to execute correctly. You are not checking for the DamageSource, therefore, all sources (fall damage, projectiles, anvils, cactus, etc.) will kill your entity.

3. I have no clue what "Current entity" is referring to.

Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you very much! Man,…
Mon, 06/01/2020 - 15:42

Thank you very much! Man, you don't know how much I appreciated you. I'll definitely credit you on my mod's page, it doesn't matter if the procedure works or not, but I'll credit you because you are very open when it comes to helping others. Again, thank you so much!

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No problem, that code works …
Mon, 06/01/2020 - 15:58

No problem, that code works (I tested it). So if you have any issues let me know and we will fix it😁.

Joined Aug 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
A simple way using MCreator…
Fri, 06/12/2020 - 00:58

A simple way using MCreator's block code would be to

a. Make a procedure for attacks that have an if statement for the entity and make it deal damage

b. A, but with potion effects instead

c. A, but amplified by an enchantment