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

Hello Guys,
I want to do when a player right click to certain item do something.

But When I do PlayerInteractEvent.LeftClickEmpty it works.

Can anyone help me ? (FORGE 1.15.2)

 public static void itemUpgrade(PlayerInteractEvent.RightClickEmpty event) {



              PlayerEntity player = event.getPlayer();

              String msg = TextFormatting.RED + "Success!";
              String msg2 = TextFormatting.RED + "Failed!";


              if (player.getHeldItemMainhand().getItem() == RegistryHandler.DRAGON_STEEL_SWORD.get() && player.getHeldItemOffhand().getItem() == RegistryHandler.DRAGON_STEEL.get()) {
                  gblnDiablo.LOGGER.info("Player tried upgrade");

                  if (Math.random() < 0.7D) {
                      ItemStack giveItem = new ItemStack(RegistryHandler.DRAGON_STEEL_SWORD_1.get(), 1);


                      player.sendMessage(new StringTextComponent(msg));
                      giveItem.setCount(1);
                      ItemHandlerHelper.giveItemToPlayer(player, giveItem);
                  } else {


                      ((PlayerEntity) player).inventory.clearMatchingItems(p -> new ItemStack(RegistryHandler.DRAGON_STEEL_SWORD.get(), (int) (1)).getItem() == p.getItem(),
                              (int) 1);

                      ((PlayerEntity) player).inventory.clearMatchingItems(p -> new ItemStack(RegistryHandler.DRAGON_STEEL.get(), (int) (1)).getItem() == p.getItem(),
                              (int) 1);

                     /* player.inventory.clearMatchingItems((p) -> {
                          return (new ItemStack(player.getHeldItemMainhand().getItem(), 1)).getItem() == p.getItem();
                      }, 1); */

                    /*  player.inventory.clearMatchingItems((p) -> {
                          return (new ItemStack(player.getHeldItemOffhand().getItem(), 1)).getItem() == p.getItem();
                      }, 1); */

                      player.sendMessage(new StringTextComponent(msg2));


                  }
              }
              }

 

Edited by mbkgr

  • Author
12 minutes ago, ChampionAsh5357 said:

Read the javadoc on the event. You're gonna need to send a packet.

Thank you for reply.

Where can I find it ? And also how can I find the other event usages ?

35 minutes ago, mbkgr said:

Where can I find it ? And also how can I find the other event usages ?

You can locate the class in the source or open it directly by clicking on the class name using whatever method your IDE specifies.

  • Author
27 minutes ago, ChampionAsh5357 said:

You can locate the class in the source or open it directly by clicking on the class name using whatever method your IDE specifies.

Thank you I found it but I cant figured it out... How can I solve it ?

  • Author
22 hours ago, ChampionAsh5357 said:

I solved it.But there is a another problem.When player does event, event triggers 4 time.How can I solve that ?
 

@SubscribeEvent
        public static void rightClick(PlayerInteractEvent.RightClickItem event)
        {
            PlayerEntity player = event.getPlayer();

            if (player.getHeldItemMainhand().getItem() == Items.DIAMOND_ORE && player.getHeldItemOffhand().getItem() == Items.COAL)
            {
                gblnDiablo.LOGGER.info("Player tried to upgrade");
                ItemStack giveItem = new ItemStack(Items.DIAMOND, 1);
                player.inventory.addItemStackToInventory(giveItem);
            }
        }

 

  • Author
48 minutes ago, ChampionAsh5357 said:

'This event is fired on both sides before the player triggers'. Since it holds logic, it should be properly delegated to only execute on the server.

I have two classes, one ServerEvent and the other one is ClientEvent.So I need to use ServerEvent and OnlyIn(DIST.DEDICATED_SERVER) Is that right ?

16 minutes ago, mbkgr said:

So I need to use ServerEvent and OnlyIn(DIST.DEDICATED_SERVER) Is that right ?

No, those refer to the physical side. You should only have one instance of an event (except in very specific cases). Since this code is not specific to a physical side, there should be no sided annotations. That falls under Code Style 6. The linked doc page I sent you earlier was supposed to be for you to understand about World#isRemote which is held in every entity instance and then implement.

  • Author
26 minutes ago, ChampionAsh5357 said:

No, those refer to the physical side. You should only have one instance of an event (except in very specific cases). Since this code is not specific to a physical side, there should be no sided annotations. That falls under Code Style 6. The linked doc page I sent you earlier was supposed to be for you to understand about World#isRemote which is held in every entity instance and then implement.

I understand my mistake on that document It's OK now.Thank you so much.

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.