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

Started by Scootied on

Topic category: Help with Minecraft modding (Java Edition)

Active 7 months ago
Joined Mar 2019
Points:
737

User statistics:

  • Modifications: 2
  • Forum topics: 9
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 49
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.

Active 3 years ago
Joined Sep 2019
Points:
963

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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

Active 3 weeks ago
Joined May 2019
Points:
1199

User statistics:

  • Modifications: 0
  • Forum topics: 13
  • Wiki pages: 2
  • MCreator plugins: 1
  • Comments: 844
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.

Active 3 weeks ago
Joined May 2019
Points:
1199

User statistics:

  • Modifications: 0
  • Forum topics: 13
  • Wiki pages: 2
  • MCreator plugins: 1
  • Comments: 844
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

Active 3 years ago
Joined Sep 2019
Points:
963

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
That is commented out, so no…
Sun, 05/31/2020 - 18:12

That is commented out, so no error

Active 3 weeks ago
Joined May 2019
Points:
1199

User statistics:

  • Modifications: 0
  • Forum topics: 13
  • Wiki pages: 2
  • MCreator plugins: 1
  • Comments: 844
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

Active 3 weeks ago
Joined May 2019
Points:
1199

User statistics:

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

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

Active 3 years ago
Joined Sep 2019
Points:
963

User statistics:

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

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

Active 3 years ago
Joined Sep 2019
Points:
963

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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?

Active 7 months ago
Joined Mar 2019
Points:
737

User statistics:

  • Modifications: 2
  • Forum topics: 9
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 49
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.

Active 3 years ago
Joined Sep 2019
Points:
963

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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.

Active 7 months ago
Joined Mar 2019
Points:
737

User statistics:

  • Modifications: 2
  • Forum topics: 9
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 49
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
        }
    }
}
 

Active 3 years ago
Joined Sep 2019
Points:
963

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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

Active 3 years ago
Joined Sep 2019
Points:
963

User statistics:

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

OH ALSO YOU NEED TO DO THE IMPORTS