-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
368 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/teammoeg/frostedheart/mixin/client/MixinBitmapProviderDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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<DataResult<BitmapProvider.Definition>> 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;<init>(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<GlyphProvider> 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()) ); | ||
}); | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/teammoeg/frostedheart/util/MultipleRoundHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.teammoeg.frostedheart.util; | ||
|
||
public class MultipleRoundHelper { | ||
private float reminder=0; | ||
private int maximum; | ||
private int originMax; | ||
public MultipleRoundHelper(int maximum) { | ||
this.originMax=this.maximum=maximum; | ||
} | ||
public int getRounded(float value) { | ||
value-=reminder; | ||
int retval=Math.round(value); | ||
reminder=retval-value; | ||
if(retval>maximum) | ||
retval=maximum; | ||
maximum-=retval; | ||
return retval; | ||
} | ||
public int getReminder() { | ||
return maximum; | ||
} | ||
public int getPercentRounded(float value) { | ||
return getRounded(value*originMax); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/teammoeg/frostedheart/util/lang/ComponentOptimizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.teammoeg.frostedheart.util.lang; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.network.chat.Style; | ||
|
||
public class ComponentOptimizer { | ||
StringBuilder sb=new StringBuilder(); | ||
Style sty=Style.EMPTY; | ||
List<Component> calculated=new ArrayList<>(); | ||
public ComponentOptimizer() { | ||
|
||
} | ||
public void appendChar(String ch,Style style) { | ||
if(style==sty) { | ||
sb.append(ch); | ||
}else { | ||
createComponent(); | ||
sty=style; | ||
} | ||
} | ||
public void createComponent() { | ||
if(sb.length()!=0) { | ||
calculated.add(Lang.str(sb.toString()).withStyle(sty)); | ||
sb=new StringBuilder(); | ||
} | ||
sty=Style.EMPTY; | ||
|
||
} | ||
public Component build() { | ||
createComponent(); | ||
MutableComponent mstr=Lang.str(""); | ||
for(Component c:calculated) { | ||
mstr.append(c); | ||
} | ||
return mstr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/com/teammoeg/frostedheart/util/lang/FineProgressBarBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.teammoeg.frostedheart.util.lang; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import com.teammoeg.frostedheart.util.MultipleRoundHelper; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.network.chat.Style; | ||
|
||
public class FineProgressBarBuilder { | ||
private static record ProgressElement(int color,int len,String icon){ | ||
|
||
} | ||
private static final Style def_style=FHTextIcon.applyFont(Style.EMPTY); | ||
List<ProgressElement> elm=new ArrayList<>(); | ||
MutableComponent parent=Lang.str(""); | ||
MultipleRoundHelper rounder; | ||
int len; | ||
public FineProgressBarBuilder(int length) { | ||
len=length; | ||
rounder=new MultipleRoundHelper(length); | ||
} | ||
public FineProgressBarBuilder addElement(int color,String icon,float percent) { | ||
elm.add(new ProgressElement(color,rounder.getPercentRounded(percent),icon)); | ||
return this; | ||
} | ||
public List<Component> build() { | ||
if(elm.isEmpty()) { | ||
return Arrays.asList(Lang.str("\uF510"+"\uF512".repeat(len-2)+"\uF510").withStyle(def_style),Component.empty()); | ||
} | ||
List<Component> siblings=new ArrayList<>(); | ||
StringBuilder sb=new StringBuilder(); | ||
int total=0; | ||
for(ProgressElement pe:elm) { | ||
siblings.add(Lang.str("\uF510".repeat(pe.len())).withStyle(t->t.withColor(pe.color))); | ||
total+=pe.len(); | ||
//System.out.println(pe.len); | ||
int prelen=(pe.len()-8)/2; | ||
for(int i=0;i<pe.len();i++) { | ||
if(i==prelen&&pe.icon()!=null) { | ||
sb.append(pe.icon()); | ||
i+=8; | ||
}else { | ||
sb.append("\uF511"); | ||
} | ||
} | ||
} | ||
|
||
int remainLen=len-total; | ||
if(remainLen>0) { | ||
siblings.add(Lang.str("\uF512".repeat(remainLen-1)+"\uF510")); | ||
} | ||
MutableComponent mstr=Lang.str("").withStyle(def_style); | ||
siblings.forEach(mstr::append); | ||
return Arrays.asList(mstr,Lang.str(sb.toString()).withStyle(def_style)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/com/teammoeg/frostedheart/util/mixin/ChangeAdvanceGlyph.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.teammoeg.frostedheart.util.mixin; | ||
|
||
import java.util.function.Function; | ||
|
||
import com.mojang.blaze3d.font.GlyphInfo; | ||
import com.mojang.blaze3d.font.SheetGlyphInfo; | ||
|
||
import net.minecraft.client.gui.font.glyphs.BakedGlyph; | ||
|
||
public record ChangeAdvanceGlyph(int advance,GlyphInfo nested) implements GlyphInfo { | ||
|
||
|
||
@Override | ||
public float getAdvance() { | ||
return advance; | ||
} | ||
|
||
@Override | ||
public BakedGlyph bake(Function<SheetGlyphInfo, BakedGlyph> p_231088_) { | ||
return nested.bake(p_231088_); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.