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)

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.

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

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.

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

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

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.

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?

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.

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.

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

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

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