Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5 official mappings] Custum Item use method help (solved)


reasure
 Share

Recommended Posts

 

public class BlazeAndSteel extends FlintAndSteelItem {
    public BlazeAndSteel(Properties properties) {
        super(properties.fireResistant().stacksTo(1).durability(128));
    }

    @Override
    public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
        ItemStack item = player.getItemInHand(hand);
        if (!world.isClientSide()) {
            ActionResultType result = fireEntity(item, player, player, hand);
            return new ActionResult<>(result, item);
        }
        return super.use(world, player, hand);
    }

    @Override
    public ActionResultType interactLivingEntity(ItemStack item, PlayerEntity player, LivingEntity target, Hand hand) {
        if (!target.level.isClientSide()) {
            return fireEntity(item, player, target, hand);
        }
        return super.interactLivingEntity(item, player, target, hand);
    }

    protected ActionResultType fireEntity(ItemStack item, PlayerEntity player, LivingEntity target, Hand hand) {
        if (!target.fireImmune()) {
            item.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(hand));
            player.playSound(SoundEvents.FLINTANDSTEEL_USE, 1.0f, random.nextFloat() * 0.4f + 0.8f);
            int fireTick = random.nextInt(10 * 20 + 1) + 20;
            if (fireTick > target.getRemainingFireTicks()) {
                target.setSecondsOnFire(fireTick);
            }
            target.hurt(DamageSource.ON_FIRE, random.nextInt(4));
            return ActionResultType.CONSUME;
        }
        return ActionResultType.FAIL;
    }
}

It has three actions

1. use on block -> act like flint and steel (useOn in FlintAndSteelItem.class)

2. use on entity -> light entity on fire (interactLivingEntity)

3. use on air -> light player on fire (use)

 

When I use it on entity (case 2), it light both entity and player on fire.

But I want to make it light only entity on fire.

Give me help please.

Edited by reasure
Link to comment
Share on other sites

  • reasure changed the title to [1.16.5 official mappings] Custum Item use method help
20 hours ago, diesieben07 said:

That is strange, I can't see why it would do that. I would recommend using the debugger.

I solved this problem by using

return ActionResultType.CONSUME;

in interactLivingEntity instead of using super.interactLivingEntity()

Link to comment
Share on other sites

  • reasure changed the title to [1.16.5 official mappings] Custum Item use method help (solved)

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.