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:
I assume you are talking…
Sun, 05/31/2020 - 00:43

I assume you are talking about arrows? Here is something I came up with on the spot. KEEP IN MIND IN THIS SNIPPET OF CODE YOU CAN ADD CHECKS FOR ARMOR AND/OR OTHER PROJECTILE ENTITIES!

    @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 05:23, 31. Jul 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you for helping but if…
Sun, 05/31/2020 - 16:09

Thank you for helping but if I may ask, how to I plug this into my procedures with the custom code snippet? They never seem to work no matter what I do with them.

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
To plug it in, Shocking…
Sun, 05/31/2020 - 16:41

To plug it in, Shocking Artist correct me if I am wrong, but since you are subscribing to an event I believe you can just put that in your entity class. But you are probably better off creating a forge event subscriber for your mod, so I believe you can create a custom element that does that? I would ask Shocking Artist because I haven't used MCreator in a while.

LivingDamageEvent is a forge event so you are going to want to register the class with the forge event bus,

@Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)

put that on top, and change Main.MODID to your mod id.

You may have to register the class in the main class, but I believe MCreator actually does that. I would check anyway though and use this bit,

		MinecraftForge.EVENT_BUS.register(new ForgeEventSubscriber());

 I am not sure how MCreator registers there event so what I would do in your situation. 

Step 1: Create a Procedure and give it any event.

Step 2: Go into the code and switch the events around and add in the code snippet.

Step 3: That's all you have to do as long as MCreator registers procedures like a forge event subscriber

Sorry if that seems confusing but because I haven't been on MCreator for a while, it is hard for me to know the exact steps but you should be able to figure out with some tweaking.

 

Now for your error can you post some code and take an image of the procedure.

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
After adding those two lines…
Sun, 05/31/2020 - 17:06

After adding those two lines and changing what MCreator told me to change, this is the last error:

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I apologize, it didnt upload…
Sun, 05/31/2020 - 17:07

I apologize, it didnt upload properly: 

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
mcreator will restore the…
Sun, 05/31/2020 - 17:24

mcreator will restore the code eyery time and errors will arise

lock the code

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
mcreator will restore the…
Sun, 05/31/2020 - 17:24

mcreator will restore the code eyery time and errors will arise

lock the code

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok from that error there are…
Sun, 05/31/2020 - 17:28

Ok from that error there are a lot of things that are wrong you need to share code ASAP! Your game is going to crash. You are setting the MODID to a variable that I believe isn't there. Your MODID needs to be a String. There is nothing I can do without code

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
But yes @Shocking Artist…
Sun, 05/31/2020 - 17:29

But yes @Shocking Artist. Lock the code

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alright i examined the code…
Sun, 05/31/2020 - 17:40

Alright i examined the code i dont know how Mcreator's registration rules work.

I believe it should be something like this

@TestingPrpceduresModElements.ModElement.Tag
public class LolProcedure extends TestingPrpceduresModElements.ModElement {
	public LolProcedure(TestingPrpceduresModElements instance) {
		super(instance, 1);
		MinecraftForge.EVENT_BUS.register(this);
	}

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure Lol!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		if (entity instanceof LivingEntity)
			((LivingEntity) entity).addPotionEffect(new EffectInstance(Effects.SPEED, (int) 60, (int) 1));
	}

	@SubscribeEvent
	public void onEntityAttacked(LivingAttackEvent event) {
		if (event != null && event.getEntity() != null) {
			Entity entity = event.getEntity();
			Entity sourceentity = event.getSource().getTrueSource();
			int i = (int) entity.getPosX();
			int j = (int) entity.getPosY();
			int k = (int) entity.getPosZ();
			World world = entity.world;
			java.util.HashMap<String, Object> dependencies = new java.util.HashMap<>();
			dependencies.put("x", i);
			dependencies.put("y", j);
			dependencies.put("z", k);
			dependencies.put("world", world);
			dependencies.put("entity", entity);
			dependencies.put("sourceentity", sourceentity);
			dependencies.put("event", event);
			this.executeProcedure(dependencies);
		}
	}
}

when entity damaged give speed?