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

Minecraft version: 1.15.1

 

So I want my mod to add an Creative Tab in which one can use all the heads of the current online Players.

 

so far I got this:

public static ArrayList<String> online_player_names = new ArrayList<String>() {{
        add("Steve");
        add("my_name");
        add("Alex");
        add("Herobrine");
        add("Cake");
        add("CaptainSparkles");
        add("Steve");
        add("Steve");
        add("Steve");
        add("Steve");
        add("Steve");
        add("Steve");
        add("Steve");
        add("Steve");
        add("Steve");
    }};
//this is a list of predefined heads

@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
	@SubscribeEvent
        public static void updateHeads(final GuiOpenEvent event){
            Collection<NetworkPlayerInfo> playersC= Minecraft.getInstance().getConnection().getPlayerInfoMap();
            playersC.forEach((loadedPlayer)->{
                String LoadedPlayerName = loadedPlayer.getGameProfile().getName();
                if(!online_player_names.contains(LoadedPlayerName)){
                    online_player_names.add(LoadedPlayerName);

                }

            });
            online_player_names.forEach((playername)->{
                ItemStack head = (new ItemStack(Blocks.PLAYER_HEAD));
                CompoundNBT nbt = head.getTag();
                nbt.putString("Skullowner", playername);
                head.setTag(nbt);
                Item heads = head.getItem();
              //Put Itemstack to Creative Tab
                ModItemGroups.MOD_ITEM_GROUP_Skulls.fill(new NonNullList<ItemStack>() {{add(head);}});
            });
	}

 

 

this code gives an error when it tries to put the ItemStack into a new Creative Tab:

 

Error Code From pastebin here

 

I don't know how to solve this 

I didn't fin any references on how to add Already exsisting Items to a new CreativeTab but with changed NBT

 

here is my code for the creative Tabs:

package com.anonymusdennis.annomod.init;

import com.anonymusdennis.annomod.annomod;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.NonNullList;
import net.minecraft.util.registry.Registry;
import java.util.function.Supplier;

public class ModItemGroups  {
    public static class ModItemGroup extends ItemGroup {

        private final Supplier<ItemStack> iconSupplier;

        public ModItemGroup(final String name, final Supplier<ItemStack> iconSupplier) {
            super(name);
            this.iconSupplier = iconSupplier;
        }

        @Override
        public ItemStack createIcon() {
            return iconSupplier.get();
        }
        @Override
        public void fill(NonNullList<ItemStack> items) {
            for(Item item : Registry.ITEM) {
                item.fillItemGroup(this, items);
            }
        }
    }
    public static final ItemGroup MOD_ITEM_GROUP_Banner = new ModItemGroup("jolo", () -> new ItemStack(Items.LIGHT_BLUE_BANNER));
    public static ItemGroup MOD_ITEM_GROUP_Skulls = (new ModItemGroup("Heads", () -> new ItemStack(Items.LIGHT_BLUE_BANNER)));
    public static final ItemGroup MOD_ITEM_GROUP_Standart = new ModItemGroup(annomod.MOD_ID, () -> new ItemStack(ItemInit.erstes_item));
    public static final ItemGroup MOD_ITEM_GROUP_Rest = new ModItemGroup("Rest", () -> new ItemStack(Items.LIGHT_BLUE_BANNER));

}

or here from pastebin:

https://pastebin.com/EMm8BqyA

 

Edited by anonymusdennis
bad Internet

  • Author
@Override
public void fill(NonNullList<ItemStack> items) {
    
    for(Item item : Registry.ITEM) {
        item.fillItemGroup(this, items);
    }
}

so far I got this but what is the list of Items I am supposed to get?

I am new to this topic please forgive my stupidity

 

  • Author
public static class ModItemGroup extends ItemGroup {
    public String name = "";
    public ItemGroup UpdateName(String name)
    {
        this.name = "";
        return this;
    }

    public static ArrayList<String> player_names = new ArrayList<String>() {{}};
    private final Supplier<ItemStack> iconSupplier;

    public ModItemGroup(final String name, final Supplier<ItemStack> iconSupplier) {
        super(name);
        this.iconSupplier = iconSupplier;
    }
    @Override
    public void fill(NonNullList<ItemStack> items) {
        LOGGER.info(this.name);

        if(this.name == "skull"){
            LOGGER.info(this.name + "success");
            items = new NonNullList<ItemStack>() {{
                player_names.forEach((playername)->{
                    ItemStack head = (new ItemStack(Blocks.PLAYER_HEAD));
                    CompoundNBT nbt = head.getTag();
                    nbt.putString("Skullowner", playername);
                    head.setTag(nbt);
                    Item heads = head.getItem();
                    add(head);
                });}};
        }
    }
    @Override
    public ItemStack createIcon() {
        return iconSupplier.get();
    }

}

Now I got this is this better?

I also removed the call of the fill function



Now I got another error :

[10:34:56] [Render thread/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: Unable to have damage AND stack.
    Index: 2

 

And below there is this error:


 Caught exception during event RegistryEvent.Register<minecraft:item> dispatch for modid annomod


here is the complete Error

 

https://pastebin.com/4W14KiMv

Edited by anonymusdennis

  • Author

okay i think I got it started without any errors:

 

package com.anonymusdennis.annomod.init;

import com.anonymusdennis.annomod.annomod;
import net.minecraft.block.Blocks;
import net.minecraft.client.gui.screen.inventory.CreativeScreen;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.NonNullList;
import net.minecraft.util.registry.Registry;

import java.util.ArrayList;
import java.util.function.Supplier;
import net.minecraft.client.gui.screen.inventory.CreativeScreen;

import static net.minecraft.world.biome.Biome.LOGGER;

public class ModItemGroups  {

    public static class ModItemGroup extends ItemGroup {
        public String name = "";
        public ItemGroup UpdateName(String name)
        {
            this.name = "";
            return this;
        }

        public static ArrayList<String> player_names = new ArrayList<String>() {{}};
        private final Supplier<ItemStack> iconSupplier;

        public ModItemGroup(final String name, final Supplier<ItemStack> iconSupplier) {
            super(name);
            this.iconSupplier = iconSupplier;
        }
        @Override
        public void fill(NonNullList<ItemStack> items) {
            LOGGER.info(this.name);

            if(this.name == "skull"){
                LOGGER.info(this.name + "success");

                    player_names.forEach((playername)-> {
                        ItemStack head = (new ItemStack(Blocks.PLAYER_HEAD));
                        CompoundNBT nbt = head.getTag();
                        nbt.putString("Skullowner", playername);
                        head.setTag(nbt);
                        Item heads = head.getItem();
                        items.add(head);
                    });
                for(Item item : Registry.ITEM) {
                    item.fillItemGroup(this, items);
                }
            }
        }
        @Override
        public ItemStack createIcon() {
            return iconSupplier.get();
        }

    }
    public static final ItemGroup MOD_ITEM_GROUP_Banner = new ModItemGroup("jolo", () -> new ItemStack(Items.LIGHT_BLUE_BANNER));
    public ItemGroup MOD_ITEM_GROUP_Skulls = ((new ModItemGroup("Heads", () -> new ItemStack(Items.LIGHT_BLUE_BANNER))).UpdateName("skull"));
    public static final ItemGroup MOD_ITEM_GROUP_Standart = new ModItemGroup(annomod.MOD_ID, () -> new ItemStack(ItemInit.erstes_item));
    public static final ItemGroup MOD_ITEM_GROUP_Rest = new ModItemGroup("Rest", () -> new ItemStack(Items.LIGHT_BLUE_BANNER));

}

 

this does somehow cause the creative Tab "Heads" not to show up why?

 

I am truly sorry If I am stressing you..

 

  • Author

okay i got it now and here is my code for anyone who is interested:

 

 

ModItemGroups.java

package com.anonymusdennis.annomod.init;

import com.anonymusdennis.annomod.annomod;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.NonNullList;
import net.minecraft.util.registry.Registry;

import java.util.ArrayList;
import java.util.function.Supplier;
import java.util.logging.Logger;

import static net.minecraft.world.biome.Biome.LOGGER;

public class ModItemGroups  {

    public static class ModItemGroup extends ItemGroup {
        public String namer = "";

        private final Supplier<ItemStack> iconSupplier;

        public ModItemGroup(final String name, final Supplier<ItemStack> iconSupplier, String skull) {
            super(name);
            this.namer = skull;
            namer = skull;
            this.iconSupplier = iconSupplier;
        }
        @Override
        public void fill(NonNullList<ItemStack> items) {
            if(namer == "skull"){
                annomod.online_player_names.forEach((playername)-> {
                    ItemStack head = (new ItemStack(Blocks.PLAYER_HEAD));
                    CompoundNBT nbt = head.getOrCreateTag();
                    nbt.putString("SkullOwner", playername);
                    nbt.put("display", new CompoundNBT() {{
                        putString("text", playername);
                    }});
                    head.setTag(nbt);
                    Item heads = head.getItem();
                    items.add(head);
                });

            }
            for(Item item : Registry.ITEM) {
                item.fillItemGroup(this, items);
            }
        }
        @Override
        public ItemStack createIcon() {
            return iconSupplier.get();
        }

    }
    public static final ItemGroup MOD_ITEM_GROUP_Blocks = new ModItemGroup("jolo", () -> new ItemStack(Items.LIGHT_BLUE_BANNER), "banner");
    public static final ItemGroup MOD_ITEM_GROUP_Skulls = new ModItemGroup("Heads", () -> new ItemStack(Items.PLAYER_HEAD),"skull");
    public static final ItemGroup MOD_ITEM_GROUP_Standart = new ModItemGroup(annomod.MOD_ID, () -> new ItemStack(ItemInit.erstes_item), "standard");
    public static final ItemGroup MOD_ITEM_GROUP_Food = new ModItemGroup("Rest", () -> new ItemStack(Items.LIGHT_BLUE_BANNER), "rest");

}

 

annomod.java

 

package com.anonymusdennis.annomod;

import com.anonymusdennis.annomod.init.ModItemGroups;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.SkullBlock;
import net.minecraft.block.SkullPlayerBlock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.play.NetworkPlayerInfo;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.NonNullList;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.network.NetworkRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.ArrayList;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("annomod")
public class annomod
{

private int online_players = 0;
    // Directly reference a log4j logger.
    public static ArrayList<String> online_player_names = new ArrayList<String>() {{
        add("anonymusdennis");
        add("Steve");
        //List of heads to be added by default
    }};

    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "annomod";
    public static annomod instance;
    public annomod() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        //FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        //FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
        instance = this;
        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        // do something that can only be done on the client
    }

    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        // do something when the server starts
    }

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here
            LOGGER.info("HELLO from Register Block");
        }
        @SubscribeEvent
        public static void updateHeads(final GuiOpenEvent event){

            Collection<NetworkPlayerInfo> playersC= Minecraft.getInstance().getConnection().getPlayerInfoMap();
            playersC.forEach((loadedPlayer)->{
                String LoadedPlayerName = loadedPlayer.getGameProfile().getName();
                if(!online_player_names.contains(LoadedPlayerName)){
                    online_player_names.add(LoadedPlayerName);
                }
                LoadedPlayerName = loadedPlayer.getDisplayName().getString();
                if(!online_player_names.contains(LoadedPlayerName)) {
                    online_player_names.add(LoadedPlayerName);
                }
            });
            String LoadedPlayerName = Minecraft.getInstance().player.getDisplayName().getString();
            if(!online_player_names.contains(LoadedPlayerName)) {
                online_player_names.add(LoadedPlayerName);
            }


        }
    }
}

 

 

 

 

 

 

Thanks to everyone !!!!!!!!

  • 2 months later...

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.