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.

Featured Replies

Posted

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

}

 

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.

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.