mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Add support for custom CreativeModeTab implementations (#9210)
This commit is contained in:
1 parent
e6c7958456
commit
f050617b47
2 files changed
+53
-6
No files matched your search
@@ -6,11 +6,14 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.CreativeModeTab.TabVisibility;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.DyeItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
@@ -62,6 +65,17 @@ public class CreativeModeTabTest
|
||||
output.accept(new ItemStack(Blocks.DIORITE));
|
||||
output.accept(new ItemStack(Blocks.ANDESITE));
|
||||
}));
|
||||
|
||||
event.registerCreativeModeTab(new ResourceLocation(MOD_ID, "colors"), builder -> builder.title(Component.literal("Colors"))
|
||||
.displayItems((features, output, hasPermissions) ->
|
||||
{
|
||||
for (DyeColor color : DyeColor.values())
|
||||
{
|
||||
output.accept(DyeItem.byColor(color));
|
||||
}
|
||||
})
|
||||
.withTabFactory(CreativeModeColorTab::new)
|
||||
);
|
||||
}
|
||||
|
||||
private static ItemStack i(ItemLike item) { return new ItemStack(item); }
|
||||
@@ -88,4 +102,28 @@ public class CreativeModeTabTest
|
||||
entries.putBefore(i(Blocks.ANDESITE), i(Blocks.POLISHED_ANDESITE), vis);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CreativeModeColorTab extends CreativeModeTab
|
||||
{
|
||||
private final ItemStack[] iconItems;
|
||||
|
||||
public CreativeModeColorTab(CreativeModeTab.Builder builder)
|
||||
{
|
||||
super(builder);
|
||||
|
||||
DyeColor[] colors = DyeColor.values();
|
||||
iconItems = new ItemStack[colors.length];
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
{
|
||||
iconItems[i] = new ItemStack(DyeItem.byColor(colors[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItem()
|
||||
{
|
||||
int idx = (int)(System.currentTimeMillis() / 1200) % iconItems.length;
|
||||
return iconItems[idx];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user