Skip to content

Commit

Permalink
Merge pull request #21 from BlazingTwist/1.20.5
Browse files Browse the repository at this point in the history
1.20.5 - 1.20.6
  • Loading branch information
BlazingTwist authored May 4, 2024
2 parents 28e0408 + 905f892 commit bca164c
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
# Use these Java versions
java: [
17 # Minimum supported by Minecraft
21 # Minimum supported by Minecraft 1.20.5
]
# and run on both Linux and Windows
os: [ubuntu-20.04, windows-latest]
Expand Down
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.20.1
Built for version 1.20.5

[Curseforge release](https://www.curseforge.com/minecraft/mc-mods/item-counts-fabric)

Expand Down
18 changes: 4 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version + "+mc" + project.minecraft_version
Expand All @@ -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:[11.0,12.0)") {
modImplementation("me.shedaniel.cloth:cloth-config-fabric:[14.0,15.0)") {
exclude(group: "net.fabricmc.fabric-api")
}
modImplementation("com.terraformersmc:modmenu:[7.1,8.0)") {
modImplementation("com.terraformersmc:modmenu:[10.0,11.0)") {
exclude group: "net.fabricmc.fabric-api"
}

Expand All @@ -53,13 +53,6 @@ tasks.withType(JavaCompile).configureEach {
it.options.release = 17
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
Expand All @@ -74,9 +67,6 @@ publishing {
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.1
loader_version=0.14.21
minecraft_version=1.20.5
yarn_mappings=1.20.5+build.1
loader_version=0.15.10

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

# Dependencies
fabric_version=0.83.0+1.20.1
fabric_version=0.97.5+1.20.5
6 changes: 4 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.stream.IntStream;
import java.util.stream.Stream;

import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
Expand Down Expand Up @@ -187,14 +188,7 @@ private boolean countStacksSeparately(ItemStack a, ItemStack b) {
}

private boolean nbtDataMatches(ItemStack a, ItemStack b) {
if (a.hasNbt() != b.hasNbt()) {
return false;
}
if (!a.hasNbt() || a.getNbt() == null) {
// neither itemStack has NBT data
return true;
}
return a.getNbt().equals(b.getNbt());
return a.getComponents().equals(b.getComponents());
}

private boolean nameMatches(ItemStack a, ItemStack b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public abstract class DrawContextMixin {
"I" +
"I" +
"Z" +
")I",
remap = false)
")I"
)
)
private int redirectDrawItemSlotText(
DrawContext instance, TextRenderer textRenderer, String text, int x, int y, int color, boolean shadow
Expand Down
128 changes: 55 additions & 73 deletions src/main/java/blazingtwist/itemcounts/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import blazingtwist.itemcounts.ItemCounts;
import blazingtwist.itemcounts.config.ItemCountsConfig;
import blazingtwist.itemcounts.util.ColorHelper;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
Expand All @@ -13,15 +11,13 @@
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.PlayerScreenHandler;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -37,42 +33,40 @@ public abstract class InGameHudMixin {
@Final
private MinecraftClient client;

@Shadow
@Final
private ItemRenderer itemRenderer;

@Shadow
private int scaledWidth;

@Shadow
private int scaledHeight;

private void renderItemOverlay(ItemCountsConfig.ItemRenderConfig config, boolean onHotbar,
private void renderItemOverlay(DrawContext context, ItemCountsConfig.ItemRenderConfig config, boolean onHotbar,
PlayerEntity player, ItemStack stack, int x, int y) {
if (!config.enabled) {
return;
}
if (!onHotbar) {
x = scaledWidth / 2;
y = scaledHeight / 2;
x = context.getScaledWindowWidth() / 2;
y = context.getScaledWindowHeight() / 2;
}
x += config.offset.x;
y += config.offset.y;

boolean didRenderText = renderItemText(config, onHotbar, player, stack, x, y);
if (config.iconOption.shouldShowIcon(didRenderText)) {
renderItemAt(stack, x, y, config.offset.textScale, onHotbar);
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);
}
}

private boolean renderItemText(ItemCountsConfig.ItemRenderConfig config, boolean onHotbar,
PlayerEntity player, ItemStack stack, int x, int y) {
String text;
int color = -1;
private boolean shouldRenderItem(ItemCountsConfig.ItemRenderConfig config, PlayerEntity player, ItemStack stack) {
if (stack.isDamageable() && config.durabilityFilter.showDurabilityInsteadOfItemCount(stack)) {
return config.durabilityOption.shouldShowDurability(stack);
} else {
return config.countOption.shouldShowCount(player, stack);
}
}

private void renderItemText(DrawContext context, ItemCountsConfig.ItemRenderConfig config, boolean onHotbar,
PlayerEntity player, ItemStack stack, int x, int y) {
final String text;
final int color;
if (stack.isDamageable() && config.durabilityFilter.showDurabilityInsteadOfItemCount(stack)) {
if (!config.durabilityOption.shouldShowDurability(stack)) {
return false;
}
int maxDamage = stack.getMaxDamage();
int currentDamage = stack.getDamage();
text = "" + (maxDamage - currentDamage);
Expand All @@ -83,80 +77,68 @@ private boolean renderItemText(ItemCountsConfig.ItemRenderConfig config, boolean
color = stack.getItemBarColor();
}
} else {
if (!config.countOption.shouldShowCount(player, stack)) {
return false;
}
text = "" + ItemCounts.getConfig().item_count_rules.getTotalItemCount(player, stack);
if (config.colors.enableCustomColors) {
color = config.colors.colorItemCount;
}
color = config.colors.enableCustomColors ? config.colors.colorItemCount : -1;
}

renderTextAt(config, text, color, x, y, onHotbar);
return true;
renderTextAt(context, config, text, color, x, y, onHotbar);
}

private void renderTextAt(ItemCountsConfig.ItemRenderConfig config,
private void renderTextAt(DrawContext context, ItemCountsConfig.ItemRenderConfig config,
String text, int color, int x, int y, boolean isOnHotbar) {
float scaleFactor = config.offset.textScale;
TextRenderer renderer = client.textRenderer;
MatrixStack matrixStack = new MatrixStack();
matrixStack.translate(0, ItemCounts.FONT_Y_OFFSET * scaleFactor, 250);
MatrixStack matrices = context.getMatrices();
matrices.push();
matrices.translate(0, ItemCounts.FONT_Y_OFFSET * scaleFactor, 200f);
if (isOnHotbar) {
matrixStack.translate(ItemCounts.HOTBAR_X_OFFSET * scaleFactor, 0, 0);
matrices.translate(ItemCounts.HOTBAR_X_OFFSET * scaleFactor, 0, 0);
}
matrixStack.scale(scaleFactor, scaleFactor, 1);
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
matrices.scale(scaleFactor, scaleFactor, 1);

TextRenderer renderer = client.textRenderer;
renderer.draw(
text,
config.offset.anchor.applyAnchorOffset(x / scaleFactor, text, renderer),
config.offset.anchor.applyAnchorOffset(x / scaleFactor, text, client.textRenderer),
(y / scaleFactor) - (ItemCounts.FONT_HEIGHT / 2),
color >= 0 ? color : 16777215,
true,
matrixStack.peek().getPositionMatrix(),
immediate,
matrices.peek().getPositionMatrix(),
context.getVertexConsumers(),
TextRenderer.TextLayerType.NORMAL,
0,
15728880,
false
renderer.isRightToLeft()
);
immediate.draw();

matrices.pop();
}

private void renderItemAt(ItemStack item, int x, int y, float scaleFactor, boolean isOnHotbar) {
//textureManager.getTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).setFilter(false, false);
RenderSystem.setShaderTexture(0, PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
RenderSystem.enableBlend();
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.translate(x, y, 100.0F);
private void renderItemAt(DrawContext context, ItemStack item, int x, int y, float scaleFactor, boolean isOnHotbar) {
ItemRenderer itemRenderer = client.getItemRenderer();
BakedModel model = itemRenderer.getModel(item, null, null, 0);

MatrixStack contextMatrices = context.getMatrices();
contextMatrices.push();
contextMatrices.translate(x, y, 150f);
if (isOnHotbar) {
matrixStack.translate(ItemCounts.HOTBAR_X_OFFSET * scaleFactor, 0, 0);
contextMatrices.translate(ItemCounts.HOTBAR_X_OFFSET * scaleFactor, 0, 0);
}
matrixStack.scale(1.0F, -1.0F, 1.0F);
matrixStack.scale(16.0F, 16.0F, 16.0F);
RenderSystem.applyModelViewMatrix();
MatrixStack matrixStack2 = new MatrixStack();
matrixStack2.scale(scaleFactor, scaleFactor, scaleFactor);
contextMatrices.scale(16.0F, -16.0F, 16.0F);
contextMatrices.scale(scaleFactor, scaleFactor, scaleFactor);

VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
BakedModel model = itemRenderer.getModel(item, null, null, 0);
boolean bl = !model.isSideLit();
if (bl) {
DiffuseLighting.disableGuiDepthLighting();
}

itemRenderer.renderItem(item, ModelTransformationMode.GUI, false, matrixStack2, immediate, 15728880, OverlayTexture.DEFAULT_UV, model);
itemRenderer.renderItem(item, ModelTransformationMode.GUI, false, contextMatrices, immediate, 15728880, OverlayTexture.DEFAULT_UV, model);
immediate.draw();
RenderSystem.enableDepthTest();
if (bl) {
DiffuseLighting.enableGuiDepthLighting();
}

matrixStack.pop();
RenderSystem.applyModelViewMatrix();
contextMatrices.pop();
}

@Inject(method = "renderHotbarItem(" +
Expand All @@ -176,16 +158,16 @@ public void onRenderHotbarItem(DrawContext context, int x, int y, float tickDelt
ItemCountsConfig config = ItemCounts.getConfig();

if (player.getMainHandStack() == stack) {
renderItemOverlay(config.mainHand_relativeToCrosshairConfig, false, player, stack, x, y);
renderItemOverlay(config.mainHand_relativeToHotbarConfig, true, player, stack, x, y);
renderItemOverlay(context, config.mainHand_relativeToCrosshairConfig, false, player, stack, x, y);
renderItemOverlay(context, config.mainHand_relativeToHotbarConfig, true, player, stack, x, y);
}

if (player.getOffHandStack() == stack) {
renderItemOverlay(config.offHand_relativeToCrosshairConfig, false, player, stack, x, y);
renderItemOverlay(config.offHand_relativeToHotbarConfig, true, player, stack, x, y);
renderItemOverlay(context, config.offHand_relativeToCrosshairConfig, false, player, stack, x, y);
renderItemOverlay(context, config.offHand_relativeToHotbarConfig, true, player, stack, x, y);
}

renderItemOverlay(config.hotbar_relativeToHotbarConfig, true, player, stack, x, y);
renderItemOverlay(context, config.hotbar_relativeToHotbarConfig, true, player, stack, x, y);
}

@Inject(
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.14.21",
"fabricloader": ">=0.15.10",
"fabric": "*",
"minecraft": "~1.20.1",
"minecraft": "~1.20.5",
"java": ">=17"
},
"suggests": {
Expand Down

0 comments on commit bca164c

Please sign in to comment.