Skip to content

Commit

Permalink
re-implement with no mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Dec 27, 2024
1 parent c193536 commit fb7f8fc
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static List<Component> 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;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Component> 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<Component> siblings=new ArrayList<>();
StringBuilder sb=new StringBuilder();
int lastIconReminder=0;
int progressedLength=0;
List<Integer> 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<lastIconReminder)
remlen=lastIconReminder;
lastIconReminder=remlen+8-pe.len();
if(lastIconReminder<0)lastIconReminder=0;
iconPoss.add(remlen+progressedLength);
progressedLength+=pe.len();
}else {
iconPoss.add(-1);
}
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");
}
}
Iterator<ProgressElement> 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<len;i++) {
int iconPos=iconPoss.indexOf(i-8);
if(iconPos!=-1) {
//System.out.println("Appending icon "+iconPos);
co.appendChar("\uF511"+elm.get(iconPos).icon+"\uF513", def_style);
}
if(i-offset>=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();
}

}
4 changes: 1 addition & 3 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init>(FLcom/mojang/blaze3d/platform/NativeImage;IIIIII)V # <init>
public net.minecraftforge.common.capabilities.CapabilityManager providers
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "bitmap",
"file": "frostedheart:font/white.png",
"height":8,
"ascent":519,
"ascent":7,
"chars":[
"\uF510"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"providers": [
{
"type": "space",
"advances":{
"\uF511":-8,
"\uF513":-1
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "bitmap",
"file": "frostedheart:font/white_blank.png",
"height":8,
"ascent":519,
"ascent":7,
"chars":[
"\uF512"
]
Expand Down
Binary file not shown.
3 changes: 1 addition & 2 deletions src/main/resources/frostedheart.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
"client.PrimaryLevelDataMixin",
"client.ToastComponentMixin",
"create.MixinOpenConfigButtonHandler",
"oculus.IrisRenderingPipelineAccess",
"client.MixinBitmapProviderDefinition"
"oculus.IrisRenderingPipelineAccess"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit fb7f8fc

Please sign in to comment.