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:
package net.mcreator…
Sun, 05/31/2020 - 17:47
package net.mcreator.yourmodid.procedures;

import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.common.MinecraftForge;

import net.minecraft.entity.player.ServerPlayerEntity;

import net.mcreator.yourmodid.YourModIdElements;
import net.minecraftforge.event.entity.living.LivingDamageEvent;

@YourModIdElements.ModElement.Tag
public class EntityProjectileImmunityProcedure extends YourModIdElements.ModElement {
	public EntityProjectileImmunityProcedure(YourModIdElements instance) {
		super(instance, 148);
		MinecraftForge.EVENT_BUS.register(this);
	}

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
	}

    @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
        }
    }
}

That should work

Last seen on 17:16, 16. Mar 2024
Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
also i have already…
Sun, 05/31/2020 - 18:06

also i have already submitted this five days ago so they'll officially implement this soon.

Last seen on 17:16, 16. Mar 2024
Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
pretty sure new error is…
Sun, 05/31/2020 - 18:08

pretty sure new error is coming soon...

//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:
That is commented out, so no…
Sun, 05/31/2020 - 18:12

That is commented out, so no error

Last seen on 17:16, 16. Mar 2024
Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I don't mean that im not…
Sun, 05/31/2020 - 18:15

I don't mean that im not dumb

that person doesn't know how to java

Last seen on 17:16, 16. Mar 2024
Joined May 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
so you should be more…
Sun, 05/31/2020 - 18:16

so you should be more beginner-friendly, think their way.....

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh lmao! Yeah, @Scootied…
Sun, 05/31/2020 - 18:17

Oh lmao! Yeah, @Scootied. Post code when you think you are done, please.

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh yeah sorry, @Scootied, do…
Sun, 05/31/2020 - 18:21

Oh yeah sorry, @Scootied, do you want anything else to happen to the player?

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alright, thank you again for…
Mon, 06/01/2020 - 16:27

Alright, thank you again for helping but this is the error I got this time: https://imgur.com/a/5p8jeXG

This is the code behind it: https://imgur.com/a/Mzf18wn

Sorry for taking so long I was a bit busy. I changed all of the mod id parts into my mod id. If I got anything wrong, just tell me.

(Also I removed the comment due to aritsts "pretty sure an error is coming up" comment.

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yeah, that is not how you do…
Mon, 06/01/2020 - 16:30

Yeah, that is not how you do it. I really need you to paste to me everything in your procedure class, not the actual procedure. Don't use custom snippets.

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alright, sorry. I turned it…
Mon, 06/01/2020 - 16:46

Alright, sorry. I turned it into a custom elements. I apologize if Im still doing it wrong I've never really experimented outside of just procedures. Heres the error screenshot: https://imgur.com/a/KkJLUe8

Heres the code:

package net.mcreator.scootys_pvz;

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);
    }

    @Override
    public void initElements() {
    }

    @Override
    public void init(FMLCommonSetupEvent event) {
    }

    @Override
    public void serverLoad(FMLServerStartingEvent event) {
    }
}

package net.mcreator.scootys_pvz.procedures;

import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.common.MinecraftForge;

import net.minecraft.entity.player.ServerPlayerEntity;

import net.mcreator.scootys_pvz.ScootysPvzElements;
import net.minecraftforge.event.entity.living.LivingDamageEvent;

@YourModIdElements.ModElement.Tag
public class EntityProjectileImmunityProcedure extends ScootysPvzElements.ModElement {
    public EntityProjectileImmunityProcedure(ScootysPvzElements instance) {
        super(instance, 148);
        MinecraftForge.EVENT_BUS.register(this);
    }

    public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
    }

    @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:
package net.mcreator.scootys…
Mon, 06/01/2020 - 17:01

package net.mcreator.scootys_pvz;

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
        }
    }
}

 

 

Try that

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
OH ALSO YOU NEED TO DO THE…
Mon, 06/01/2020 - 17:01

OH ALSO YOU NEED TO DO THE IMPORTS