Skip to content

Commit

Permalink
Merge pull request #16 from BlazingTwist/1.20.1
Browse files Browse the repository at this point in the history
1.4.0 - allow disable vanilla item counts
  • Loading branch information
BlazingTwist authored Jul 22, 2023
2 parents a8152fe + 783c1d1 commit 28e0408
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.21

# Mod Properties
mod_version = 1.3.0
mod_version = 1.4.0
maven_group = blazingtwist
archives_base_name = itemcounts

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/blazingtwist/itemcounts/ItemCounts.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ItemCounts implements ModInitializer {
public static final float FONT_Y_OFFSET = 8;
public static final float HOTBAR_X_OFFSET = 8;

public static boolean mixin_drawItemCalledFromRenderHotbarItem;

private static ConfigHolder<ItemCountsConfig> configHolder;

public static ItemCountsConfig getConfig(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public class ItemCountsConfig implements ConfigData {
false
);

@ConfigEntry.Category("rules")
public boolean show_vanilla_count = true;

public static class ItemRenderConfig {
@AutoConfigConstructor
public ItemRenderConfig() {
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/blazingtwist/itemcounts/mixin/DrawContextMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package blazingtwist.itemcounts.mixin;

import blazingtwist.itemcounts.ItemCounts;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Environment(EnvType.CLIENT)
@Mixin(DrawContext.class)
public abstract class DrawContextMixin {

@Redirect(
method = "drawItemInSlot(" +
"Lnet/minecraft/client/font/TextRenderer;" +
"Lnet/minecraft/item/ItemStack;" +
"I" +
"I" +
"Ljava/lang/String;" +
")V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/DrawContext;" +
"drawText(" +
"Lnet/minecraft/client/font/TextRenderer;" +
"Ljava/lang/String;" +
"I" +
"I" +
"I" +
"Z" +
")I",
remap = false)
)
private int 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;
}

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

}
30 changes: 29 additions & 1 deletion src/main/java/blazingtwist/itemcounts/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void renderItemAt(ItemStack item, int x, int y, float scaleFactor, boole
"Lnet/minecraft/entity/player/PlayerEntity;" +
"Lnet/minecraft/item/ItemStack;" +
"I" +
")V", at = @At("HEAD"))
")V", at = @At("TAIL"))
public void onRenderHotbarItem(DrawContext context, int x, int y, float tickDelta, PlayerEntity player, ItemStack stack, int seed, CallbackInfo info) {
if (stack.isEmpty()) {
return;
Expand All @@ -188,4 +188,32 @@ public void onRenderHotbarItem(DrawContext context, int x, int y, float tickDelt
renderItemOverlay(config.hotbar_relativeToHotbarConfig, true, player, stack, x, y);
}

@Inject(
method = "renderHotbarItem(" +
"Lnet/minecraft/client/gui/DrawContext;" +
"I" +
"I" +
"F" +
"Lnet/minecraft/entity/player/PlayerEntity;" +
"Lnet/minecraft/item/ItemStack;" +
"I" +
")V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/DrawContext;" +
"drawItemInSlot(" +
"Lnet/minecraft/client/font/TextRenderer;" +
"Lnet/minecraft/item/ItemStack;" +
"I" +
"I" +
")V",
shift = At.Shift.BEFORE
)
)
private void onBefore_drawHotbarItem_call_drawItemInSlot(
DrawContext context, int x, int y, float tickDelta, PlayerEntity player, ItemStack stack, int seed, CallbackInfo info
) {
ItemCounts.mixin_drawItemCalledFromRenderHotbarItem = true;
}

}
3 changes: 2 additions & 1 deletion src/main/resources/assets/itemcounts/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@
"text.autoconfig.itemcounts.option.item_count_rules": "Configure how items are counted",
"text.autoconfig.itemcounts.option.item_count_rules.separateNbtData": "separate item-count by item NBT tags",
"text.autoconfig.itemcounts.option.item_count_rules.separateName": "separate item-count by item name",
"text.autoconfig.itemcounts.option.item_count_rules.separateDurability": "separate item-count by remaining durability"
"text.autoconfig.itemcounts.option.item_count_rules.separateDurability": "separate item-count by remaining durability",
"text.autoconfig.itemcounts.option.show_vanilla_count": "Show the vanilla item-counts"
}
3 changes: 2 additions & 1 deletion src/main/resources/itemcounts.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"mixins": [
],
"client": [
"InGameHudMixin"
"InGameHudMixin",
"DrawContextMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Binary file not shown.

0 comments on commit 28e0408

Please sign in to comment.