diff --git a/src/main/java/vazkii/quark/content/experimental/client/tooltip/VariantsComponent.java b/src/main/java/vazkii/quark/content/experimental/client/tooltip/VariantsComponent.java new file mode 100644 index 0000000000..84bc553821 --- /dev/null +++ b/src/main/java/vazkii/quark/content/experimental/client/tooltip/VariantsComponent.java @@ -0,0 +1,81 @@ +package vazkii.quark.content.experimental.client.tooltip; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; +import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import vazkii.quark.content.experimental.module.VariantSelectorModule; + +@OnlyIn(Dist.CLIENT) +public class VariantsComponent implements ClientTooltipComponent, TooltipComponent { + + final ItemStack stack; + + boolean computed = false; + List variants; + int height, width; + + public VariantsComponent(ItemStack stack) { + this.stack = stack; + } + + private List getVariants() { + if(computed) + return variants; + + + List setVariants = new ArrayList<>(); + Item item = stack.getItem(); + if(item instanceof BlockItem bi) { + Block block = bi.getBlock(); + + Collection allVariants = VariantSelectorModule.variants.getAllVariants(block); + for(Block b : allVariants) + setVariants.add(new ItemStack(b)); + } + + computed = true; + variants = setVariants; + + int size = variants.size(); + height = (size == 0 ? 0 : 20); + width = size * 18; + + return variants; + } + + @Override + public void renderImage(Font font, int x, int y, PoseStack stack, ItemRenderer render, int yea) { + List variants = getVariants(); + + for(int i = 0; i < variants.size(); i++) { + ItemStack variant = variants.get(i); + render.renderGuiItem(variant, x + i * 18, y); + } + } + + @Override + public int getHeight() { + getVariants(); + return height; + } + + @Override + public int getWidth(Font font) { + getVariants(); + return width; + } + +} \ No newline at end of file