2024-03-14 05:09:55 +00:00
|
|
|
package pm.c7.scout.client.gui;
|
|
|
|
|
|
|
|
import com.google.common.math.IntMath;
|
|
|
|
import net.minecraft.client.font.TextRenderer;
|
2024-03-16 02:01:13 +00:00
|
|
|
import net.minecraft.client.gui.DrawContext;
|
2024-03-14 05:09:55 +00:00
|
|
|
import net.minecraft.client.gui.tooltip.TooltipComponent;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.collection.DefaultedList;
|
|
|
|
import pm.c7.scout.ScoutUtil;
|
|
|
|
import pm.c7.scout.item.BagTooltipData;
|
|
|
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
|
|
|
public class BagTooltipComponent implements TooltipComponent {
|
2024-03-14 06:12:23 +00:00
|
|
|
private final DefaultedList<ItemStack> inventory;
|
|
|
|
private final int slotCount;
|
|
|
|
|
|
|
|
public BagTooltipComponent(BagTooltipData data) {
|
|
|
|
this.inventory = data.getInventory();
|
|
|
|
this.slotCount = data.getSlotCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getHeight() {
|
|
|
|
return (18 * IntMath.divide(slotCount, 6, RoundingMode.UP)) + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWidth(TextRenderer textRenderer) {
|
|
|
|
return 18 * (Math.min(slotCount, 6));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-16 02:01:13 +00:00
|
|
|
public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext graphics) {
|
2024-03-14 06:12:23 +00:00
|
|
|
int originalX = x;
|
|
|
|
|
|
|
|
for (int i = 0; i < slotCount; i++) {
|
|
|
|
this.drawSlot(x, y, i, graphics, textRenderer);
|
|
|
|
|
|
|
|
x += 18;
|
|
|
|
if ((i + 1) % 6 == 0) {
|
|
|
|
y += 18;
|
|
|
|
x = originalX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-16 02:01:13 +00:00
|
|
|
private void drawSlot(int x, int y, int index, DrawContext graphics, TextRenderer textRenderer) {
|
2024-03-14 06:12:23 +00:00
|
|
|
ItemStack itemStack = this.inventory.get(index);
|
|
|
|
graphics.drawTexture(ScoutUtil.SLOT_TEXTURE, x, y, 0, 46, 7, 18, 18, 256, 256);
|
|
|
|
graphics.drawItem(itemStack, x + 1, y + 1, index);
|
|
|
|
graphics.drawItemInSlot(textRenderer, itemStack, x + 1, y + 1);
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
}
|