How to make projectile pass through block?

Started by alessandro8888 on

Topic category: Help with modding (Java Edition)

Last seen on 21:46, 11. Jun 2024
Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make projectile pass through block?

Hello, I'm trying to find how I could make a procedure that would allow a projectile to pass through a block below a certain hardness value. I've already figured out the latter set-up, but I have no idea which code blocks or whatever allows the projectile through without destroying the block or the projectile?

Last seen on 03:32, 26. Jun 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can make your projectile…
Thu, 06/06/2024 - 15:48

You can make your projectile pass through blocks, but I'm not sure if there's a great way to do so based on the block's hardness level. Basically, you need to lock your projectile element, and replace this section:

@Override
public void tick() {
super.tick();
FlameOrbFlyingProcedure.execute(this.level(), this.getX(), this.getY(), this.getZ());
if (this.inGround)
this.discard();
}

With this:

@Override
public void baseTick() {
super.baseTick();
FlameOrbFlyingProcedure.execute(this.level(), this.getX(), this.getY(), this.getZ());
}
public void tick() {
this.noPhysics = true;
super.tick();
this.noPhysics = false;
this.setNoGravity(true);
}

Where 'FlameOrbFlyingProcedure' is replaced with your projectile's 'on tick' procedure. You can remove the 'nogravity' bit if you want it still fly like a normal projectile.

You may also want to make your projectile a living entity, rather than a projectile element; there's some weird stuff with how projectile elements are rendered when their physics are disabled, and you can make a living entity that behaves like a projectile when it detects another entity nearby.