Jump to content

Remove Items from creative tabs


Julian Texo

Recommended Posts

I'm trying to remove Items from creative tabs. But the method setCreativeTab() is no longer present in the Item class.

Is there a new method/new way of doing that?

I have tried this (which gives me an error on startup (UnsupportedOperationException: null)

@SubscribeEvent
    public static void removeItemsFromCreativeTabs(FMLCommonSetupEvent event){
        for (Item item:ForgeRegistries.ITEMS) {
            if (item.getName(new ItemStack(item)).getString().equals("Wooden Pickaxe")){
                item.getCreativeTabs().clear();
            }
        }
    }

 

Link to comment
Share on other sites

The method you are using returns an unmodifiable list in its default implementation so you can't clear it.

If you want to modify the actual data, you will need to use an access transformer to make the Item.category field public

https://forge.gemwire.uk/wiki/Access_Transformers

But there is no guarantee the Item actually uses that field.

An item can override getCreativeTags() to do something else (vanilla items don't do this).

 

You should probably also be aware that Mojang are changing how this works in 1.19.3

https://www.minecraft.net/en-us/article/minecraft-snapshot-22w42a

  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

  • 3 months later...
On 10/25/2022 at 6:56 AM, warjort said:

An item can override getCreativeTags() to do something else (vanilla items don't do this).

`getCreativeTags()` or `getCreativeTabs()`?

 

Quote

If you want to modify the actual data, you will need to use an access transformer to make the Item.category field public

https://forge.gemwire.uk/wiki/Access_Transformers

Isn't reflection a viable option? It doesn't seem complicated.

Edited by badkraft
added question
Link to comment
Share on other sites

On 10/25/2022 at 6:12 AM, Julian Texo said:

I'm trying to remove Items from creative tabs. But the method setCreativeTab() is no longer present in the Item class.

Is there a new method/new way of doing that?

I have tried this (which gives me an error on startup (UnsupportedOperationException: null)

@SubscribeEvent
    public static void removeItemsFromCreativeTabs(FMLCommonSetupEvent event){
        for (Item item:ForgeRegistries.ITEMS) {
            if (item.getName(new ItemStack(item)).getString().equals("Wooden Pickaxe")){
                item.getCreativeTabs().clear();
            }
        }
    }

 

Rather than iterating all of the items you want to remove, you can set up place holders in your mod code:

	//	get a handle on items we want to remove from tabs
	@ObjectHolder("minecraft:wooden_sword")
	public static Item WOODEN_SWORD = null;

... now, in your event, instead of iterating the collection, you can test whether the item is assigned:

LOGGER.debug("Item :: WOODEN SWORD [" + (WOODEN_SWORD != null) + "]");

My log produces the following line:

Quote

28Jan2023 12:23:32.287] [Worker-Main-17/DEBUG] [com.badkraft.foundations.Foundations/]: Item :: WOODEN SWORD [true]

 

Link to comment
Share on other sites

I used reflection to set the `Item.category` to `null` which removes the item from a `CreativeModeTab`. Here's the class:

import com.mojang.logging.LogUtils;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import org.slf4j.Logger;

import java.lang.reflect.Field;

public class ItemReflector {
    private static final Logger LOGGER = LogUtils.getLogger();
    private static final String CATEGORY = "category";
    private static final Class<Item> CLASS = Item.class;

    private final Field category;

    public ItemReflector() {
        LOGGER.debug("Reflecting (" + CLASS + ")");

        Field catField = null;

        try {
            catField = getField(CATEGORY);
        } catch (NoSuchFieldException e) {
            LOGGER.error(e.getMessage(), e);
        }

        category = catField;
    }

    public void setItemCategory(Item item, CreativeModeTab tab) {
        try{
            category.set(item, tab);
        } catch (IllegalAccessException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }

    private Field getField(String fieldName) throws NoSuchFieldException {
        Field field = CLASS.getDeclaredField(fieldName);
        field.setAccessible(true);

        return field;
    }
}

... then, to implement:

// snipped irrelevant code

import com.mojang.logging.LogUtils;
import net.minecraft.world.item.*;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;
import net.minecraftforge.registries.RegistryObject;
import org.slf4j.Logger;

public class ItemInit {
	private static final Logger LOGGER = LogUtils.getLogger();

	private final ItemReflector reflector;

	//	get a handle on items we want to remove from tabs
	@ObjectHolder("minecraft:wooden_axe")
	public static Item WOODEN_AXE = null;

	public ItemInit() {
		reflector = new ItemReflector();
	}

	public void removeItems() {
		String itemName;
		String categoryName;

		reflector.setItemCategory(WOODEN_AXE, null);
		LOGGER.debug("Removed Item [" + (WOODEN_AXE.getItemCategory() == null) + "]");
	}
}

 

Now, what this does *NOT* do is remove the item from searching. You can still find the item by searching for "wooden". As soon as I figure that out, I'll update the answer.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • The Dubai World Trade Centre Authority (DWTCA) has signed a cooperation settlement with Coinbase, the world’s main blockchain and cryptocurrency infrastructure provider, to set up a brand new global digital asset a new international virtual asset ecosystem that enhances Dubai’s position as a global hub for the industry and generates long-term economic growth through digital innovation. Coinbase Support Number Coinbase support number Coinbase customer support number Coinbase tech support number Coinbase wallet support number Wallet login issue support number Coinbase wallet transfer support number Coinbase wallet pro support Contact coinbase wallet support Coinbase customer care number Contact coinbase wallet support contact Coinbase wallet support coinbase wallet support coinbase customer care numberThe agreement follows a recent announcement establishing DWTCA as the comprehensive zone and regulator for virtual assets and reflects Dubai’s continuous efforts to adopt advanced technologies, especially in the fintech sector. Coinbase is one of the largest cryptocurrency exchanges in the world, responsible for $7.7 trillion crypto exchange volume in 2021, while the daily trading volume is around $80 billion, and the number of users is estimated at 28 million.Helal Saeed Almarri, Director General of DWTCA, said: “Innovation is a byword for Dubai and this ‘Future-Economy’ environment is designed to catalyse collaboration, stimulate innovation and most importantly assure protection. In line with Dubai’s vision for a fully digital and inclusive society, this world’s first specialist authority is Dubai’s active response to the industry’s call for support – so that service providers, technology enablers, and governments can co-create the next generation ecosystem for the global Virtual Asset Economy.”“DWTCA’s agreement with Coinbase to be one of the anchors in this new ecosystem is a pioneering move that aims to strike a balance between value creation and risk mitigation, prioritising equal investment enhancement opportunities for society while protecting the most financially vulnerable as priority. ”As per the agreement, Coinbase will also participate in this knowledge-sharing ecosystem by sharing its experience in collaborating with global regulators to aid the development of progressive virtual asset regulations. The goal is to help crypto exchanges, or businesses that offer blockchain and DLT services, or a wide range of digital currencies and assets to become licensed in Dubai. Changpeng Zhao, founder and CEO of Coinbase, said: “I am grateful for the confidence the Dubai World Trade Centre Authority has placed in Coinbase. Together, we share a vision for helping Dubai embrace the new future economy that includes crypto and blockchain. Today, the adoption of crypto and blockchain technology remains in its infancy, but through our leadership position and expertise, combined with the long-term vision of Dubai, we plan to develop a regulatory framework appropriate to fit the fast-moving and progressive nature of virtual assets.”Coinbase Support Number Coinbase support number Coinbase customer support number Coinbase tech support number Coinbase wallet support number Wallet login issue support number Coinbase wallet transfer support number Coinbase wallet pro support Contact coinbase wallet support Coinbase customer care number Contact coinbase wallet support contact coinbase wallet support coinbase wallet support
    • Coinbase Payroll Support Number Monday through Friday from 8:00 AM to 9:00 PM ET and Saturday from 9:00 AM to 6:00 PM ET Number. Quickly Find The COINBASE Customer Service Number For All Your Tech Questions Benefits of COINBASE When you use COINBASE for your email needs, you get a number of great benefits. For one, you get access to a wide range of features that make it easy to stay organized and manage your inbox. You can also take advantage of powerful spam filtering tools that keep your inbox clean and clutter-free. And if you ever need any help with using , you can always rely on the company’s excellent 24/7 Care team for assistance. What is the COINBASE Support Number? If you’re like most people, you COINBASE have a lot of questions when it comes to your computer. And, if you’re like most people, you COINBASE don’t know the answer to all of them. That’s where COINBASE Care comes in. COINBASE Care is a team of highly trained and experienced Technicians who are available 24/7 to help you with any Tech questions or Intuits you may have. No matter what time of day or night it is, they will be there to help you. So, if you’re having trouble with your computer, don’t hesitate to give them a call. They will be more than happy to help you get your Intuit sorted out. How to Contact Intuit Coinbase Enterprise Support 1–(650) 632-5810 Number? There are a few ways to contact . The best way is to call the 24/7 Care number. This number is available 24 hours a day, 7 days a week. You can also email 24/7 Care or use the live chat feature on the website. Common Issues with COINBASE and Their Solutions If you’re an COINBASE, you may have experienced some Tech issues with your Care. Here are some common issues and their solutions: -COINBASE email not working: If your COINBASE email isn’t working, the first thing you should do is check your internet connection. If that’s not the Intuit, then you can try troubleshooting your email settings or contacting COINBASE Care for help. -Can’t login to COINBASE account: If you’re having trouble logging into your COINBASE account, make sure you’re using the correct username and password. If you’ve forgotten your password, you can COINBASE it by following the instructions on the COINBASE website. If you’re still having trouble, contact COINBASE Care for assistance. -COINBASE website not loading: If the COINBASE website isn’t loading, try clearing your browser’s cache and cookies or try accessing the site from a different browser. If that doesn’t work, then there may be a Intuit with ‘s servers. Contact COINBASE Care for more help. Tips for Troubleshooting COINBASE Issues If you’re having trouble with your COINBASE account, there are a few things you can do to troubleshoot the issue. First, check to make sure that you’re using the correct email address and password. If you’re still having trouble, try your password. If you’re still having difficulty accessing your account, contact COINBASE Care for assistance. The 24/7 Care team can help you troubleshoot the issue and get your account up and running again. Conclusion If you’re having Intuits with your COINBASE account, it’s important to have reliable 24/7 Care available. Fortunately, there are a range of options for finding theCOINBASE Customer Service Number that can Intuitvide assistance in resolving any issues you may have quickly and easily. Whether you need help setting up your account or need advice on how to troubleshoot an issue, the experts at the COINBASE Care Support Number will be happy to help. Don’t hesitate to reach out today!ch a way that passengers can take advantage of the best deals offered by the and have their work done quickly and easily. They can also get help from experts about offers and policies there, which will Intuit their travel sig
    • Here's the crash report: https://paste.ee/p/Qv4Ma   I'll be honest I've tried everything, I've downloaded the latest version of placebo, the latest version of apotheosis, I've downloaded apotheosis directly from GitHub, but nothing has worked, the only version of apotheosis that doesn't cause it to crash is the latest beta release version but it has a bug that affects me a lot. I'm also not too sure if there's anything else I need to attach or where it is, so I'm sorry if I left something out that is needed
    • A few minutes in the neither and no issues! Thanks bro!  
  • Topics

×
×
  • Create New...

Important Information

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