Jump to content

[SOLVED] How I can cancel an entity's InteractionResult event?


FantaLaTone

Recommended Posts

Hello I have an entity with mobInteraction event. When right clicked it with a specific item mob tells player to mob's gender but when I right clicked with item it tells mob's gender and also process other interactions how I can return after tells player mob's gender?

 

Here's my code :

@Override
    public InteractionResult mobInteract(Player player, InteractionHand hand) {
        ItemStack itemstack = player.getItemInHand(hand);
        Item item = itemstack.getItem();
        Level world = player.level;

        if (world.isClientSide) {
            if (item == ModItems.GRIFFIN_GENDER_TOME.get()) {
                player.sendMessage(new TextComponent("")
                        .append(this.getGender() == 0 ? "§bBoy" : "§dGirl")
                        , player.getUUID());
                return InteractionResult.SUCCESS;
                // RETURN AFTER THIS BUT IT'S NOT WORKING
            }
        }

        if (item == Items.PORKCHOP || item == Items.BEEF && !isTame()) {
            if (this.level.isClientSide) {
                return InteractionResult.CONSUME;
            } else {
                if (!player.getAbilities().instabuild) {
                    itemstack.shrink(1);
                }

                if (!ForgeEventFactory.onAnimalTame(this, player) && this.random.nextInt(8) == 0) {
                    if (!this.level.isClientSide) {
                        super.tame(player);
                        this.navigation.recomputePath();
                        this.setTarget(null);
                        this.level.broadcastEntityEvent(this, (byte)7);
                        setSitting(true);
                    }
                }

                return InteractionResult.SUCCESS;
            }
        }

        if(isTame() && !this.level.isClientSide && hand == InteractionHand.MAIN_HAND) {
            setSitting(!isSitting());
            return InteractionResult.SUCCESS;
        }

        if (itemstack.getItem() == Items.PORKCHOP || itemstack.getItem() == Items.BEEF) {
            return InteractionResult.PASS;
        }

        return super.mobInteract(player, hand);
    }

 

Edited by FantaLaTone
Link to comment
Share on other sites

I solved the problem by just rearrengin if statements order

if (item == ModItems.GRIFFIN_GENDER_TOME.get()) {
            if (world.isClientSide) {
                player.sendMessage(new TextComponent("")
                                .append(this.getGender() == 0 ? "§bBoy" : "§dGirl")
                        , player.getUUID());
            }
            return InteractionResult.SUCCESS;
        }

 

Link to comment
Share on other sites

  • FantaLaTone changed the title to [SOLVED] How I can cancel an entity's InteractionResult event?

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.



×
×
  • Create New...

Important Information

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