Jump to content

Reference problem intellij (1.18.2)


Seawarrior

Recommended Posts

in the following code, references isButtonDown and isKeyDown aren't working... please help me ! thx
 

package com.seawarrior.trueguns.item;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
@Mod("hk416item")
public class HK416Item extends Item implements IHK416Item {

    public HK416Item(Properties properties) {
        super(properties);
    }

    boolean LeftClick = false;
    boolean rKeyPressed = false;


    @SubscribeEvent
    public void onMouseInput(InputEvent.MouseInputEvent event) {

        if(event.getButton() == 0 && event.isButtonDown()) {
            LeftClick = true;
        }
    }

    @SubscribeEvent
    public void onKeyInput(InputEvent.KeyInputEvent event) {

        if(event.getKey() == InputConstants.KEY_R && event.isKeyDown()) {
            rKeyPressed = true;
        }
    }


    @Override
    public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {

        if(LeftClick) {
            // Logique clic gauche
            LeftClick = false;
        }

        if(rKeyPressed) {
            // Logique touche R
            rKeyPressed = false;
        }

        return InteractionResultHolder.consume(player.getItemInHand(hand));
    }

    private void zoom(Player player, double zoomFactor) {
        // Zoom logic
    }

    private void fire(Level world, Player player) {
        // Fire logic
    }

    // Variables cadence de tir
    private final int fireRate = 15;
    private int timeSinceLastShot = 0;

    // Rechargement
    private final int magAmmo = 30;
    private int reloadTime = 50;

    // Zoom
    private final double zoomFactor = 2.0;

    @Override
    public void onStoppedUsing(ItemStack stack, Level world, LivingEntity user, int remainingUseTicks, Player player) {
        timeSinceLastShot = 0;
        zoom(player, 1.0);
    }

}

 

Link to comment
Share on other sites

9 hours ago, Seawarrior said:

i annotated with SubscribeEvent look at the code

Read Paint_Ninja's message again, there's an additional requirement that you're not meeting.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.



×
×
  • Create New...

Important Information

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