From fb7f8fc7adf0cbe037d363299c5b40e589783b88 Mon Sep 17 00:00:00 2001 From: khjxiaogu <54445543+khjxiaogu@users.noreply.github.com> Date: Fri, 27 Dec 2024 18:18:37 +0800 Subject: [PATCH] re-implement with no mixin --- .../health/tooltip/FoodNutritionStats.java | 2 +- .../client/MixinBitmapProviderDefinition.java | 61 ------------------ .../util/lang/ComponentOptimizer.java | 5 +- .../util/lang/FineProgressBarBuilder.java | 59 +++++++++++------ .../resources/META-INF/accesstransformer.cfg | 4 +- .../frostedheart/font/include/white.json | 2 +- .../frostedheart/font/include/white_back.json | 11 ++++ .../font/include/white_blank.json | 2 +- .../frostedheart/textures/font/white_back.png | Bin 100 -> 0 bytes src/main/resources/frostedheart.mixins.json | 3 +- 10 files changed, 59 insertions(+), 90 deletions(-) delete mode 100644 src/main/java/com/teammoeg/frostedheart/mixin/client/MixinBitmapProviderDefinition.java create mode 100644 src/main/resources/assets/frostedheart/font/include/white_back.json delete mode 100644 src/main/resources/assets/frostedheart/textures/font/white_back.png diff --git a/src/main/java/com/teammoeg/frostedheart/content/health/tooltip/FoodNutritionStats.java b/src/main/java/com/teammoeg/frostedheart/content/health/tooltip/FoodNutritionStats.java index ae639d1f4..77ab9cce6 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/health/tooltip/FoodNutritionStats.java +++ b/src/main/java/com/teammoeg/frostedheart/content/health/tooltip/FoodNutritionStats.java @@ -73,7 +73,7 @@ public static List getFoodStats(Item item, ItemStack stack, Player pl if(nutrition.vegetable()>0) { builder.addElement(VEGETABLE_COLOR, "\uF503",nutrition.vegetable()); } - list.addAll(builder.build()); + list.add(builder.build()); } return list; } diff --git a/src/main/java/com/teammoeg/frostedheart/mixin/client/MixinBitmapProviderDefinition.java b/src/main/java/com/teammoeg/frostedheart/mixin/client/MixinBitmapProviderDefinition.java deleted file mode 100644 index f353946b6..000000000 --- a/src/main/java/com/teammoeg/frostedheart/mixin/client/MixinBitmapProviderDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.teammoeg.frostedheart.mixin.client; - -import java.io.InputStream; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import com.mojang.blaze3d.font.GlyphInfo; -import com.mojang.blaze3d.font.GlyphProvider; -import com.mojang.blaze3d.platform.NativeImage; -import com.mojang.serialization.DataResult; -import com.teammoeg.frostedheart.util.mixin.ChangeAdvanceGlyph; - -import it.unimi.dsi.fastutil.ints.IntAVLTreeSet; -import it.unimi.dsi.fastutil.ints.IntSet; -import net.minecraft.client.gui.font.CodepointMap; -import net.minecraft.client.gui.font.providers.BitmapProvider; -import net.minecraft.client.gui.font.providers.BitmapProvider.Glyph; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ResourceManager; - -@Mixin(net.minecraft.client.gui.font.providers.BitmapProvider.Definition.class) -public class MixinBitmapProviderDefinition { - int advance=-256; - @Shadow - @Mutable - int ascent; - public MixinBitmapProviderDefinition() { - - } - @Inject(at=@At("HEAD"),method="validate") - private static void fh$validate(BitmapProvider.Definition p_286662_,CallbackInfoReturnable> res){ - if(p_286662_.ascent()>0xFF&&p_286662_.ascent()>p_286662_.height()) { - ((MixinBitmapProviderDefinition)(Object)p_286662_).advance=((p_286662_.ascent()>>8)&0xff)-1; - if(((MixinBitmapProviderDefinition)(Object)p_286662_).advance>=128) - ((MixinBitmapProviderDefinition)(Object)p_286662_).advance=((MixinBitmapProviderDefinition)(Object)p_286662_).advance-256; - //System.out.println("assum advance "+((MixinBitmapProviderDefinition)(Object)p_286662_).advance); - ((MixinBitmapProviderDefinition)(Object)p_286662_).ascent&=0Xff; - } - - } - @Inject(at=@At(value="INVOKE",target="Lnet/minecraft/client/gui/font/providers/BitmapProvider;(Lcom/mojang/blaze3d/platform/NativeImage;Lnet/minecraft/client/gui/font/CodepointMap;)V"),method="load",locals=LocalCapture.CAPTURE_FAILSOFT) - private void fh$load(ResourceManager p_286694_, CallbackInfoReturnable cir, ResourceLocation resourcelocation, InputStream inputstream, NativeImage nativeimage, int i, int j, int k, int l, float f, CodepointMap codepointmap) { - if(advance>-256) { - IntSet keys=new IntAVLTreeSet(codepointmap.keySet()); - //System.out.println("modifying fonts"); - keys.forEach(t->{ - BitmapProvider.Glyph gi=(Glyph) codepointmap.get(t); - //System.out.println(t+":"+gi); - if(gi!=null) - codepointmap.put(t, new BitmapProvider.Glyph(gi.scale(),gi.image(), gi.offsetX(), gi.offsetY(), gi.width(), gi.height(), advance, gi.ascent()) ); - }); - } - } - -} diff --git a/src/main/java/com/teammoeg/frostedheart/util/lang/ComponentOptimizer.java b/src/main/java/com/teammoeg/frostedheart/util/lang/ComponentOptimizer.java index 94d327176..d7127a83b 100644 --- a/src/main/java/com/teammoeg/frostedheart/util/lang/ComponentOptimizer.java +++ b/src/main/java/com/teammoeg/frostedheart/util/lang/ComponentOptimizer.java @@ -15,12 +15,11 @@ public ComponentOptimizer() { } public void appendChar(String ch,Style style) { - if(style==sty) { - sb.append(ch); - }else { + if(style!=sty) { createComponent(); sty=style; } + sb.append(ch); } public void createComponent() { if(sb.length()!=0) { diff --git a/src/main/java/com/teammoeg/frostedheart/util/lang/FineProgressBarBuilder.java b/src/main/java/com/teammoeg/frostedheart/util/lang/FineProgressBarBuilder.java index f23880bec..23c28d596 100644 --- a/src/main/java/com/teammoeg/frostedheart/util/lang/FineProgressBarBuilder.java +++ b/src/main/java/com/teammoeg/frostedheart/util/lang/FineProgressBarBuilder.java @@ -28,35 +28,58 @@ public FineProgressBarBuilder addElement(int color,String icon,float percent) { elm.add(new ProgressElement(color,rounder.getPercentRounded(percent),icon)); return this; } - public List build() { + public Component build() { if(elm.isEmpty()) { - return Arrays.asList(Lang.str("\uF510"+"\uF512".repeat(len-2)+"\uF510").withStyle(def_style),Component.empty()); + return Lang.str("\uF510\uF513"+"\uF512\uF513".repeat(len-2)+"\uF510").withStyle(def_style); } - List siblings=new ArrayList<>(); - StringBuilder sb=new StringBuilder(); + int lastIconReminder=0; + int progressedLength=0; + List iconPoss=new ArrayList<>(); int total=0; for(ProgressElement pe:elm) { - siblings.add(Lang.str("\uF510".repeat(pe.len())).withStyle(t->t.withColor(pe.color))); + if(pe.icon!=null) { + int remlen=(pe.len()-8)/2; + if(remlen celm=elm.iterator(); + ProgressElement cur=celm.next(); + Style cstyle=def_style.withColor(cur.color()); + int offset=0; + + //StringBuilder iconBuilder=new StringBuilder(); + ComponentOptimizer co=new ComponentOptimizer(); + for(int i=0;i=cur.len()) { + offset+=cur.len(); + if(!celm.hasNext()) + break; + cur=celm.next(); + cstyle=def_style.withColor(cur.color()); + } + co.appendChar("\uF510\uF513", cstyle); } - int remainLen=len-total; if(remainLen>0) { - siblings.add(Lang.str("\uF512".repeat(remainLen-1)+"\uF510")); + //System.out.println(remainLen); + co.appendChar("\uF512\uF513".repeat(remainLen-1), def_style); + co.appendChar("\uF510", def_style); } - MutableComponent mstr=Lang.str("").withStyle(def_style); - siblings.forEach(mstr::append); - return Arrays.asList(mstr,Lang.str(sb.toString()).withStyle(def_style)); + return co.build(); } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index c30ee60fb..d95e84b19 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -18,6 +18,4 @@ public net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlac public net.minecraft.world.damagesource.DamageSource f_19330_ # hungerDamage public net.minecraftforge.common.capabilities.CapabilityProvider serializeCaps public net.minecraft.client.renderer.GameRenderer m_109141_(Lnet/minecraft/client/Camera;FZ)D # getFov -public net.minecraftforge.common.capabilities.CapabilityManager providers -public net.minecraft.client.gui.font.providers.BitmapProvider$Glyph -public net.minecraft.client.gui.font.providers.BitmapProvider$Glyph (FLcom/mojang/blaze3d/platform/NativeImage;IIIIII)V # \ No newline at end of file +public net.minecraftforge.common.capabilities.CapabilityManager providers \ No newline at end of file diff --git a/src/main/resources/assets/frostedheart/font/include/white.json b/src/main/resources/assets/frostedheart/font/include/white.json index c3a9d6232..3ce3a6f77 100644 --- a/src/main/resources/assets/frostedheart/font/include/white.json +++ b/src/main/resources/assets/frostedheart/font/include/white.json @@ -4,7 +4,7 @@ "type": "bitmap", "file": "frostedheart:font/white.png", "height":8, - "ascent":519, + "ascent":7, "chars":[ "\uF510" ] diff --git a/src/main/resources/assets/frostedheart/font/include/white_back.json b/src/main/resources/assets/frostedheart/font/include/white_back.json new file mode 100644 index 000000000..077c839c0 --- /dev/null +++ b/src/main/resources/assets/frostedheart/font/include/white_back.json @@ -0,0 +1,11 @@ +{ + "providers": [ + { + "type": "space", + "advances":{ + "\uF511":-8, + "\uF513":-1 + } + } + ] +} diff --git a/src/main/resources/assets/frostedheart/font/include/white_blank.json b/src/main/resources/assets/frostedheart/font/include/white_blank.json index 0d98f2567..b71a90088 100644 --- a/src/main/resources/assets/frostedheart/font/include/white_blank.json +++ b/src/main/resources/assets/frostedheart/font/include/white_blank.json @@ -4,7 +4,7 @@ "type": "bitmap", "file": "frostedheart:font/white_blank.png", "height":8, - "ascent":519, + "ascent":7, "chars":[ "\uF512" ] diff --git a/src/main/resources/assets/frostedheart/textures/font/white_back.png b/src/main/resources/assets/frostedheart/textures/font/white_back.png deleted file mode 100644 index 2defc6dd7cc61192045aa1d5f518f7879dda0572..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 100 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1SGw4HSYi^&H|6fVg?3oVGw3ym^DWNC@ALX s;uyjao&4wje|u)L15J7i%+0|}3^6{;(x2ac0GYwy>FVdQ&MBb@0DC_c7ytkO diff --git a/src/main/resources/frostedheart.mixins.json b/src/main/resources/frostedheart.mixins.json index 602593097..32462c960 100644 --- a/src/main/resources/frostedheart.mixins.json +++ b/src/main/resources/frostedheart.mixins.json @@ -76,8 +76,7 @@ "client.PrimaryLevelDataMixin", "client.ToastComponentMixin", "create.MixinOpenConfigButtonHandler", - "oculus.IrisRenderingPipelineAccess", - "client.MixinBitmapProviderDefinition" + "oculus.IrisRenderingPipelineAccess" ], "injectors": { "defaultRequire": 1