Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rendering stuff #4301

Merged
merged 4 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,7 @@ public WTextBox textBox(String text) {
public abstract <T> WDropdown<T> dropdown(T[] values, T value);
public <T extends Enum<?>> WDropdown<T> dropdown(T value) {
Class<?> klass = value.getClass();
T[] values = null;
try {
values = (T[]) klass.getDeclaredMethod("values").invoke(null);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}

T[] values = (T[]) klass.getEnumConstants();
return dropdown(values, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public static void refresh() {
}

public static void load(FontFace fontFace) {
if (RENDERER != null && RENDERER.fontFace.equals(fontFace)) return;
if (RENDERER != null) {
if (RENDERER.fontFace.equals(fontFace)) return;
else RENDERER.destroy();
}

try {
RENDERER = new CustomTextRenderer(fontFace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ private static ICapabilityTracker getTracker(String fieldName) {
capStateField.setAccessible(true);
return (ICapabilityTracker) capStateField.get(state);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
return null;
throw new IllegalStateException("Could not find GL state tracker '" + fieldName + "'", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void destroy() {
}

public void begin() {
if (building) throw new IllegalStateException("Mesh.end() called while already building.");
if (building) throw new IllegalStateException("Mesh.begin() called while already building.");

verticesPointer = verticesPointerStart;
vertexI = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ private String read(String path) {
try {
return IOUtils.toString(mc.getResourceManager().getResource(new MeteorIdentifier("shaders/" + path)).get().getInputStream(), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
return "";
throw new IllegalStateException("Could not read shader '" + path + "'", e);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.client.util.math.MatrixStack;
import org.lwjgl.BufferUtils;

import java.nio.Buffer;
import java.nio.ByteBuffer;

public class CustomTextRenderer implements TextRenderer {
Expand All @@ -33,11 +32,10 @@ public CustomTextRenderer(FontFace fontFace) {
this.fontFace = fontFace;

byte[] bytes = Utils.readBytes(fontFace.toStream());
ByteBuffer buffer = BufferUtils.createByteBuffer(bytes.length).put(bytes);
ByteBuffer buffer = BufferUtils.createByteBuffer(bytes.length).put(bytes).flip();

fonts = new Font[5];
for (int i = 0; i < fonts.length; i++) {
((Buffer) buffer).flip();
fonts[i] = new Font(buffer, (int) Math.round(18 * ((i * 0.5) + 1)));
}
}
Expand Down Expand Up @@ -132,4 +130,8 @@ public void end(MatrixStack matrices) {
building = false;
scale = 1;
}

public void destroy() {
mesh.destroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ public double render(Mesh mesh, String string, double x, double y, Color color,

return x;
}

private record CharData(float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float xAdvance) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@

import net.minecraft.nbt.NbtCompound;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class EnumSetting<T extends Enum<?>> extends Setting<T> {
private T[] values;
private final T[] values;

private final List<String> suggestions;

public EnumSetting(String name, String description, T defaultValue, Consumer<T> onChanged, Consumer<Setting<T>> onModuleActivated, IVisible visible) {
super(name, description, defaultValue, onChanged, onModuleActivated, visible);

try {
values = (T[]) defaultValue.getClass().getMethod("values").invoke(null);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}

values = (T[]) defaultValue.getClass().getEnumConstants();
suggestions = new ArrayList<>(values.length);
for (T value : values) suggestions.add(value.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static <T extends Annotation> void reflectInit(Method task, Class<T> ann
try {
task.invoke(null);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
throw new IllegalStateException("Error running @%s task '%s.%s'".formatted(annotation.getSimpleName(), task.getClass().getSimpleName(), task.getName()), e);
} catch (NullPointerException e) {
throw new RuntimeException("Method \"%s\" using Init annotations from non-static context".formatted(task.getName()), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void download() {
try {
String url = URLS.get(name);
if (url == null) {
synchronized (TO_RETRY) {
synchronized (TO_REMOVE) {
TO_REMOVE.add(this);
downloading = false;
return;
Expand Down