Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ypekkatre committed Oct 7, 2024
1 parent c982639 commit 3446cf2
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
import io.github.darkkronicle.kronhud.util.DrawPosition;
import io.github.darkkronicle.kronhud.util.ItemUtil;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.PotionItem;
import net.minecraft.util.Identifier;

import java.util.List;
Expand Down Expand Up @@ -40,11 +45,36 @@ public void renderItem(DrawContext context, ItemStack stack, int x, int y) {

public void renderMainItem(DrawContext context, ItemStack stack, int x, int y) {
RenderUtil.drawItem(context, stack, x, y);
String total = String.valueOf(ItemUtil.getTotal(client, stack));
if (total.equals("1")) {
total = null;
int total = ItemUtil.getTotal(client, stack);;

if (stack.getMaxCount() == 1) {
Item item = stack.getItem();
if ((Object)item instanceof PotionItem potionitem) {
total = 0;
PotionContentsComponent contents = stack.get(DataComponentTypes.POTION_CONTENTS);
boolean isSplash = potionitem == Items.SPLASH_POTION;
boolean isLingering = potionitem == Items.LINGERING_POTION;
if (contents != null) {
Iterable<StatusEffectInstance> effects = contents.getEffects();
for (ItemStack st : ItemUtil.getItems(client)) {
if (st == null) continue;
Item it = st.getItem();
if (it == null) continue;
if ((Object) it instanceof PotionItem potionitem2) {
PotionContentsComponent contents2 = st.get(DataComponentTypes.POTION_CONTENTS);
boolean isSplash2 = potionitem2 == Items.SPLASH_POTION;
boolean isLingering2 = potionitem2 == Items.LINGERING_POTION;
if (contents2 == null) continue;
if (contents2.getEffects().equals(effects)
&& isSplash == isSplash2
&& isLingering == isLingering2) total += 1;
}
}
}
}
}
context.drawItemInSlot(client.textRenderer, stack, x, y, total);

context.drawItemInSlot(client.textRenderer, stack, x, y, total > 1 ? String.valueOf(total) : null);
}

@Override
Expand Down

0 comments on commit 3446cf2

Please sign in to comment.