I want to make it so the player doesn't take damage from projectile entities

Started by Scootied on

Topic category: Help with modding (Java Edition)

Last seen on 05:23, 31. Jul 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I want to make it so the player doesn't take damage from projectile entities

Says it all in the title. No matter what I do, the same 2 hearts of damage stays the same for me. It seems to have to real fix and is extremely aggravating. There seems to be no work around for this and it makes the mod unplayable at times. Please, if there is anyway to make these projectiles not affect players. Please tell me.

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
import net.minecraft.entity…
Mon, 06/01/2020 - 17:02
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;

Add these up top

Make sure the code is locked

 

Last seen on 05:23, 31. Jul 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alright, only 2 errors left:…
Mon, 06/01/2020 - 17:12

Alright, only 2 errors left: https://imgur.com/a/fbvjAq5

I just pasted it and added the imports.

package net.mcreator.scootys_pvz;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

@ScootysPvzModElements.ModElement.Tag
public class PeapodNoDamageProper extends ScootysPvzModElements.ModElement {
    /**
     * Do not remove this constructor
     */
    public PeapodNoDamageProper(ScootysPvzModElements instance) {
        super(instance, 531);

        MinecraftForge.EVENT_BUS.register(this);
    }

    @Override
    public void initElements() {
    }

    @Override
    public void init(FMLCommonSetupEvent event) {
    }

    @Override
    public void serverLoad(FMLServerStartingEvent event) {
    }

 

    @SubscribeEvent
    public void onDamageEvent(LivingDamageEvent event)
    {
        DamageSource source = event.getSource();
        if (source.getImmediateSource() instanceof AbstractArrowEntity)
        {
            event.setCanceled(true);
            //DO WHATEVER YOU WANT HERE. I.e. GIVE PLAYER MAGIC. idk
        }
    }
}
 

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You need to import these …
Mon, 06/01/2020 - 17:19

You need to import these

import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.entity.living.LivingDamageEvent;

 

Last seen on 05:23, 31. Jul 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alright, now its coming up…
Mon, 06/01/2020 - 17:25

Alright, now its coming up with this instead: https://imgur.com/a/uMKtocv

Code:

package net.mcreator.scootys_pvz;

import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

@ScootysPvzModElements.ModElement.Tag
public class PeapodNoDamageProper extends ScootysPvzModElements.ModElement {
    /**
     * Do not remove this constructor
     */
    public PeapodNoDamageProper(ScootysPvzModElements instance) {
        super(instance, 531);

        MinecraftForge.EVENT_BUS.register(this);
    }

    @Override
    public void initElements() {
    }

    @Override
    public void init(FMLCommonSetupEvent event) {
    }

    @Override
    public void serverLoad(FMLServerStartingEvent event) {
    }

 

    @SubscribeEvent
    public void onDamageEvent(LivingDamageEvent event)
    {
        DamageSource source = event.getSource();
        if (source.getImmediateSource() instanceof AbstractArrowEntity)
        {
            event.setCanceled(true);
            //DO WHATEVER YOU WANT HERE. I.e. GIVE PLAYER MAGIC. idk
        }
    }
}
 

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well then add these imports…
Mon, 06/01/2020 - 17:31

Well then add these imports...

import net.minecraft.util.DamageSource;
import net.minecraftforge.common.MinecraftForge;

 

Last seen on 05:23, 31. Jul 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
HOLY! IT WORKS! Thank you so…
Mon, 06/01/2020 - 17:41

HOLY! IT WORKS! Thank you so much dude you have no idea how big this is for me. The mod will improve tenfold with this. But I do have 1 more request, do you think its possible to also disable the knockback you get?

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
HOLY! IT WORKS! Thank you so…
Mon, 06/01/2020 - 17:48

HOLY! IT WORKS! Thank you so much dude you have no idea how big this is for me

Thanks...

But I do have 1 more request, do you think its possible to also disable the knockback you get?

Yeah, I thought that would happen. But to answer, maybe, I am a little fried right now? I'll get back to you.

Last seen on 05:23, 31. Jul 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Of course. Im already really…
Mon, 06/01/2020 - 17:50

Of course. Im already really happy with just this. Anytime if your able to get back to me. Thanks again

Well then add these imports…
Tue, 06/02/2020 - 10:51

Well then add these imports...

You can use Ctrl + W in code editors to autoimport too ;)

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
👍 
Tue, 06/02/2020 - 13:10

👍 

Last seen on 06:22, 13. Mar 2023
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I know this is old as hell…
Mon, 05/09/2022 - 04:38

I know this is old as hell but I was looking this up and I solved this in a much easier way if anyone comes across this. The entity is still hit, but all damage is negated. Add this procedure then add an EntityHit procedure to your projectile and add damage from the the player that way, or effects if you want the projectile to have no damage. The tag can be whatever you want, just add whatever projectile you want to have no damage to it. You just have to edit the tag code and enter the projectile entity to it manually as mcreator won't let you add to it.

Procedure