Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[SOLVED] [1.16.2] Projectile that extinguishes fire, not working?

Featured Replies

Posted

I want to add a modded Snowball entity which should extinguish fire blocks.

(replace the FireBlock with AirBlock?) whenever it is inside a FireBlock.

 

 

Here's my code in class ModSnowballEntity (which is not working😞)

So fire blocks are transparent blocks. The class Entity has a method called onInsideBlock, maybe I should utilize that method?

 

I know that there must be some problems with the code below (I don't think it will work even if the block is changed to Stone or something else)

public class ModSnowballEntity extends ModProjectileItemEntity {
  // ...
    protected void onBlockHit(BlockRayTraceResult result) {
        BlockPos pos = result.getPos();
        BlockState ibs = world.getBlockState(pos);
        if (ibs.getBlock() instanceof FireBlock) {
            world.removeBlock(pos, true);
        }
    }
  // ...
}

 

Here is the complete code of ModProjectileItemEntity (I copied most of it from the vanilla ProjectileItemEntity):

public abstract class ModProjectileItemEntity extends ProjectileItemEntity {
    public ModProjectileItemEntity(EntityType<? extends ProjectileItemEntity> type, World worldIn) {
        super(type, worldIn);
    }
    public ModProjectileItemEntity(EntityType<? extends ProjectileItemEntity> type, double x, double y, double z, World worldIn) {
        super(type, x, y, z, worldIn);
    }
    public ModProjectileItemEntity(EntityType<? extends ProjectileItemEntity> type, LivingEntity livingEntityIn, World worldIn) {
        super(type, livingEntityIn, worldIn);
    }
  
    // Called when the Projectile hits an entity
    protected void onEntityHit(EntityRayTraceResult result) {
        super.onEntityHit(result);
        Entity entity = result.getEntity();
        int i = entity instanceof BlazeEntity ? 3 : 0;
        entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.func_234616_v_()), (float)i);
    }
    // Called when the Projectile hits a block or entity
    protected void onImpact(RayTraceResult result) {
        super.onImpact(result);
        if (!this.world.isRemote) {
            this.world.setEntityState(this, (byte)3);
            this.remove();
        }
    }
}

 

Sorry I'm new to modding and I have been asking questions frequently...

Edited by Ooooscar
solved issue

Use onInsideBlock. onImpact, onEntityHit, and onBlockHit don't work because the entity is not actually colliding with the fire block.

  • Author

I solved the problem!!!

Here's my code:

public class ModSnowballEntity extends ProjectileItemEntity {
    private static boolean is_crit = false;
    // ...
  
    // Called when the ModSnowball hits a block
    // If it's a critical shot: Extinguish fire
    protected void func_230299_a_(BlockRayTraceResult result) {
        super.func_230299_a_(result);
        if (is_crit) {
            BlockPos pos = result.getPos();
            Direction direction = result.getFace();

            BlockPos pos_offset = pos.offset(direction);
            Block block_offset = this.world.getBlockState(pos_offset).getBlock();

            boolean face_can_catch_fire = ((FireBlock)Blocks.FIRE).canCatchFire(this.world, pos, direction);

            if (block_offset instanceof FireBlock && (face_can_catch_fire || (direction.equals(Direction.UP)))) {
                playSound(SoundEvents.BLOCK_FIRE_EXTINGUISH, 0.5F, 2.6F + (rand.nextFloat() - rand.nextFloat()) * 0.8F);
                this.world.removeBlock(pos_offset, false);
            }
        }
    }

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.