diff options
Diffstat (limited to 'src')
79 files changed, 1600 insertions, 1030 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java index b6f11790..91ae3740 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java +++ b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java @@ -84,6 +84,7 @@ public class SkyblockerMod implements ClientModInitializer { DungeonMap.init(); TheRift.init(); TitleContainer.init(); + ScreenMaster.init(); containerSolverManager.init(); scheduler.scheduleCyclic(Utils::update, 20); scheduler.scheduleCyclic(DiscordRPCManager::updateDataAndPresence, 100); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/ScreenBuilder.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/ScreenBuilder.java index 1197ca2d..4c317a57 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/ScreenBuilder.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/ScreenBuilder.java @@ -5,9 +5,10 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -20,6 +21,7 @@ import me.xmrvizzy.skyblocker.skyblock.tabhud.screenbuilder.pipeline.CollideStag import me.xmrvizzy.skyblocker.skyblock.tabhud.screenbuilder.pipeline.PipelineStage; import me.xmrvizzy.skyblocker.skyblock.tabhud.screenbuilder.pipeline.PlaceStage; import me.xmrvizzy.skyblocker.skyblock.tabhud.screenbuilder.pipeline.StackStage; +import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.DungeonPlayerWidget; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.EmptyWidget; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.EventWidget; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.Widget; @@ -29,6 +31,9 @@ import net.minecraft.util.Identifier; public class ScreenBuilder { + // TODO: Let EmptyWidget contain an error message + + private static final Logger LOGGER = LoggerFactory.getLogger("skyblocker"); // layout pipeline private ArrayList<PipelineStage> layoutPipeline = new ArrayList<>(); @@ -37,12 +42,15 @@ public class ScreenBuilder { // maps alias -> widget instance private HashMap<String, Widget> objectMap = new HashMap<>(); + private String builderName; + /** * Create a ScreenBuilder from a json. */ - public ScreenBuilder(String jsonfile) throws IOException { + public ScreenBuilder(Identifier ident) throws IOException { + + this.builderName = ident.getPath(); - Identifier ident = new Identifier(SkyblockerMod.NAMESPACE, "tabhud/" + jsonfile + ".json"); BufferedReader reader = MinecraftClient.getInstance().getResourceManager().openAsReader(ident); JsonObject json = JsonParser.parseReader(reader).getAsJsonObject(); reader.close(); @@ -61,7 +69,10 @@ public class ScreenBuilder { } for (JsonElement l : layout) { - layoutPipeline.add(createStage(l.getAsJsonObject())); + PipelineStage ps = createStage(l.getAsJsonObject()); + if (ps != null) { + layoutPipeline.add(ps); + } } } @@ -76,8 +87,11 @@ public class ScreenBuilder { switch (name) { case "EventWidget": return new EventWidget(widget.get("inGarden").getAsBoolean()); + case "DungeonPlayerWidget": + return new DungeonPlayerWidget(widget.get("player").getAsInt()); case "Widget": // clown case sanity check. don't instantiate the superclass >:| + LOGGER.error("Couldn't find class \"{}\"!", name); return new EmptyWidget(); } @@ -85,13 +99,14 @@ public class ScreenBuilder { // TODO don't get package list for every widget; do it once and cache. // fine for now, as this would only shorten the load time anyways - // find all packages that might contain widget classes - Package[] packs = Package.getPackages(); - - List<String> packnames = Arrays.stream(packs) - .map(pack -> pack.getName()) - .filter(s -> s.startsWith("me.xmrvizzy.skyblocker.skyblock.tabhud.widget")) - .toList(); + // list all packages that might contain widget classes + // using Package isn't reliable, as some classes might not be loaded yet, + // causing the packages not to show. + String packbase = "me.xmrvizzy.skyblocker.skyblock.tabhud.widget"; + String[] packnames = { + packbase, + packbase + ".rift" + }; // construct the full class name and try to load. Class<?> clazz = null; @@ -105,6 +120,7 @@ public class ScreenBuilder { // load failed. if (clazz == null) { + LOGGER.error("Couldn't find class \"{}\"!", name); return new EmptyWidget(); } @@ -114,6 +130,7 @@ public class ScreenBuilder { return (Widget) ctor.newInstance(); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException ex) { + LOGGER.error("Failed to create instance of class {}!", clazz.getSimpleName()); return new EmptyWidget(); } } @@ -134,14 +151,17 @@ public class ScreenBuilder { return new AlignStage(this, descr); case "collideAgainst": return new CollideStage(this, descr); + default: + LOGGER.error("No such op \"{}\" as requested by {}", op, this.builderName); + return null; } - return null; } /** * Lookup Widget instance from alias name */ public Widget getInstance(String name) { + // TODO: filter null here or in stage classes return this.objectMap.get(name); } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java index 97969503..997bd5a9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java @@ -1,51 +1,56 @@ package me.xmrvizzy.skyblocker.skyblock.tabhud.screenbuilder; -import java.io.BufferedReader; import java.io.IOException; import java.util.HashMap; -import java.util.Map.Entry; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import me.xmrvizzy.skyblocker.SkyblockerMod; -import net.minecraft.client.MinecraftClient; +import me.xmrvizzy.skyblocker.skyblock.tabhud.TabHud; +import me.xmrvizzy.skyblocker.skyblock.tabhud.util.PlayerLocator; +import net.fabricmc.fabric.api.resource.ResourceManagerHelper; +import net.fabricmc.fabric.api.resource.ResourcePackActivationType; +import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.gui.DrawContext; +import net.minecraft.resource.Resource; +import net.minecraft.resource.ResourceManager; +import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; public class ScreenMaster { - private static final Identifier ASSIGNMENT_JSON = new Identifier(SkyblockerMod.NAMESPACE, "tabhud/assignment.json"); private static final Logger LOGGER = LoggerFactory.getLogger("skyblocker"); private static HashMap<String, ScreenBuilder> standardMap = new HashMap<>(); - // private static HashMap<String, ScreenBuilder> screenAMap = new HashMap<>(); - // private static HashMap<String, ScreenBuilder> screenBMap = new HashMap<>(); - - static { - init(); - } + private static HashMap<String, ScreenBuilder> screenAMap = new HashMap<>(); + private static HashMap<String, ScreenBuilder> screenBMap = new HashMap<>(); /** - * Load the assignment json and construct the screen mapping + * Load a screen mapping from */ - public static void init() { - try (BufferedReader reader = MinecraftClient.getInstance().getResourceManager().openAsReader(ASSIGNMENT_JSON)) { - - JsonObject json = JsonParser.parseReader(reader).getAsJsonObject(); - JsonObject standard = json.getAsJsonObject("standard"); - for (Entry<String, JsonElement> entry : standard.entrySet()) { - standardMap.put(entry.getKey(), new ScreenBuilder(entry.getValue().getAsString())); + public static void load(Identifier ident) { + + String path = ident.getPath(); + String[] parts = path.split("/"); + String screenType = parts[parts.length - 2]; + String location = parts[parts.length - 1]; + location = location.replace(".json", ""); + + try { + + if (screenType.equals("standard")) { + standardMap.put(location, new ScreenBuilder(ident)); + } else if (screenType.equals("screenA")) { + screenAMap.put(location, new ScreenBuilder(ident)); + } else if (screenType.equals("screenB")) { + screenBMap.put(location, new ScreenBuilder(ident)); } - } catch (IOException ioex) { - LOGGER.info("[Skyblocker] Couldn't load tabhud config!"); - ioex.printStackTrace(); + LOGGER.error("Can't load screen definition from {}", path); } + } /** @@ -53,30 +58,60 @@ public class ScreenMaster { * Calls the appropriate ScreenBuilder with the screen's dimensions */ public static void render(DrawContext context, int w, int h) { - standardMap.get("default").run(context, w, h); + String location = PlayerLocator.getPlayerLocation().internal; + HashMap<String, ScreenBuilder> lookup; + if (TabHud.toggleA.isPressed()) { + lookup = screenAMap; + } else if (TabHud.toggleB.isPressed()) { + lookup = screenBMap; + } else { + lookup = standardMap; + } + + ScreenBuilder sb = lookup.get(location); + // seems suboptimal, maybe load the default first into all possible values + // and then override? + if (sb == null) { + sb = lookup.get("default"); + } + + sb.run(context, w, h); + } -} -/* - * - * stackWidgetsH -stackWidgetsW ---> stack (direction?) horiz/vert (align?) center/top/bottom/left/right - -centerH -centerW -center ---> center (center/horiz/vert) -----> place (one) (where?) center/top/bot/left/right/[corners] - -offCenterL -offCenterR ---> offCenter left/right/top/bot -----> offsetPlace (where?) center/left/right/top/bot (offset to where?) left/right/top/bot |
