How to make projectiles go through blocks?

Started by HydratedMite on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make projectiles go through blocks?

I want to make a projectile that can hit entities through blocks without destroying the blocks. How do I do this?

Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Maybe when it hits a block…
Tue, 07/09/2024 - 21:06

Maybe when it hits a block it checks if there is an entity nearby and if so damages them? Or you could check what direction it was moving and when it hits a block it spawns another a few blocks forward.

Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
But I want the projectile to…
Tue, 07/09/2024 - 21:26

But I want the projectile to keep going until the end of its range (which is pretty long), completely ignoring any and all blocks it collides with

Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I don't think that's…
Tue, 07/09/2024 - 21:40

I don't think that's possible, as far as I know. Sorry

Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm doing something similar…
Sun, 07/28/2024 - 23:45

I'm doing something similar and i found that if you use a ray trace to find the side of the block you are looking at you can then turn that into a number variable which you can then run through and "if" scenario you can make it so it spawns an arrow at a location relative to the block you hit (spawns it on the other side of the block), now I've found a bug with this solution that i have yet to find a fix for is that it is required to be a global variable where as for the ideal situation it would be a player persistent variable or some sort of readable nbt data inside the block itself. I'll let you know if i find anything

Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can use a custom entity…
Thu, 08/08/2024 - 22:09

You can use a custom entity instead, and shoot it forwards.

You can add the following line of code to your custom entity to make it go through blocks (might not work, depending on version):

public void tick() {
      this.noPhysics = true;
      super.tick();
      this.noPhysics = false;
      this.setNoGravity(true);
   }

Just have it deal damage to any entities that collide with it.