Skip to content

Commit bb5a72e

Browse files
committed
Add LiteLoader support
1 parent e73a16a commit bb5a72e

7 files changed

Lines changed: 109 additions & 17 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/.classpath
66
/.settings/
77
/eclipse/
8-
/libs/
98
/serverTest/
109

1110

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mc_version=1.8
22
forge_version=11.14.1.1354
33

4-
mod_version=1.2.6
4+
mod_version=1.2.7
55
fallback_build_number=1
66
alexiil_lib_version=1.0.+

libs/liteloader-1.8.jar

593 KB
Binary file not shown.

libs/liteloader-core-1.8.jar

447 KB
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package alexiil.mods.load;
2+
3+
import com.mumfrey.liteloader.client.gui.startup.LoadingBar;
4+
5+
public class LiteLoaderProgress extends LoadingBar {
6+
private static final int NUM_STATES = ModLoadingListener.State.values().length;
7+
private static final int LITE_LOADER_INIT_ORDINAL = ModLoadingListener.State.LITE_LOADER_INIT.ordinal();
8+
private static final float LITE_LOADER_START_PERCENT = LITE_LOADER_INIT_ORDINAL / (float) NUM_STATES;
9+
10+
private String message = "";
11+
private int totalLiteProgress = 0;
12+
private int liteProgress = 0;
13+
14+
@Override
15+
protected void _dispose() {}
16+
17+
@Override
18+
protected void _incLiteLoaderProgress() {
19+
_incLiteLoaderProgress(message);
20+
}
21+
22+
@Override
23+
protected void _incLiteLoaderProgress(String arg0) {
24+
message = arg0;
25+
liteProgress++;
26+
render();
27+
}
28+
29+
@Override
30+
protected void _incTotalLiteLoaderProgress(int arg0) {
31+
totalLiteProgress += arg0;
32+
render();
33+
}
34+
35+
private void render() {
36+
float litePercent = liteProgress / (float) totalLiteProgress;
37+
litePercent /= (float) NUM_STATES;
38+
float percent = LITE_LOADER_START_PERCENT + litePercent;
39+
ProgressDisplayer.displayProgress("LiteLoader: " + message, percent);
40+
}
41+
42+
@Override
43+
protected void _setEnabled(boolean arg0) {}
44+
45+
@Override
46+
protected void _setMessage(String arg0) {
47+
message = arg0;
48+
}
49+
}

src/main/java/alexiil/mods/load/ModLoadingListener.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,43 @@
1515

1616
public class ModLoadingListener {
1717
public enum State {
18-
CONSTRUCT("Construction"), PRE_INIT("Pre Initialization"), INIT("Initialization"), POST_INIT("Post Initialization"), LOAD_COMPLETE(
19-
"Completed"), FINAL_LOADING("Reloading Resource Packs", true);
18+
CONSTRUCT("construction"), PRE_INIT("pre_initialization"), LITE_LOADER_INIT("lite", true, true), INIT("initialization"), POST_INIT(
19+
"post_initialization"), LOAD_COMPLETE("completed"), FINAL_LOADING("reloading_resource_packs", true, false);
2020

21-
final String displayName;
21+
private String translatedName = null;
22+
final String name;
2223
/** If this state is only called once. This is false for all except for FINAL_LOADING */
2324
final boolean isLoneState;
25+
/** If this is true, then ModStage.getNext will skip this, but it will still be included in the percentage
26+
* calculation */
27+
final boolean shouldSkip;
2428

25-
State(String name, boolean mods) {
26-
displayName = name;
29+
State(String name, boolean mods, boolean skip) {
2730
isLoneState = mods;
31+
this.name = name;
32+
shouldSkip = skip;
2833
}
2934

3035
State(String name) {
31-
this(name, false);
36+
this(name, false, false);
37+
}
38+
39+
public String translate() {
40+
if (translatedName != null)
41+
return translatedName;
42+
String failure = name.replaceAll("\\_", " ");
43+
String[] split = failure.split(" ");
44+
failure = "";
45+
for (int i = 0; i < split.length; i++) {
46+
failure += i == 0 ? "" : " ";
47+
failure += split[i].substring(0, 1).toUpperCase().concat(split[i].substring(1));
48+
}
49+
translatedName = Translation.translate("betterloadingscreen.state." + name, failure);
50+
return translatedName;
3251
}
3352
}
3453

35-
public static class ModStage {
54+
private static class ModStage {
3655
public final State state;
3756

3857
@Override
@@ -56,21 +75,24 @@ public ModStage getNext() {
5675
if (ord == State.values().length)
5776
return null;
5877
s = State.values()[ord];
78+
if (s.shouldSkip)
79+
return new ModStage(s, ind).getNext();
5980
}
6081
return new ModStage(s, ind);
6182
}
6283

6384
public String getDisplayText() {
6485
if (state.isLoneState)
65-
return state.displayName;
66-
return state.displayName + ": loading " + listeners.get(index).mod.getName();
86+
return state.translate();
87+
return state.translate() + ": " + Translation.translate("betterloadingscreen.loading", "loading") + " "
88+
+ listeners.get(index).mod.getName();
6789
}
6890

69-
public double getProgress() {
70-
double values = 100 / (float) State.values().length;
71-
double part = state.ordinal() * values;
72-
double size = listeners.size();
73-
double percent = values * index / size;
91+
public float getProgress() {
92+
float values = 100 / (float) State.values().length;
93+
float part = state.ordinal() * values;
94+
float size = listeners.size();
95+
float percent = values * index / size;
7496
return part + percent;
7597
}
7698
}

src/main/java/alexiil/mods/load/coremod/BetterLoadingScreenTransformer.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,39 @@
1212
import org.objectweb.asm.tree.InsnNode;
1313
import org.objectweb.asm.tree.MethodInsnNode;
1414
import org.objectweb.asm.tree.MethodNode;
15+
import org.objectweb.asm.tree.TypeInsnNode;
1516

1617
import alexiil.mods.load.ProgressDisplayer;
1718

18-
public class BetterLoadingScreenTransformer implements IClassTransformer {
19+
public class BetterLoadingScreenTransformer implements IClassTransformer, Opcodes {
1920
@Override
2021
public byte[] transform(String name, String transformedName, byte[] basicClass) {
2122
if (transformedName.equals("net.minecraft.client.Minecraft"))
2223
return transformMinecraft(basicClass, transformedName == name);
24+
if (name.equals("com.mumfrey.liteloader.client.api.ObjectFactoryClient"))
25+
return transformObjectFactoryClient(basicClass);
2326
return basicClass;
2427
}
2528

29+
private byte[] transformObjectFactoryClient(byte[] before) {
30+
ClassNode classNode = new ClassNode();
31+
ClassReader reader = new ClassReader(before);
32+
reader.accept(classNode, 0);
33+
34+
for (MethodNode m : classNode.methods) {
35+
if (m.name.equals("preBeginGame")) {
36+
m.instructions.clear();
37+
m.instructions.add(new TypeInsnNode(NEW, "alexiil/mods/load/LiteLoaderProgress"));
38+
m.instructions.add(new MethodInsnNode(INVOKESPECIAL, "alexiil/mods/load/LiteLoaderProgress", "<init>", "()V", false));
39+
m.instructions.add(new InsnNode(RETURN));
40+
}
41+
}
42+
43+
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
44+
classNode.accept(cw);
45+
return cw.toByteArray();
46+
}
47+
2648
private byte[] transformMinecraft(byte[] before, boolean dev) {
2749
boolean hasFoundStartGame = false;
2850
ClassNode classNode = new ClassNode();

0 commit comments

Comments
 (0)