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

Here is some base code to work with on "picking up" an item.  You can look for attributes on the item picked up, and apply effects as you like.

 

Spoiler
@SubscribeEvent
    public void onItemPickup(PlayerEvent.ItemPickupEvent event) {
        ItemStack itemStack = event.getStack();
        String itemNamespace = "";
        String itemPath = "";
        Item item = itemStack.getItem(); //Somehow translates to the item name (minecraft:sand is "sand" here)
        try {
            itemNamespace = Objects.requireNonNull(item.getRegistryName()).getNamespace();
            itemPath = Objects.requireNonNull(item.getRegistryName()).getPath();
        } catch (Exception e) {
            LOGGER.info("Unable to get item namespace or path.");
        }
        String itemId = itemNamespace + ":" + itemPath;
        ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
        String playerName = player.getName().getUnformattedComponentText();  //Just player name.

        Minecraft mc = Minecraft.getInstance();
        if(mc.player != null) {
            //mc.player.sendChatMessage("[" + playerName + "][" + player.getPlayerIP() + "] picked up [" + itemId + "][" + itemStack.getCount() + "]");
            LOGGER.info("[" + playerName + "] picked up [" + itemId + "]");
        }
    }

 

 

first you mix Server and Client Side code,
since you cast the Player of the Event to a ServerPlayerEntity which is Server-Side
and then you use the Minecraft class which is completely Client Side
you should use a instanceof check bevor like:

PlayerEntity player = event.getPlayer();
if (player instanceof ServerPlayerEntity) {
  // do server stuff here
} else if (player instanceof ClientPlayerEntity) {
  // do client stuff here
}

if you cleaned up your code (which you should definitely do),
you could use PlayerEntity#addEffect

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.