[Feature] Item Renderer
This commit is contained in:
parent
8ef0d82ed6
commit
02284d9f94
4 changed files with 66 additions and 0 deletions
|
@ -11,6 +11,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
|||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
@ -275,5 +276,12 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
|
|||
add(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
protected Item addItem(ItemStack stack) {
|
||||
Item i = new Item(Value.fit(), Value.fit());
|
||||
i.setItem(stack);
|
||||
add(i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.betterx.ui.vanilla.VanillaScrollerRenderer;
|
|||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
@ -196,4 +197,9 @@ public class HorizontalStack extends AbstractHorizontalStack<HorizontalStack> {
|
|||
) {
|
||||
return super.addScrollable(width, height, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item addItem(ItemStack stack) {
|
||||
return super.addItem(stack);
|
||||
}
|
||||
}
|
||||
|
|
46
src/main/java/org/betterx/ui/layout/components/Item.java
Normal file
46
src/main/java/org/betterx/ui/layout/components/Item.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package org.betterx.ui.layout.components;
|
||||
|
||||
|
||||
import org.betterx.ui.layout.values.Rectangle;
|
||||
import org.betterx.ui.layout.values.Value;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class Item extends CustomRenderComponent {
|
||||
private ItemStack itemStack;
|
||||
|
||||
public Item(Value width, Value height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
public Item setItem(ItemStack item) {
|
||||
this.itemStack = item;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customRender(PoseStack stack, int x, int y, float deltaTicks, Rectangle bounds, Rectangle clipRect) {
|
||||
final ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
|
||||
itemRenderer.renderAndDecorateItem(Minecraft.getInstance().player, itemStack, bounds.left, bounds.top, 0);
|
||||
itemRenderer.renderGuiItemDecorations(
|
||||
Minecraft.getInstance().font,
|
||||
itemStack,
|
||||
bounds.left,
|
||||
bounds.top,
|
||||
"" + itemStack.getCount()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentWidth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentHeight() {
|
||||
return 16;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import org.betterx.ui.vanilla.VanillaScrollerRenderer;
|
|||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
@ -208,4 +209,9 @@ public class VerticalStack extends AbstractVerticalStack<VerticalStack> {
|
|||
) {
|
||||
return super.addScrollable(width, height, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item addItem(ItemStack stack) {
|
||||
return super.addItem(stack);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue