-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/main/java/vazkii/quark/content/experimental/client/tooltip/VariantsComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ItemStack> variants; | ||
int height, width; | ||
|
||
public VariantsComponent(ItemStack stack) { | ||
this.stack = stack; | ||
} | ||
|
||
private List<ItemStack> getVariants() { | ||
if(computed) | ||
return variants; | ||
|
||
|
||
List<ItemStack> setVariants = new ArrayList<>(); | ||
Item item = stack.getItem(); | ||
if(item instanceof BlockItem bi) { | ||
Block block = bi.getBlock(); | ||
|
||
Collection<Block> 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<ItemStack> 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; | ||
} | ||
|
||
} |