Skip to content

Commit ba1cc6f

Browse files
committed
add inventory hud
1 parent 30605fd commit ba1cc6f

File tree

11 files changed

+548
-1
lines changed

11 files changed

+548
-1
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public void init() {
122122
add(new MouseMovementHud());
123123
add(new DebugCountersHud());
124124
add(new DayCounterHud());
125+
add(new InventoryHud());
125126
entries.put(BedwarsMod.getInstance().getUpgradesOverlay().getId(), BedwarsMod.getInstance().getUpgradesOverlay());
126127
entries.put(BedwarsMod.getInstance().getResourceOverlay().getId(), BedwarsMod.getInstance().getResourceOverlay());
127128

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright © 2025 moehreag <[email protected]> & Contributors
3+
*
4+
* This file is part of AxolotlClient.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*
20+
* For more information, see the LICENSE file.
21+
*/
22+
23+
package io.github.axolotlclient.modules.hud.gui.hud.vanilla;
24+
25+
import java.util.List;
26+
27+
import com.mojang.blaze3d.systems.RenderSystem;
28+
import io.github.axolotlclient.AxolotlClient;
29+
import io.github.axolotlclient.modules.hud.gui.component.DynamicallyPositionable;
30+
import io.github.axolotlclient.modules.hud.gui.entry.BoxHudEntry;
31+
import io.github.axolotlclient.modules.hud.gui.layout.AnchorPoint;
32+
import io.github.axolotlclient.modules.hud.util.ItemUtil;
33+
import net.minecraft.block.Blocks;
34+
import net.minecraft.client.render.DiffuseLighting;
35+
import net.minecraft.client.util.math.MatrixStack;
36+
import net.minecraft.item.ItemStack;
37+
import net.minecraft.item.Items;
38+
import net.minecraft.util.Identifier;
39+
40+
public class InventoryHud extends BoxHudEntry implements DynamicallyPositionable {
41+
public static final Identifier ID = new Identifier(AxolotlClient.MODID, "inventoryhud");
42+
private static final ItemStack[] PLACEHOLDER = new ItemStack[]{
43+
new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE),
44+
null, null, null, null, null, null, null, null, null,
45+
new ItemStack(Items.STONE_SWORD), new ItemStack(Items.STONE_PICKAXE), new ItemStack(Items.STONE_AXE), new ItemStack(Items.STONE_SHOVEL), new ItemStack(Items.STONE_HOE), null, null, null, new ItemStack(Items.GLOWSTONE_DUST, 63)
46+
};
47+
private static final int ITEM_SIZE = 18;
48+
private static final int ITEM_TILE_SIZE = 16;
49+
50+
public InventoryHud() {
51+
super(164, 56, true);
52+
}
53+
54+
@Override
55+
public double getDefaultX() {
56+
return 0.5;
57+
}
58+
59+
@Override
60+
public double getDefaultY() {
61+
return 0.76;
62+
}
63+
64+
@Override
65+
public void renderComponent(MatrixStack stack, float delta) {
66+
List<ItemStack> inventorySlots = client.player.inventory.main;
67+
var pos = getPos();
68+
int x = pos.x() + 2;
69+
int y = pos.y() + 2;
70+
for (int i = 9, inventorySlotsLength = inventorySlots.size(); i < inventorySlotsLength; i++) {
71+
ItemStack itemStack = inventorySlots.get(i);
72+
int w = i - 9;
73+
if (!itemStack.isEmpty()) {
74+
renderStack(stack, x+(w % 9) * ITEM_SIZE, y + (w / 9) * ITEM_SIZE, itemStack);
75+
}
76+
}
77+
}
78+
79+
80+
private void renderStack(MatrixStack stack, int x, int y, ItemStack itemStack) {
81+
if (background.get() && backgroundColor.get().getAlpha() > 0) {
82+
fillRect(stack, x, y, ITEM_TILE_SIZE, ITEM_TILE_SIZE, backgroundColor.get().toInt());
83+
}
84+
ItemUtil.renderGuiItemModel(getScale(), itemStack, x, y);
85+
ItemUtil.renderGuiItemOverlay(stack, client.textRenderer, itemStack, x, y, null, -1, true);
86+
RenderSystem.disableDepthTest();
87+
}
88+
89+
@Override
90+
public void renderPlaceholderComponent(MatrixStack matrix, float delta) {
91+
ItemStack[] inventorySlots = PLACEHOLDER;
92+
var pos = getPos();
93+
int x = pos.x() + 2;
94+
int y = pos.y() + 2;
95+
for (int i = 0, inventorySlotsLength = inventorySlots.length; i < inventorySlotsLength; i++) {
96+
ItemStack stack = inventorySlots[i];
97+
if (stack != null) {
98+
renderStack(matrix, x + (i % 9) * ITEM_SIZE, y + (i / 9) * ITEM_SIZE, stack);
99+
}
100+
}
101+
}
102+
103+
@Override
104+
public Identifier getId() {
105+
return ID;
106+
}
107+
108+
@Override
109+
public AnchorPoint getAnchor() {
110+
return AnchorPoint.MIDDLE_MIDDLE;
111+
}
112+
}

1.20/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public void init() {
115115
add(new MouseMovementHud());
116116
add(new DebugCountersHud());
117117
add(new DayCounterHud());
118+
add(new InventoryHud());
118119
entries.put(BedwarsMod.getInstance().getUpgradesOverlay().getId(), BedwarsMod.getInstance().getUpgradesOverlay());
119120
entries.put(BedwarsMod.getInstance().getResourceOverlay().getId(), BedwarsMod.getInstance().getResourceOverlay());
120121

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright © 2025 moehreag <[email protected]> & Contributors
3+
*
4+
* This file is part of AxolotlClient.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*
20+
* For more information, see the LICENSE file.
21+
*/
22+
23+
package io.github.axolotlclient.modules.hud.gui.hud.vanilla;
24+
25+
import java.util.List;
26+
27+
import io.github.axolotlclient.AxolotlClient;
28+
import io.github.axolotlclient.modules.hud.gui.component.DynamicallyPositionable;
29+
import io.github.axolotlclient.modules.hud.gui.entry.BoxHudEntry;
30+
import io.github.axolotlclient.modules.hud.gui.layout.AnchorPoint;
31+
import net.minecraft.block.Blocks;
32+
import net.minecraft.client.gui.GuiGraphics;
33+
import net.minecraft.item.ItemStack;
34+
import net.minecraft.item.Items;
35+
import net.minecraft.util.Identifier;
36+
37+
public class InventoryHud extends BoxHudEntry implements DynamicallyPositionable {
38+
public static final Identifier ID = new Identifier(AxolotlClient.MODID, "inventoryhud");
39+
private static final ItemStack[] PLACEHOLDER = new ItemStack[]{
40+
new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE),
41+
null, null, null, null, null, null, null, null, null,
42+
new ItemStack(Items.STONE_SWORD), new ItemStack(Items.STONE_PICKAXE), new ItemStack(Items.STONE_AXE), new ItemStack(Items.STONE_SHOVEL), new ItemStack(Items.STONE_HOE), null, null, null, new ItemStack(Items.GLOWSTONE_DUST, 63)
43+
};
44+
private static final int ITEM_SIZE = 18;
45+
private static final int ITEM_TILE_SIZE = 16;
46+
47+
public InventoryHud() {
48+
super(164, 56, true);
49+
}
50+
51+
@Override
52+
public double getDefaultX() {
53+
return 0.5;
54+
}
55+
56+
@Override
57+
public double getDefaultY() {
58+
return 0.76;
59+
}
60+
61+
@Override
62+
public void renderComponent(GuiGraphics graphics, float delta) {
63+
List<ItemStack> inventorySlots = client.player.getInventory().main;
64+
var pos = getPos();
65+
int x = pos.x() + 2;
66+
int y = pos.y() + 2;
67+
for (int i = 9, inventorySlotsLength = inventorySlots.size(); i < inventorySlotsLength; i++) {
68+
ItemStack itemStack = inventorySlots.get(i);
69+
int w = i - 9;
70+
if (!itemStack.isEmpty()) {
71+
renderStack(graphics, x + (w % 9) * ITEM_SIZE, y + (w / 9) * ITEM_SIZE, itemStack);
72+
}
73+
}
74+
}
75+
76+
77+
private void renderStack(GuiGraphics graphics, int x, int y, ItemStack itemStack) {
78+
if (background.get() && backgroundColor.get().getAlpha() > 0) {
79+
fillRect(graphics, x, y, ITEM_TILE_SIZE, ITEM_TILE_SIZE, backgroundColor.get().toInt());
80+
}
81+
graphics.drawItem(itemStack, x, y);
82+
graphics.drawItemInSlot(client.textRenderer, itemStack, x, y);
83+
}
84+
85+
@Override
86+
public void renderPlaceholderComponent(GuiGraphics graphics, float delta) {
87+
ItemStack[] inventorySlots = PLACEHOLDER;
88+
var pos = getPos();
89+
int x = pos.x() + 2;
90+
int y = pos.y() + 2;
91+
for (int i = 0, inventorySlotsLength = inventorySlots.length; i < inventorySlotsLength; i++) {
92+
ItemStack stack = inventorySlots[i];
93+
if (stack != null) {
94+
renderStack(graphics, x + (i % 9) * ITEM_SIZE, y + (i / 9) * ITEM_SIZE, stack);
95+
}
96+
}
97+
}
98+
99+
@Override
100+
public Identifier getId() {
101+
return ID;
102+
}
103+
104+
@Override
105+
public AnchorPoint getAnchor() {
106+
return AnchorPoint.MIDDLE_MIDDLE;
107+
}
108+
}

1.21.6/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public void init() {
115115
add(new MouseMovementHud());
116116
add(new DebugCountersHud());
117117
add(new DayCounterHud());
118+
add(new InventoryHud());
118119
entries.put(BedwarsMod.getInstance().getUpgradesOverlay().getId(), BedwarsMod.getInstance().getUpgradesOverlay());
119120
entries.put(BedwarsMod.getInstance().getResourceOverlay().getId(), BedwarsMod.getInstance().getResourceOverlay());
120121

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright © 2025 moehreag <[email protected]> & Contributors
3+
*
4+
* This file is part of AxolotlClient.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*
20+
* For more information, see the LICENSE file.
21+
*/
22+
23+
package io.github.axolotlclient.modules.hud.gui.hud.vanilla;
24+
25+
import java.util.List;
26+
27+
import io.github.axolotlclient.AxolotlClient;
28+
import io.github.axolotlclient.modules.hud.gui.component.DynamicallyPositionable;
29+
import io.github.axolotlclient.modules.hud.gui.entry.BoxHudEntry;
30+
import io.github.axolotlclient.modules.hud.gui.layout.AnchorPoint;
31+
import net.minecraft.client.gui.GuiGraphics;
32+
import net.minecraft.resources.ResourceLocation;
33+
import net.minecraft.world.item.ItemStack;
34+
import net.minecraft.world.item.Items;
35+
import net.minecraft.world.level.block.Blocks;
36+
37+
public class InventoryHud extends BoxHudEntry implements DynamicallyPositionable {
38+
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(AxolotlClient.MODID, "inventoryhud");
39+
private static final ItemStack[] PLACEHOLDER = new ItemStack[]{
40+
new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE), new ItemStack(Blocks.STONE),
41+
null, null, null, null, null, null, null, null, null,
42+
new ItemStack(Items.STONE_SWORD), new ItemStack(Items.STONE_PICKAXE), new ItemStack(Items.STONE_AXE), new ItemStack(Items.STONE_SHOVEL), new ItemStack(Items.STONE_HOE), null, null, null, new ItemStack(Items.GLOWSTONE_DUST, 63)
43+
};
44+
private static final int ITEM_SIZE = 18;
45+
private static final int ITEM_TILE_SIZE = 16;
46+
47+
public InventoryHud() {
48+
super(164, 56, true);
49+
}
50+
51+
@Override
52+
public double getDefaultX() {
53+
return 0.5;
54+
}
55+
56+
@Override
57+
public double getDefaultY() {
58+
return 0.76;
59+
}
60+
61+
@Override
62+
public void renderComponent(GuiGraphics graphics, float delta) {
63+
List<ItemStack> inventorySlots = client.player.getInventory().getNonEquipmentItems();
64+
var pos = getPos();
65+
int x = pos.x() + 2;
66+
int y = pos.y() + 2;
67+
for (int i = 9, inventorySlotsLength = inventorySlots.size(); i < inventorySlotsLength; i++) {
68+
ItemStack itemStack = inventorySlots.get(i);
69+
int w = i - 9;
70+
if (!itemStack.isEmpty()) {
71+
renderStack(graphics, x + (w % 9) * ITEM_SIZE, y + (w / 9) * ITEM_SIZE, itemStack);
72+
}
73+
}
74+
}
75+
76+
77+
private void renderStack(GuiGraphics graphics, int x, int y, ItemStack itemStack) {
78+
if (background.get() && backgroundColor.get().getAlpha() > 0) {
79+
fillRect(graphics, x, y, ITEM_TILE_SIZE, ITEM_TILE_SIZE, backgroundColor.get().toInt());
80+
}
81+
graphics.renderItem(itemStack, x, y);
82+
graphics.renderItemDecorations(client.font, itemStack, x, y);
83+
}
84+
85+
@Override
86+
public void renderPlaceholderComponent(GuiGraphics graphics, float delta) {
87+
ItemStack[] inventorySlots = PLACEHOLDER;
88+
var pos = getPos();
89+
int x = pos.x() + 2;
90+
int y = pos.y() + 2;
91+
for (int i = 0, inventorySlotsLength = inventorySlots.length; i < inventorySlotsLength; i++) {
92+
ItemStack stack = inventorySlots[i];
93+
if (stack != null) {
94+
renderStack(graphics, x + (i % 9) * ITEM_SIZE, y + (i / 9) * ITEM_SIZE, stack);
95+
}
96+
}
97+
}
98+
99+
@Override
100+
public ResourceLocation getId() {
101+
return ID;
102+
}
103+
104+
@Override
105+
public AnchorPoint getAnchor() {
106+
return AnchorPoint.MIDDLE_MIDDLE;
107+
}
108+
}

1.21/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public void init() {
114114
add(new PlayerHud());
115115
add(new MouseMovementHud());
116116
add(new DebugCountersHud());
117+
add(new InventoryHud());
117118
entries.put(BedwarsMod.getInstance().getUpgradesOverlay().getId(), BedwarsMod.getInstance().getUpgradesOverlay());
118119
entries.put(BedwarsMod.getInstance().getResourceOverlay().getId(), BedwarsMod.getInstance().getResourceOverlay());
119120

0 commit comments

Comments
 (0)