Начинающий
- Статус
- Оффлайн
- Регистрация
- 23 Апр 2024
- Сообщения
- 80
- Реакции
- 0
- Выберите загрузчик игры
- Fabric
хз зачем это
ну ладно
ss:
ну ладно
ss:
inventory:
package test.xeon.client.hud.elements.component;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.item.ItemStack;
import test.xeon.Xeon;
import test.xeon.base.font.Font;
import test.xeon.base.font.Fonts;
import test.xeon.base.theme.Theme;
import test.xeon.client.hud.HudRenderStyle;
import test.xeon.client.hud.elements.draggable.DraggableHudElement;
import test.xeon.utility.mixin.accessors.DrawContextAccessor;
import test.xeon.utility.render.display.base.BorderRadius;
import test.xeon.utility.render.display.base.CustomDrawContext;
import test.xeon.utility.render.display.base.color.ColorRGBA;
import test.xeon.utility.game.player.PlayerIntersectionUtil;
public class InventoryComponent extends DraggableHudElement {
private static final float HEADER_HEIGHT = 17.5F;
private static final float SLOT_STEP = 13.0F;
private static final float ITEM_SCALE = 0.5F;
private static final int START_SLOT = 9;
private static final int END_SLOT = 36;
private final List<ItemStack> stacks = new ArrayList<>();
public InventoryComponent(String name, float initialX, float initialY, float windowWidth, float windowHeight, float offsetX, float offsetY, DraggableHudElement.Align align) {
super(name, initialX, initialY, windowWidth, windowHeight, offsetX, offsetY, align);
this.width = 123.0F;
this.height = 60.0F;
}
@Override
public void tick() {
this.stacks.clear();
if (mc.player == null) {
return;
}
for(int i = START_SLOT; i < END_SLOT; ++i) {
this.stacks.add(mc.player.getInventory().getStack(i));
}
}
@Override
public void render(CustomDrawContext ctx) {
if (!this.shouldDisplay()) {
return;
}
Theme theme = Xeon.getInstance().getThemeManager().getCurrentTheme();
Font titleFont = Fonts.REGULAR.getFont(8.0F);
HudRenderStyle.drawSplitPanel(ctx, this.x, this.y, this.width, this.height, HEADER_HEIGHT, theme, 1.0F);
float titleX = this.x + this.width / 2.0F - titleFont.width(this.getName()) / 2.0F;
float titleY = this.y + 4.5F;
ctx.drawText(titleFont, this.getName(), titleX, titleY, ColorRGBA.WHITE);
float offsetY = 20.0F;
float offsetX = 4.0F;
for(ItemStack stack : this.stacks) {
this.drawStack(ctx, stack, this.x + offsetX, this.y + offsetY);
offsetX += SLOT_STEP;
if (offsetX > this.width - SLOT_STEP) {
offsetY += SLOT_STEP;
offsetX = 4.0F;
}
}
}
private boolean shouldDisplay() {
if (mc.player == null) {
return PlayerIntersectionUtil.isChat(mc.currentScreen);
}
for(ItemStack stack : this.stacks) {
if (!stack.isEmpty()) {
return true;
}
}
return PlayerIntersectionUtil.isChat(mc.currentScreen) || mc.currentScreen instanceof ChatScreen;
}
private void drawStack(CustomDrawContext ctx, ItemStack stack, float x, float y) {
if (stack.isEmpty()) {
return;
}
ctx.pushMatrix();
ctx.getMatrices().translate(x, y, 0.0F);
ctx.getMatrices().scale(ITEM_SCALE, ITEM_SCALE, 1.0F);
ctx.drawItem(stack, 0, 0);
((DrawContextAccessor)ctx).callDrawItemBar(stack, 0, 0);
((DrawContextAccessor)ctx).callDrawCooldownProgress(stack, 0, 0);
ctx.popMatrix();
}
}