Skip to content

Commit cf8a569

Browse files
committed
1.5.6
1 parent 7062442 commit cf8a569

11 files changed

Lines changed: 319 additions & 22 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ buildscript {
1717
}
1818
}
1919
dependencies {
20-
classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT"
20+
classpath "com.anatawa12.forge:ForgeGradle:2.3-1.0.+"
2121
}
2222
}
2323

src/main/java/alexiil/mc/mod/load/ClsManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ public static boolean renderTransitionFrame() {
191191
return true;
192192
}
193193

194+
public static void finish() {
195+
instance.close();
196+
}
197+
194198
public static class Resolution {
195199
private double width, height;
196200
private double scale = 1;

src/main/java/alexiil/mc/mod/load/CustomLoadingScreen.java

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package alexiil.mc.mod.load;
22

3+
import java.io.BufferedOutputStream;
4+
import java.io.BufferedWriter;
35
import java.io.File;
6+
import java.io.FileOutputStream;
7+
import java.io.IOException;
8+
import java.io.OutputStream;
9+
import java.io.OutputStreamWriter;
410
import java.util.Random;
511

612
import net.minecraftforge.common.MinecraftForge;
@@ -56,6 +62,7 @@ public class CustomLoadingScreen {
5662
"Sets the config to use for the custom loading screen. Use 'builtin/random' for a random loading screen on each load."
5763
+ "\nAlternatively you can prefix this with 'config/' to load from the 'config/customloadingscreen/' directory."
5864
+ "\nOr you can use 'sample/slideshow' to display images from config/customloadingscreen/slideshow_#.png."
65+
+ "\nOr you can set this to 'config/example' to use the default example config."
5966
);
6067

6168
String[] defaultRandoms = { "sample/default", "sample/white", "sample/scrolling", "sample_panorama_lower" };
@@ -106,6 +113,29 @@ public class CustomLoadingScreen {
106113
if (CONFIG.hasChanged()) {
107114
CONFIG.save();
108115
}
116+
117+
File clsRoot = new File("./config/customloadingscreen/");
118+
119+
if (!clsRoot.exists()) {
120+
clsRoot.mkdir();
121+
}
122+
123+
File clsExample = new File(clsRoot, "example.json");
124+
125+
if (!clsExample.exists()) {
126+
127+
try (OutputStream out = new FileOutputStream(clsExample)) {
128+
BufferedOutputStream bos = new BufferedOutputStream(out);
129+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(bos));
130+
131+
writeExampleCfg(bw);
132+
133+
bw.flush();
134+
135+
} catch (IOException e) {
136+
CLSLog.warn("Failed to write the example config file!", e);
137+
}
138+
}
109139
}
110140

111141
public static void finish() {
@@ -131,4 +161,139 @@ public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event
131161
CONFIG.save();
132162
}
133163
}
164+
165+
private static void ln(BufferedWriter bw, String str) throws IOException {
166+
bw.write(str.replace('#', '"'));
167+
bw.newLine();
168+
}
169+
170+
private static void writeExampleCfg(BufferedWriter bw) throws IOException {
171+
// Exploded copy of "sample/config/default.json"
172+
ln(bw, "{");
173+
ln(bw, " #renders#: [");
174+
ln(bw, " {");
175+
ln(bw, " #image#: {");
176+
ln(bw, " #parent#: #builtin/panorama#,");
177+
ln(bw, " #image#: #textures/gui/title/background/panorama_x.png#");
178+
ln(bw, " }");
179+
ln(bw, " },");
180+
ln(bw, " {");
181+
ln(bw, " #image#: {");
182+
ln(bw, " #parent#: #builtin/image#,");
183+
ln(bw, " #image#: #customloadingscreen:textures/generic/darkened_blur_horizontal_strip.png#,");
184+
ln(bw, " #position_type#: #CENTER#,");
185+
ln(bw, " #offset_pos#: #CENTER#,");
186+
ln(bw, " #position#: {");
187+
ln(bw, " #x#: #0#,");
188+
ln(bw, " #y#: #0#,");
189+
ln(bw, " #width#: #screen_width#,");
190+
ln(bw, " #height#: #100#");
191+
ln(bw, " },");
192+
ln(bw, " #texture#: {");
193+
ln(bw, " #x#: #0#,");
194+
ln(bw, " #y#: #0#,");
195+
ln(bw, " #width#: #1#,");
196+
ln(bw, " #height#: #1#");
197+
ln(bw, " }");
198+
ln(bw, " }");
199+
ln(bw, " },");
200+
ln(bw, " {");
201+
ln(bw, " #image#: {");
202+
ln(bw, " #parent#:#builtin/image#,");
203+
ln(bw, " #image#: #customloadingscreen:textures/progress_bars.png#,");
204+
ln(bw, " #position_type#: #CENTER#,");
205+
ln(bw, " #offset_pos#: #CENTER#,");
206+
ln(bw, " #position#:{");
207+
ln(bw, " #x#: #0#,");
208+
ln(bw, " #y#:#20#,");
209+
ln(bw, " #width#:#182 * 2#,");
210+
ln(bw, " #height#:#20#");
211+
ln(bw, " },");
212+
ln(bw, " #texture#:{");
213+
ln(bw, " #x#: #0#,");
214+
ln(bw, " #y#: #70 / 256.0#,");
215+
ln(bw, " #width#: #182 / 256.0#,");
216+
ln(bw, " #height#: #10 / 256.0#");
217+
ln(bw, " }");
218+
ln(bw, " }");
219+
ln(bw, " },");
220+
ln(bw, " {");
221+
ln(bw, " #image#: {");
222+
ln(bw, " #parent#: #builtin/image#,");
223+
ln(bw, " #image#: #customloadingscreen:textures/progress_bars.png#,");
224+
ln(bw, " #position_type#: #CENTER#,");
225+
ln(bw, " #offset_pos#: #CENTER#,");
226+
ln(bw, " #position#:{");
227+
ln(bw, " #x#:#percentage * 182 - 182#,");
228+
ln(bw, " #y#:#20#,");
229+
ln(bw, " #width#:#percentage * 182 * 2#,");
230+
ln(bw, " #height#:#20#");
231+
ln(bw, " },");
232+
ln(bw, " #texture#:{");
233+
ln(bw, " #x#:#0#,");
234+
ln(bw, " #y#:#80 / 256.0#,");
235+
ln(bw, " #width#: #percentage * 182 / 256.0#,");
236+
ln(bw, " #height#:#10 / 256.0#");
237+
ln(bw, " }");
238+
ln(bw, " }");
239+
ln(bw, " },");
240+
ln(bw, " {");
241+
ln(bw, " #image#: {");
242+
ln(bw, " #parent#: #builtin/text#,");
243+
ln(bw, " #image#: #textures/font/ascii.png#,");
244+
ln(bw, " #position_type#: #CENTER#,");
245+
ln(bw, " #offset_pos#: #CENTER#,");
246+
ln(bw, " #text#: #is_reloading ? status : (status + ': ' + sub_status)#,");
247+
ln(bw, " #position#: {");
248+
ln(bw, " #x#: #0#,");
249+
ln(bw, " #y#: #-20#,");
250+
ln(bw, " #width#: #0#,");
251+
ln(bw, " #height#: #0#");
252+
ln(bw, " },");
253+
ln(bw, " #colour#:#0xFF_FF_FF_FF#");
254+
ln(bw, " }");
255+
ln(bw, " },");
256+
ln(bw, " {");
257+
ln(bw, " #image#: {");
258+
ln(bw, " #parent#: #builtin/text#,");
259+
ln(bw, " #image#: #textures/font/ascii.png#,");
260+
ln(bw, " #position_type#: #CENTER#,");
261+
ln(bw, " #offset_pos#: #CENTER#,");
262+
ln(bw, " #text#: #is_reloading ? sub_status : ''#,");
263+
ln(bw, " #position#: {");
264+
ln(bw, " #x#: #0#,");
265+
ln(bw, " #y#: #0#,");
266+
ln(bw, " #width#: #0#,");
267+
ln(bw, " #height#: #0#");
268+
ln(bw, " },");
269+
ln(bw, " #colour#:#0xFF_FF_FF_FF#");
270+
ln(bw, " }");
271+
ln(bw, " },");
272+
ln(bw, " {");
273+
ln(bw, " #image#: {");
274+
ln(bw, " #parent#: #builtin/text#,");
275+
ln(bw, " #image#: #textures/font/ascii.png#,");
276+
ln(bw, " #position_type#: #CENTER#,");
277+
ln(bw, " #offset_pos#: #CENTER#,");
278+
ln(bw, " #text#: #(floor(percentage * 100)) + '%'#,");
279+
ln(bw, " #position#: {");
280+
ln(bw, " #x#: #0#,");
281+
ln(bw, " #y#: #-10#,");
282+
ln(bw, " #width#: #0#,");
283+
ln(bw, " #height#: #0#");
284+
ln(bw, " },");
285+
ln(bw, " #colour#:#0xFF_FF_FF_FF#");
286+
ln(bw, " }");
287+
ln(bw, " }");
288+
ln(bw, " ],");
289+
ln(bw, " #functions#:[");
290+
ln(bw, " ],");
291+
ln(bw, " #factories#:[");
292+
ln(bw, " ],");
293+
ln(bw, " #actions#:[");
294+
ln(bw, " ],");
295+
ln(bw, " #variables#:{");
296+
ln(bw, " }");
297+
ln(bw, "}");
298+
}
134299
}

src/main/java/alexiil/mc/mod/load/json/Area.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
package alexiil.mc.mod.load.json;
22

3+
import java.lang.reflect.Type;
4+
5+
import com.google.gson.JsonDeserializationContext;
6+
import com.google.gson.JsonDeserializer;
7+
import com.google.gson.JsonElement;
8+
import com.google.gson.JsonObject;
9+
import com.google.gson.JsonParseException;
10+
11+
import net.minecraft.util.JsonUtils;
12+
313
import alexiil.mc.mod.load.baked.render.BakedArea;
414

515
import buildcraft.lib.expression.FunctionContext;
616
import buildcraft.lib.expression.api.InvalidExpressionException;
717

818
public class Area {
19+
public static final JsonDeserializer<Area> DESERIALISER = Area::deserialise;
20+
921
public final String x, y, width, height;
1022

1123
public Area(double x, double y, double width, double height) {
@@ -28,6 +40,29 @@ public String toString() {
2840
}
2941

3042
public BakedArea bake(FunctionContext context) throws InvalidExpressionException {
43+
if (width == null) {
44+
throw new InvalidExpressionException("Missing 'width'!");
45+
}
46+
if (height == null) {
47+
throw new InvalidExpressionException("Missing 'height'!");
48+
}
3149
return new BakedArea(x == null ? "0" : x, y == null ? "0" : y, width, height, context);
3250
}
51+
52+
private static Area deserialise(JsonElement json, Type typeOfT, JsonDeserializationContext context)
53+
throws JsonParseException {
54+
55+
if (!json.isJsonObject()) {
56+
throw new JsonParseException("Expected an object, but got " + json);
57+
}
58+
59+
JsonObject obj = json.getAsJsonObject();
60+
61+
String x = JsonUtils.getString(obj, "x", null);
62+
String y = JsonUtils.getString(obj, "y", null);
63+
String width = JsonUtils.getString(obj, "width", null);
64+
String height = JsonUtils.getString(obj, "height", null);
65+
66+
return new Area(x, y, width, height);
67+
}
3368
}

src/main/java/alexiil/mc/mod/load/json/ConfigManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public boolean hasDefault() {
9191
.registerTypeAdapter(JsonVariable[].class, VariableArrayDeserialiser.VARIABLES)//
9292
.registerTypeAdapter(JsonConstant[].class, VariableArrayDeserialiser.CONSTANTS)//
9393
.registerTypeAdapter(JsonFactory.class, FactoryDeserialiser.INSTANCE)//
94+
.registerTypeAdapter(Area.class, Area.DESERIALISER)//
9495
// .registerTypeAdapter(JsonAction.class, ActionDeserialiser.INSTANCE)//
9596
.create();
9697
GSON_DEFAULT = new GsonBuilder().setPrettyPrinting().create();

src/main/java/alexiil/mc/mod/load/json/JsonConfigurable.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.gson.JsonDeserializationContext;
99
import com.google.gson.JsonElement;
1010
import com.google.gson.JsonObject;
11+
import com.google.gson.JsonParseException;
1112

1213
import net.minecraft.util.ResourceLocation;
1314

@@ -154,12 +155,17 @@ protected static <O> O[] consolidateArray(O[] first, O[] last) {
154155
return array;
155156
}
156157

157-
protected static Area consolidateArea(JsonObject obj, String memeber, JsonDeserializationContext ctx, Area parent) {
158+
protected static Area consolidateArea(JsonObject obj, String member, JsonDeserializationContext ctx, Area parent) {
158159
Area in;
159-
if (obj.has(memeber)) {
160-
in = ctx.deserialize(obj.get(memeber), Area.class);
161-
if (in == null) {
162-
return parent;
160+
if (obj.has(member)) {
161+
JsonElement memberJson = obj.get(member);
162+
try {
163+
in = ctx.deserialize(memberJson, Area.class);
164+
if (in == null) {
165+
return parent;
166+
}
167+
} catch (JsonParseException e) {
168+
throw new JsonParseException("Failed to read '" + member + " json as an area\n" + memberJson, e);
163169
}
164170
} else {
165171
return parent;

src/main/java/alexiil/mc/mod/load/render/ClsTexture.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import java.io.FileNotFoundException;
55
import java.io.IOException;
66
import java.io.InputStream;
7+
import java.nio.IntBuffer;
78

9+
import org.lwjgl.BufferUtils;
810
import org.lwjgl.opengl.GL11;
11+
import org.lwjgl.opengl.GL12;
12+
import org.lwjgl.opengl.GL14;
913
import org.lwjgl.opengl.GLContext;
1014
import org.lwjgl.opengl.KHRDebug;
1115

@@ -14,8 +18,6 @@
1418
import net.minecraft.client.resources.IResourceManager;
1519
import net.minecraft.util.ResourceLocation;
1620

17-
import net.minecraftforge.fml.client.SplashProgress;
18-
1921
public class ClsTexture extends SimpleTexture {
2022

2123
private BufferedImage image;
@@ -32,7 +34,6 @@ public ResourceLocation location() {
3234

3335
@Override
3436
public int getGlTextureId() {
35-
3637
if (glTextureId == -1) {
3738
glTextureId = GL11.glGenTextures();
3839
}
@@ -82,12 +83,39 @@ public void loadTexture(IResourceManager resourceManager) throws IOException {
8283
loadImage(resourceManager);
8384
}
8485

85-
synchronized (SplashProgress.class) {
86-
TextureUtil.uploadTextureImageAllocate(getGlTextureId(), image, blur, clamp);
86+
int id = getGlTextureId();
87+
GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
88+
89+
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0);
90+
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, 0);
91+
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, 0);
92+
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0.0F);
93+
94+
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, blur ? GL11.GL_LINEAR : GL11.GL_NEAREST);
95+
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, blur ? GL11.GL_LINEAR : GL11.GL_NEAREST);
96+
97+
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, clamp ? GL11.GL_CLAMP : GL11.GL_REPEAT);
98+
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, clamp ? GL11.GL_CLAMP : GL11.GL_REPEAT);
99+
100+
int width = image.getWidth();
101+
int height = image.getHeight();
102+
IntBuffer buffer = BufferUtils.createIntBuffer(width * height);
103+
104+
for (int y = 0; y < height; y++) {
105+
for (int x = 0; x < width; x++) {
106+
buffer.put(image.getRGB(x, y));
107+
}
87108
}
88109

110+
buffer.flip();
111+
112+
GL11.glTexImage2D(
113+
GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV,
114+
buffer
115+
);
116+
89117
if (GLContext.getCapabilities().GL_KHR_debug) {
90-
KHRDebug.glObjectLabel(GL11.GL_TEXTURE, getGlTextureId(), "CLS_custom_tex_'" + location() + "'");
118+
KHRDebug.glObjectLabel(GL11.GL_TEXTURE, id, "CLS_custom_tex_'" + location() + "'");
91119
}
92120
}
93121
}

src/main/java/alexiil/mc/mod/load/render/MainSplashRenderer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ public static void run() {
267267
}
268268
}
269269
LongTermProgressTracker.save(SingleProgressBarTracker.getProgressSections());
270+
if (enableCustom) {
271+
ClsManager.finish();
272+
}
270273
clearGL();
271274
invokeSplashAnimationFinish();
272275
}

0 commit comments

Comments
 (0)