Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ItemCounts

A Minecraft [Fabric](https://fabricmc.net/) mod that displays the total amount of items in your hotbar.
Built for version 1.21.5
Built for version 1.21.6

[Curseforge release](https://www.curseforge.com/minecraft/mc-mods/item-counts-fabric)
[Modrinth release](https://modrinth.com/mod/item-counts)
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.10-SNAPSHOT'
id 'fabric-loom' version "${loom_version}"
id 'maven-publish'
}

Expand Down Expand Up @@ -29,10 +29,10 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation("me.shedaniel.cloth:cloth-config-fabric:[18.0,19.0)") {
modImplementation("me.shedaniel.cloth:cloth-config-fabric:[19.0,20.0)") {
exclude(group: "net.fabricmc.fabric-api")
}
modImplementation("com.terraformersmc:modmenu:[14.0,15.0)") {
modImplementation("com.terraformersmc:modmenu:[15.0,16.0)") {
exclude group: "net.fabricmc.fabric-api"
}

Expand Down
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.21.5
yarn_mappings=1.21.5+build.1
loader_version=0.16.10
minecraft_version=1.21.6
yarn_mappings=1.21.6+build.1
loader_version=0.16.14
loom_version=1.10-SNAPSHOT

# Mod Properties
mod_version = 1.6.1
maven_group = blazingtwist
archives_base_name = itemcounts

# Dependencies
fabric_version=0.119.5+1.21.5
fabric_version=0.127.0+1.21.6
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@ public abstract class DrawContextMixin {
"I" +
"I" +
"Z" +
")I"
")V"
)
)
private int redirectDrawItemSlotText(
private void redirectDrawItemSlotText(
DrawContext instance, TextRenderer textRenderer, String text, int x, int y, int color, boolean shadow
) {
boolean isCalledFromHotbarRenderItem = ItemCounts.mixin_drawItemCalledFromRenderHotbarItem;
if (ItemCounts.mixin_drawItemCalledFromRenderHotbarItem) {
ItemCounts.mixin_drawItemCalledFromRenderHotbarItem = false;
}

if (isCalledFromHotbarRenderItem && !ItemCounts.getConfig().show_vanilla_count) {
return 0;
if (!isCalledFromHotbarRenderItem || ItemCounts.getConfig().show_vanilla_count) {
instance.drawText(textRenderer, text, x, y, color, shadow);
}

return instance.drawText(textRenderer, text, x, y, color, shadow);
}

}
38 changes: 19 additions & 19 deletions src/main/java/blazingtwist/itemcounts/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import org.joml.Matrix3x2fStack;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -42,12 +42,12 @@ private void renderItemOverlay(DrawContext context, ItemCountsConfig.ItemRenderC
y += config.offset.y;

boolean doRenderText = shouldRenderItem(config, player, stack);
if (doRenderText) {
renderItemText(context, config, onHotbar, player, stack, x, y);
}
if (config.iconOption.shouldShowIcon(doRenderText)) {
renderItemAt(context, stack, x, y, config.offset.textScale, onHotbar, player, seed);
}
if (doRenderText) {
renderItemText(context, config, onHotbar, player, stack, x, y);
}
}

@Unique
Expand Down Expand Up @@ -86,40 +86,40 @@ private void renderItemText(DrawContext context, ItemCountsConfig.ItemRenderConf
private void renderTextAt(DrawContext context, ItemCountsConfig.ItemRenderConfig config,
String text, int color, int x, int y, boolean isOnHotbar) {
float scaleFactor = config.offset.textScale;
MatrixStack matrices = context.getMatrices();
matrices.push();
matrices.translate(0, ItemCounts.FONT_Y_OFFSET * scaleFactor, 200f);
Matrix3x2fStack matrices = context.getMatrices();
matrices.pushMatrix();
matrices.translate(0, ItemCounts.FONT_Y_OFFSET * scaleFactor);
if (isOnHotbar) {
matrices.translate(ItemCounts.HOTBAR_X_OFFSET * scaleFactor, 0, 0);
matrices.translate(ItemCounts.HOTBAR_X_OFFSET * scaleFactor, 0);
}
matrices.scale(scaleFactor, scaleFactor, 1);
matrices.scale(scaleFactor, scaleFactor);

context.drawText(
client.textRenderer,
text,
(int) (config.offset.anchor.applyAnchorOffset(x / scaleFactor, text, client.textRenderer)),
(int) ((y / scaleFactor) - (ItemCounts.FONT_HEIGHT / 2)),
color >= 0 ? color : 16777215,
color >= 0 ? (0xff000000 | color) : -1,
true
);

matrices.pop();
matrices.popMatrix();
}

@Unique
private void renderItemAt(DrawContext context, ItemStack item, int x, int y, float scaleFactor, boolean isOnHotbar, PlayerEntity player, int seed) {
MatrixStack contextMatrices = context.getMatrices();
contextMatrices.push();
contextMatrices.scale(scaleFactor, scaleFactor, scaleFactor);
Matrix3x2fStack contextMatrices = context.getMatrices();
contextMatrices.pushMatrix();
contextMatrices.scale(scaleFactor, scaleFactor);

if (isOnHotbar) {
contextMatrices.translate(ItemCounts.HOTBAR_X_OFFSET, 0, 0);
contextMatrices.translate(ItemCounts.HOTBAR_X_OFFSET, 0);
}
int scaledX = ((int)(x / scaleFactor)) - 8; // -8 to offset the reapplied offset in 'drawItem'...
int scaledY = ((int)(y / scaleFactor)) - 8;
int scaledX = ((int) (x / scaleFactor)) - 8; // -8 to offset the reapplied offset in 'drawItem'...
int scaledY = ((int) (y / scaleFactor)) - 8;
context.drawItem(player, item, scaledX, scaledY, seed);

contextMatrices.pop();
contextMatrices.popMatrix();
}

@Inject(method = "renderHotbarItem(" +
Expand All @@ -130,7 +130,7 @@ private void renderItemAt(DrawContext context, ItemStack item, int x, int y, flo
"Lnet/minecraft/entity/player/PlayerEntity;" +
"Lnet/minecraft/item/ItemStack;" +
"I" +
")V", at = @At("HEAD"), order = 999)
")V", at = @At("TAIL"), order = 999)
public void onRenderHotbarItem(DrawContext context, int x, int y, RenderTickCounter tickCounter, PlayerEntity player, ItemStack stack, int seed, CallbackInfo info) {
if (stack.isEmpty()) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
],

"depends": {
"fabricloader": ">=0.16.10",
"fabricloader": ">=0.16.14",
"fabric-api": "*",
"minecraft": "~1.21.5",
"minecraft": "~1.21.6",
"java": ">=17"
},
"suggests": {
Expand Down