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.

[1.16.5] [Forge 36.2.34] Cast Custom Item In Vanilla Honey Bottle Class

Featured Replies

Posted

Hi i would like some help to cast my custom item into a method Vanilla Minecraft uses to return an empty bottle to the player after the use, the class i'm using as pattern it's "HoneyBottleItem" (forge_snapshot > net > minecraft > item > HoneyBottleItem).

The issue i'm occurring it's not recognizing the custom item of the mod, substituted with the glass bottle of Minecraft, here's my version:

 

package net.alexmaster75.tea.item.custom;

import net.alexmaster75.tea.item.TeaItems;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.stats.Stats;
import net.minecraft.world.World;

public class TeaCupConsume extends Item {
    public TeaCupConsume(Properties properties) {
        super(properties);
    }

    public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) {
        super.onItemUseFinish(stack, worldIn, entityLiving);
        if (entityLiving instanceof ServerPlayerEntity) {
            ServerPlayerEntity serverplayerentity = (ServerPlayerEntity)entityLiving;
            CriteriaTriggers.CONSUME_ITEM.trigger(serverplayerentity, stack);
            serverplayerentity.addStat(Stats.ITEM_USED.get(this));
        }



        if (stack.isEmpty()) {
            return new ItemStack(TeaItems.EMPTY_CUP); // <- Error: Required type: IItemProvider
																// Provided: RegistryObject <net.minecraft.item.Item>
        } else {
            if (entityLiving instanceof PlayerEntity && !((PlayerEntity)entityLiving).abilities.isCreativeMode) {
                ItemStack itemstack = new ItemStack(TeaItems.EMPTY_CUP); // <- Same error
                PlayerEntity playerentity = (PlayerEntity)entityLiving;
                if (!playerentity.inventory.addItemStackToInventory(itemstack)) {
                    playerentity.dropItem(itemstack, false);
                }
            }

            return stack;
        }
    }

}

^ My Version

It may seem a stupid error but i'm not getting the solution

Thanks

Edited by Alexmaster75
Removed Vanilla code

You need to actually get the Item instance form the registry (by calling #get).

Also, DON'T SHARE VANILLA CODE! You do not have the rights to share it, and we can all look it up for ourselves.

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.