Skip to content

Commit a54cef2

Browse files
committed
Move to pc
1 parent 23acd4e commit a54cef2

File tree

10 files changed

+287
-92
lines changed

10 files changed

+287
-92
lines changed

src/main/java/llc/redstone/hysentials/Hysentials.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import llc.redstone.hysentials.macrowheel.MacroWheelData;
3434
import llc.redstone.hysentials.quest.Quest;
35+
import llc.redstone.hysentials.renderer.text.FancyFormattingKt;
3536
import llc.redstone.hysentials.util.*;
3637
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
3738
import llc.redstone.hysentials.command.*;
@@ -152,8 +153,6 @@ public void onFMLPreInitialization(FMLPreInitializationEvent event) {
152153
public void init(FMLInitializationEvent event) {
153154
registerImages();
154155
config = new HysentialsConfig();
155-
updateAndAdd();
156-
157156
File file = new File(modDir, "./config/hysentials");
158157
if (!file.exists() && !file.mkdirs()) {
159158
throw new RuntimeException("Failed to create config directory! Please report this to sinender on Discord");
@@ -240,11 +239,11 @@ public void postInit(FMLPostInitializationEvent event) {
240239
isHytils = Loader.isModLoaded("hytils-reborn");
241240
chatHandler.init();
242241

243-
imageIconRenderer = new ImageIconRenderer();
242+
// imageIconRenderer = new ImageIconRenderer();
244243
minecraftFont = Minecraft.getMinecraft().fontRendererObj;
245-
if (FormattingConfig.fancyRendering()) {
246-
Minecraft.getMinecraft().fontRendererObj = imageIconRenderer;
247-
}
244+
// if (FormattingConfig.fancyRendering()) {
245+
// Minecraft.getMinecraft().fontRendererObj = imageIconRenderer;
246+
// }
248247

249248
registerHandlers();
250249

@@ -257,6 +256,13 @@ public void postInit(FMLPostInitializationEvent event) {
257256
if (config.macroWheelHud.position.getX() == 0 && config.macroWheelHud.position.getY() == 0) {
258257
config.macroWheelHud.position.setPosition((Renderer.screen.getWidth() / 2f) - (34*5f) / 2, (Renderer.screen.getHeight() / 2f) - (34*5f) / 2);
259258
}
259+
260+
for (int i = 1000; 65000 > i ; i++) {
261+
if (Minecraft.getMinecraft().fontRendererObj.getCharWidth((char) i) > 0) {
262+
FancyFormattingKt.getChars().put((char) i, Minecraft.getMinecraft().fontRendererObj.getCharWidth((char) i));
263+
}
264+
}
265+
updateAndAdd();
260266
}
261267
@Mod.EventHandler
262268
public void finishedStarting(FMLLoadCompleteEvent event) {

src/main/java/llc/redstone/hysentials/config/hysentialmods/ReplaceConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.lang.reflect.Field;
2020
import java.util.*;
21+
import java.util.concurrent.ConcurrentHashMap;
2122

2223
public class ReplaceConfig extends Config {
2324
@Switch(
@@ -86,8 +87,8 @@ protected BasicOption getCustomOption(Field field, CustomOption annotation, Opti
8687
return option;
8788
}
8889

89-
public HashMap<String, String> getAllActiveReplacements() {
90-
HashMap<String, String> replacements = new HashMap<>();
90+
public ConcurrentHashMap<String, String> getAllActiveReplacements() {
91+
ConcurrentHashMap<String, String> replacements = new ConcurrentHashMap<>();
9192
for (ReplaceStuff replaceStuff : globalReplacements) {
9293
replacements.putAll(replaceStuff.replacements);
9394
}

src/main/java/llc/redstone/hysentials/handlers/imageicons/ImageIcon.java

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
import java.io.InputStream;
2323
import java.util.*;
2424
import java.util.List;
25+
import java.util.concurrent.atomic.AtomicBoolean;
2526
import java.util.regex.Matcher;
2627
import java.util.regex.Pattern;
2728

29+
import static llc.redstone.hysentials.renderer.text.FancyFormattingKt.getChars;
30+
2831
public class ImageIcon {
2932
public static HashMap<String, ImageIcon> imageIcons = new HashMap<>();
3033
public static Random random = new Random();
@@ -37,6 +40,8 @@ public class ImageIcon {
3740
public int height;
3841
public boolean emoji;
3942

43+
public String replacement = null;
44+
4045
public ImageIcon(String name, ResourceLocation resourceLocation, boolean emoji) {
4146
this.name = name;
4247
this.resourceLocation = resourceLocation;
@@ -95,6 +100,7 @@ public void handleImageIcon() throws IOException {
95100
this.dynamicTexture = new DynamicTexture(image);
96101
// this.resourceLocation = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation(this.name, this.dynamicTexture);
97102
}
103+
setReplacement();
98104
}
99105

100106
public static void reloadIcons() {
@@ -137,32 +143,71 @@ public int getHeight() {
137143

138144
public static Pattern stringPattern = Pattern.compile(":([a-z_\\-0-9?]+):", 2);
139145

140-
public int renderImage(float x, float y, boolean shadow, int oldColor, UUID uuid, float alpha) {
141-
if (emoji && uuid != null && !CosmeticManager.hasCosmetic(uuid, "hymojis")) {
142-
return -1;
143-
}
146+
public void setReplacement() {
144147
int width = this.getWidth();
145148
int height = this.getHeight();
146149
float scaledHeight = 9.0f / height;
150+
float updatedHeight = height * scaledHeight;
151+
float updatedWidth = width * scaledHeight;
152+
153+
int currentWidth = 0;
154+
boolean isFirst = true;
155+
AtomicBoolean breaks = new AtomicBoolean(false);
156+
StringBuilder string = new StringBuilder();
157+
while (currentWidth < updatedWidth) {
158+
Integer charWidth = null;
159+
for (Map.Entry<Character, Integer> entry : getChars().entrySet()) {
160+
if (entry.getValue() + currentWidth <= updatedWidth) {
161+
charWidth = entry.getValue() + 1;
162+
break;
163+
}
164+
}
165+
if (charWidth == null) {
166+
break;
167+
}
168+
currentWidth += charWidth;
169+
List<Character> charKeys = new ArrayList<>();
170+
for (Map.Entry<Character, Integer> entry : getChars().entrySet()) {
171+
if (entry.getValue().equals(charWidth)) {
172+
if (isFirst) {
173+
imageIcons.values().stream().filter(icon -> icon.replacement != null && !icon.replacement.isEmpty() && icon.replacement.charAt(0) == entry.getKey()).findFirst().ifPresent(icon -> {
174+
breaks.set(true);
175+
});
176+
if (breaks.get()) {
177+
continue;
178+
}
179+
isFirst = false;
180+
}
181+
charKeys.add(entry.getKey());
182+
}
183+
}
184+
char charKey = charKeys.get(new Random().nextInt(charKeys.size()));
185+
string.append(charKey);
186+
}
187+
System.out.println("Using " + string + " for " + name);
188+
replacement = string.toString();
189+
}
147190

148-
GlStateManager.pushMatrix();
191+
public float renderImage(float x, float y, boolean shadow, int oldColor, float alpha) {
192+
int width = this.getWidth();
193+
int height = this.getHeight();
194+
float scaledHeight = 9.0f / height;
195+
float updatedHeight = height * scaledHeight;
196+
float updatedWidth = width * scaledHeight;
149197

150198
dynamicTexture.updateDynamicTexture();
151199

152-
GlStateManager.scale(scaledHeight, scaledHeight, scaledHeight);
153200
int textColor = Integer.parseInt("FFFFFF", 16);
154201
if (shadow) {
155202
textColor = (textColor & 16579836) >> 2 | textColor & -16777216;
156203
}
157204
GlStateManager.color((float) (textColor >> 16) / 255.0F, (float) (textColor >> 8 & 255) / 255.0F, (float) (textColor & 255) / 255.0F, alpha);
158-
drawModalRectWithCustomSizedTexture(x * (1 / scaledHeight), y * (1 / scaledHeight), 0, 0, width, height, width, height);
205+
drawModalRectWithCustomSizedTexture(x, y, 0f, 0f, updatedWidth, updatedHeight, updatedWidth, updatedHeight);
159206
GlStateManager.color((float) (oldColor >> 16) / 255.0F, (float) (oldColor >> 8 & 255) / 255.0F, (float) (oldColor & 255) / 255.0F, alpha);
160-
GlStateManager.popMatrix();
161-
162207
return (int) (width * scaledHeight);
163208
}
164209

165-
public static void drawModalRectWithCustomSizedTexture(double x, double y, float u, float v, int width, int height, float textureWidth, float textureHeight) {
210+
public static void drawModalRectWithCustomSizedTexture(double x, double y, float u, float v, float width, float height, float textureWidth, float textureHeight) {
166211
float f = 1.0F / textureWidth;
167212
float g = 1.0F / textureHeight;
168213
GL11.glBegin(GL11.GL_QUADS);

src/main/java/llc/redstone/hysentials/mixin/GuiUtilRCMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private static String onTrimStringToWidth(FontRenderer fr, String c0, int c1, bo
2424
if (!FormattingConfig.fancyRendering()) {
2525
return fr.trimStringToWidth(c0, c1, c2);
2626
}
27-
return Hysentials.INSTANCE.imageIconRenderer.trimStringToWidth(c0, c1, c2);
27+
// return Hysentials.INSTANCE.imageIconRenderer.trimStringToWidth(c0, c1, c2);
28+
return fr.trimStringToWidth(c0, c1, c2);
2829
}
2930
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package llc.redstone.hysentials.mixin.fancyformatting;
2+
3+
import llc.redstone.hysentials.handlers.imageicons.ImageIcon;
4+
import llc.redstone.hysentials.renderer.text.FancyFormattingKt;
5+
import net.minecraft.client.gui.FontRenderer;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Shadow;
8+
import org.spongepowered.asm.mixin.Unique;
9+
import org.spongepowered.asm.mixin.injection.*;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
@Mixin(value = FontRenderer.class, priority = 1004)
17+
public abstract class ImageIconsMixin {
18+
@Shadow
19+
private int textColor;
20+
@Shadow
21+
private float alpha;
22+
@Shadow
23+
protected float posX;
24+
@Shadow
25+
protected float posY;
26+
27+
@Unique
28+
private String hysentials$text = null;
29+
@Unique Boolean hysentials$shadow = null;
30+
31+
@Unique
32+
List<Character> hysentials$renderedChars = null;
33+
34+
@Shadow
35+
protected abstract float renderChar(char ch, boolean italic);
36+
37+
@Shadow
38+
protected abstract void doDraw(float f);
39+
40+
@ModifyArg(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Ljava/lang/String;charAt(I)C"))
41+
private int renderStringAtPosReplace(int index) {
42+
try {
43+
char c0 = hysentials$text.charAt(index);
44+
for (ImageIcon icon : ImageIcon.imageIcons.values()) {
45+
if (icon.replacement == null || icon.replacement.isEmpty()) continue;
46+
if (icon.replacement.charAt(0) == c0) {
47+
System.out.println("Found replacement for " + c0);
48+
hysentials$renderedChars = new ArrayList<>();
49+
hysentials$renderedChars.add(c0);
50+
break;
51+
}
52+
if (hysentials$renderedChars != null && icon.replacement.charAt(hysentials$renderedChars.size()) == c0) {
53+
hysentials$renderedChars.add(c0);
54+
if (hysentials$renderedChars.size() == icon.replacement.length()) {
55+
hysentials$renderedChars = null;
56+
float f = icon.renderImage(posX, posY, hysentials$shadow, textColor, alpha);
57+
doDraw(f);
58+
break;
59+
}
60+
} else {
61+
hysentials$renderedChars = null;
62+
hysentials$renderChars();
63+
}
64+
}
65+
} catch (Exception ignored) {}
66+
return index;
67+
}
68+
69+
@Inject(method = "renderChar", at = @At("HEAD"), cancellable = true)
70+
private void renderCharReplace(char ch, boolean italic, CallbackInfoReturnable<Float> cir) {
71+
if (hysentials$renderedChars != null) {
72+
cir.cancel();
73+
}
74+
}
75+
76+
@Unique
77+
private void hysentials$renderChars() {
78+
if (hysentials$renderedChars == null) return;
79+
for (char c : hysentials$renderedChars) {
80+
float f = this.renderChar(c, false);
81+
doDraw(f);
82+
}
83+
}
84+
85+
86+
//Is there a better way to do these two?
87+
@ModifyVariable(method = "renderStringAtPos", at = @At("HEAD"), argsOnly = true)
88+
private String renderStringAtPosReplace(String text) {
89+
hysentials$text = FancyFormattingKt.replaceString(text);
90+
return FancyFormattingKt.replaceString(text);
91+
}
92+
// Is there a better way to do these two?
93+
@ModifyVariable(method = "renderStringAtPos", at = @At("HEAD"), argsOnly = true, index = 2)
94+
private boolean renderStringAtPosReplace2(boolean value) {
95+
hysentials$shadow = value;
96+
return value;
97+
}
98+
99+
@Inject(method = "renderStringAtPos", at = @At("RETURN"))
100+
private void renderStringAtPosReplaceReturn(String text, boolean shadow, CallbackInfo ci) {
101+
hysentials$text = null;
102+
hysentials$shadow = null;
103+
}
104+
105+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package llc.redstone.hysentials.mixin.fancyformatting;
2+
3+
import llc.redstone.hysentials.renderer.text.FancyFormattingKt;
4+
import net.minecraft.client.gui.FontRenderer;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
8+
9+
@Mixin(value = FontRenderer.class, priority = 1005)
10+
public class ReplacementMixin {
11+
@ModifyVariable(method = "getStringWidth", at = @At("HEAD"), argsOnly = true)
12+
private String getStringWidthReplace(String text) {
13+
return FancyFormattingKt.replaceString(text);
14+
}
15+
}

0 commit comments

Comments
 (0)