mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-18 11:19:20 +00:00
Replace mantle creative tab with supplier item group
Modern item groups lazy load the item, and supplier makes it more deferred registration
This commit is contained in:
1 parent
f1037ce21a
commit
fabf401233
2 files changed
+33
-36
No files matched your search
@@ -1,36 +0,0 @@
|
||||
package slimeknights.mantle.client;
|
||||
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class CreativeTab extends ItemGroup {
|
||||
|
||||
private ItemStack icon;
|
||||
|
||||
// a vanilla icon in case the other one isn't present
|
||||
public CreativeTab(String label, ItemStack backupIcon) {
|
||||
super(label);
|
||||
|
||||
this.icon = backupIcon;
|
||||
}
|
||||
|
||||
public void setDisplayIcon(ItemStack displayIcon) {
|
||||
if (!displayIcon.isEmpty()) {
|
||||
this.icon = displayIcon;
|
||||
}
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public ItemStack getIcon() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public ItemStack createIcon() {
|
||||
return this.icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package slimeknights.mantle.util;
|
||||
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Item group that sets its item based on an item supplier
|
||||
*/
|
||||
public class SupplierItemGroup extends ItemGroup {
|
||||
private final Supplier<ItemStack> supplier;
|
||||
|
||||
/**
|
||||
* Creates a new item group
|
||||
* @param modId Tab owner mod ID
|
||||
* @param name Tab name
|
||||
* @param supplier Item stack supplier
|
||||
*/
|
||||
public SupplierItemGroup(String modId, String name, Supplier<ItemStack> supplier) {
|
||||
super(String.format("%s.%s", modId, name));
|
||||
this.setTabPath(String.format("%s/%s", modId, name));
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public ItemStack createIcon() {
|
||||
return supplier.get();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user