Jump to content

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


Ooooscar

Recommended Posts

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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