diff options
| author | Jakub <jakvb.kolodziej@gmail.com> | 2023-06-25 13:16:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-25 13:16:59 +0200 |
| commit | 5bd5e7d4881f34c1da9dcbde899f655de3777b96 (patch) | |
| tree | fcaf7de10025bbf5a33b5798b71d50c4f122a638 /src/main/java/me/xmrvizzy/skyblocker/skyblock | |
| parent | f3f000a7e5a015aa7690502c8c3b74ce558decf6 (diff) | |
| parent | dc312c8db05bc9e9cd3f4fd8c039274270a4661b (diff) | |
| download | Skyblocker-5bd5e7d4881f34c1da9dcbde899f655de3777b96.tar.gz Skyblocker-5bd5e7d4881f34c1da9dcbde899f655de3777b96.tar.bz2 Skyblocker-5bd5e7d4881f34c1da9dcbde899f655de3777b96.zip | |
Merge branch 'master' into autorejoin2
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
47 files changed, 1235 insertions, 403 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java index 4820bc0f..d89a18e0 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java @@ -7,7 +7,7 @@ import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.network.PlayerListEntry; @@ -27,7 +27,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class BackpackPreview extends DrawableHelper { +public class BackpackPreview { private static final Identifier TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/inventory_background.png"); private static final BackpackPreview instance = new BackpackPreview(); private static final Pattern PROFILE_PATTERN = Pattern.compile("Profile: ([a-zA-Z]+)"); @@ -50,7 +50,7 @@ public class BackpackPreview extends DrawableHelper { } public static void tick() { - Utils.sbChecker(); // force update isOnSkyblock to prevent crash on disconnect + Utils.update(); // force update isOnSkyblock to prevent crash on disconnect if (Utils.isOnSkyblock()) { // save all dirty storages saveStorage(); @@ -135,7 +135,7 @@ public class BackpackPreview extends DrawableHelper { } } - public static boolean renderPreview(MatrixStack matrices, int index, int mouseX, int mouseY) { + public static boolean renderPreview(DrawContext context, int index, int mouseX, int mouseY) { if (index >= 9 && index < 18) index -= 9; else if (index >= 27 && index < 45) index -= 18; else return false; @@ -149,12 +149,13 @@ public class BackpackPreview extends DrawableHelper { RenderSystem.disableDepthTest(); RenderSystem.setShaderTexture(0, TEXTURE); - BackpackPreview.drawTexture(matrices, x, y, 0, 0, 176, 7); + context.drawTexture(TEXTURE, x, y, 0, 0, 176, 7); for (int i = 0; i < rows; ++i) - BackpackPreview.drawTexture(matrices, x, y + i * 18 + 7, 0, 7, 176, 18); - BackpackPreview.drawTexture(matrices, x, y + rows * 18 + 7, 0, 25, 176, 7); + context.drawTexture(TEXTURE, x, y + i * 18 + 7, 0, 7, 176, 18); + context.drawTexture(TEXTURE, x, y + rows * 18 + 7, 0, 25, 176, 7); RenderSystem.enableDepthTest(); + MatrixStack matrices = context.getMatrices(); ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer(); TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; for (int i = 9; i < storage[index].size(); ++i) { @@ -162,8 +163,8 @@ public class BackpackPreview extends DrawableHelper { int itemY = y + (i - 9) / 9 * 18 + 8; matrices.push(); matrices.translate(0, 0, 200); - itemRenderer.renderInGui(matrices, storage[index].getStack(i), itemX, itemY); - itemRenderer.renderGuiItemOverlay(matrices, textRenderer, storage[index].getStack(i), itemX, itemY); + context.drawItem(storage[index].getStack(i), itemX, itemY); + context.drawItemInSlot(textRenderer, storage[index].getStack(i), itemX, itemY); matrices.pop(); } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java new file mode 100644 index 00000000..ccffdcca --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java @@ -0,0 +1,175 @@ +package me.xmrvizzy.skyblocker.skyblock; + +import com.google.common.collect.ImmutableSet; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import me.xmrvizzy.skyblocker.SkyblockerMod; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.NEURepo; +import me.xmrvizzy.skyblocker.utils.RenderHelper; +import me.xmrvizzy.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; +import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.text.Text; +import net.minecraft.util.DyeColor; +import net.minecraft.util.math.BlockPos; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.util.*; +import java.util.concurrent.CompletableFuture; + +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; + +public class FairySouls { + private static final Logger LOGGER = LoggerFactory.getLogger(FairySouls.class); + private static CompletableFuture<Void> fairySoulsLoaded; + private static final Map<String, Set<BlockPos>> fairySouls = new HashMap<>(); + private static final Map<String, Map<String, Set<BlockPos>>> foundFairies = new HashMap<>(); + + public static void init() { + fairySoulsLoaded = NEURepo.runAsyncAfterLoad(() -> { + try { + BufferedReader reader = new BufferedReader(new FileReader(NEURepo.LOCAL_REPO_DIR.resolve("constants").resolve("fairy_souls.json").toFile())); + for (Map.Entry<String, JsonElement> fairySoulJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { + if (fairySoulJson.getKey().equals("//") || fairySoulJson.getKey().equals("Max Souls")) { + continue; + } + ImmutableSet.Builder<BlockPos> fairySoulsForLocation = ImmutableSet.builder(); + for (JsonElement fairySoul : fairySoulJson.getValue().getAsJsonArray().asList()) { + fairySoulsForLocation.add(parseBlockPos(fairySoul)); + } + fairySouls.put(fairySoulJson.getKey(), fairySoulsForLocation.build()); + } + reader = new BufferedReader(new FileReader(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile())); + for (Map.Entry<String, JsonElement> foundFairiesForProfileJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { + Map<String, Set<BlockPos>> foundFairiesForProfile = new HashMap<>(); + for (Map.Entry<String, JsonElement> foundFairiesForLocationJson : foundFairiesForProfileJson.getValue().getAsJsonObject().asMap().entrySet()) { + Set<BlockPos> foundFairiesForLocation = new HashSet<>(); + for (JsonElement foundFairy : foundFairiesForLocationJson.getValue().getAsJsonArray().asList()) { + foundFairiesForLocation.add(parseBlockPos(foundFairy)); + } + foundFairiesForProfile.put(foundFairiesForLocationJson.getKey(), foundFairiesForLocation); + } + foundFairies.put(foundFairiesForProfileJson.getKey(), foundFairiesForProfile); + } + reader.close(); + } catch (IOException e) { + LOGGER.error("Failed to load found fairy souls", e); + } catch (Exception e) { + LOGGER.error("Encountered unknown exception loading fairy souls", e); + } + }); + ClientLifecycleEvents.CLIENT_STOPPING.register(FairySouls::saveFoundFairySouls); + WorldRenderEvents.AFTER_TRANSLUCENT.register(FairySouls::render); + ClientReceiveMessageEvents.GAME.register(FairySouls::onChatMessage); + ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE) + .then(literal("fairySouls") + .then(literal("markAllInCurrentIslandFound").executes(context -> { + FairySouls.markAllFairiesFound(); + context.getSource().sendFeedback(Text.translatable("skyblocker.fairySouls.markAllFound")); + return 1; + })) + .then(literal("markAllInCurrentIslandMissing").executes(context -> { + FairySouls.markAllFairiesNotFound(); + context.getSource().sendFeedback(Text.translatable("skyblocker.fairySouls.markAllMissing")); + return 1; + }))))); + } + + private static BlockPos parseBlockPos(JsonElement posJson) { + String[] posArray = posJson.getAsString().split(","); + return new BlockPos(Integer.parseInt(posArray[0]), Integer.parseInt(posArray[1]), Integer.parseInt(posArray[2])); + } + + public static void saveFoundFairySouls(MinecraftClient client) { + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile())); + JsonObject foundFairiesJson = new JsonObject(); + for (Map.Entry<String, Map<String, Set<BlockPos>>> foundFairiesForProfile : foundFairies.entrySet()) { + JsonObject foundFairiesForProfileJson = new JsonObject(); + for (Map.Entry<String, Set<BlockPos>> foundFairiesForLocation : foundFairiesForProfile.getValue().entrySet()) { + JsonArray foundFairiesForLocationJson = new JsonArray(); + for (BlockPos foundFairy : foundFairiesForLocation.getValue()) { + foundFairiesForLocationJson.add(foundFairy.getX() + "," + foundFairy.getY() + "," + foundFairy.getZ()); + } + foundFairiesForProfileJson.add(foundFairiesForLocation.getKey(), foundFairiesForLocationJson); + } + foundFairiesJson.add(foundFairiesForProfile.getKey(), foundFairiesForProfileJson); + } + SkyblockerMod.GSON.toJson(foundFairiesJson, writer); + writer.close(); + } catch (IOException e) { + LOGGER.error("Failed to write found fairy souls to file."); + } + } + + public static void render(WorldRenderContext context) { + if (SkyblockerConfig.get().general.fairySouls.enableFairySoulsHelper && fairySoulsLoaded.isDone() && fairySouls.containsKey(Utils.getLocationRaw())) { + for (BlockPos fairySoul : fairySouls.get(Utils.getLocationRaw())) { + float[] colorComponents = isFairySoulNotFound(fairySoul) ? DyeColor.GREEN.getColorComponents() : DyeColor.RED.getColorComponents(); + RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, fairySoul, colorComponents, 0.5F); + } + } + } + + private static boolean isFairySoulNotFound(BlockPos fairySoul) { + Map<String, Set<BlockPos>> foundFairiesForProfile = foundFairies.get(Utils.getProfile()); + if (foundFairiesForProfile == null) { + return true; + } + Set<BlockPos> foundFairiesForProfileAndLocation = foundFairiesForProfile.get(Utils.getLocationRaw()); + if (foundFairiesForProfileAndLocation == null) { + return true; + } + return !foundFairiesForProfileAndLocation.contains(fairySoul); + } + + public static void onChatMessage(Text text, boolean overlay) { + String message = text.getString(); + if (message.equals("You have already found that Fairy Soul!") || message.equals("SOUL! You found a Fairy Soul!")) { + markClosestFairyFound(); + } + } + + private static void markClosestFairyFound() { + PlayerEntity player = MinecraftClient.getInstance().player; + if (player == null) { + LOGGER.warn("Failed to mark closest fairy soul as found because player is null."); + return; + } + fairySouls.get(Utils.getLocationRaw()).stream().filter(FairySouls::isFairySoulNotFound).min(Comparator.comparingDouble(fairySoul -> fairySoul.getSquaredDistance(player.getPos()))).ifPresent(fairySoul -> { + initializeFoundFairiesForCurrentProfileAndLocation(); + foundFairies.get(Utils.getProfile()).get(Utils.getLocationRaw()).add(fairySoul); + }); + } + + public static void markAllFairiesFound() { + initializeFoundFairiesForCurrentProfileAndLocation(); + foundFairies.get(Utils.getProfile()).get(Utils.getLocationRaw()).addAll(fairySouls.get(Utils.getLocationRaw())); + } + + public static void markAllFairiesNotFound() { + Map<String, Set<BlockPos>> foundFairiesForProfile = foundFairies.get(Utils.getProfile()); + if (foundFairiesForProfile != null) { + foundFairiesForProfile.remove(Utils.getLocationRaw()); + } + } + + private static void initializeFoundFairiesForCurrentProfileAndLocation() { + initializeFoundFairiesForProfileAndLocation(Utils.getProfile(), Utils.getLocationRaw()); + } + + private static void initializeFoundFairiesForProfileAndLocation(String profile, String location) { + foundFairies.computeIfAbsent(profile, profileKey -> new HashMap<>()); + foundFairies.get(profile).computeIfAbsent(location, locationKey -> new HashSet<>()); + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java index 05b57410..6af06e6d 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java @@ -1,15 +1,13 @@ package me.xmrvizzy.skyblocker.skyblock; -import com.mojang.blaze3d.systems.RenderSystem; import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import net.minecraft.util.Identifier; -public class FancyStatusBars extends DrawableHelper { +public class FancyStatusBars { private static final Identifier BARS = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/bars.png"); private final MinecraftClient client = MinecraftClient.getInstance(); @@ -39,7 +37,7 @@ public class FancyStatusBars extends DrawableHelper { return (100 * value) / max; } - public boolean render(MatrixStack matrices, int scaledWidth, int scaledHeight) { + public boolean render(DrawContext context, int scaledWidth, int scaledHeight) { var player = client.player; if (!SkyblockerConfig.get().general.bars.enableBars || player == null) return false; @@ -72,11 +70,10 @@ public class FancyStatusBars extends DrawableHelper { moveBar(i, configAnchorNum); } - RenderSystem.setShaderTexture(0, BARS); for (var bar : bars) - bar.draw(matrices); + bar.draw(context); for (var bar : bars) - bar.drawText(matrices); + bar.drawText(context); return true; } @@ -143,32 +140,32 @@ public class FancyStatusBars extends DrawableHelper { this.text = val; } - public void draw(MatrixStack matrices) { + public void draw(DrawContext context) { // Dont draw if anchorNum is outside of range if (anchorNum < 0 || anchorNum > 2) return; // Draw the icon for the bar - drawTexture(matrices, anchorsX[anchorNum] + offsetX, anchorsY[anchorNum], 0, v, 9, 9); + context.drawTexture(BARS, anchorsX[anchorNum] + offsetX, anchorsY[anchorNum], 0, v, 9, 9); // Draw the background for the bar - drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10, anchorsY[anchorNum], 10, v, 2, 9); + context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 10, anchorsY[anchorNum], 10, v, 2, 9); for (int i = 2; i < bar_width - 2; i += 58) - drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10 + i, anchorsY[anchorNum], 12, v, Math.min(58, bar_width - 2 - i), 9); - drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10 + bar_width - 2, anchorsY[anchorNum], 70, v, 2, 9); + context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 10 + i, anchorsY[anchorNum], 12, v, Math.min(58, bar_width - 2 - i), 9); + context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 10 + bar_width - 2, anchorsY[anchorNum], 70, v, 2, 9); // Draw the filled part of the bar for (int i = 0; i < fill.length; i++) { int fill_width = this.fill[i] * (bar_width - 2) / 100; if (fill_width >= 1) - drawTexture(matrices, anchorsX[anchorNum] + offsetX + 11, anchorsY[anchorNum], 72 + i*60, v, 1, 9); + context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 11, anchorsY[anchorNum], 72 + i*60, v, 1, 9); for (int j = 1; j < fill_width - 1; j += 58) - drawTexture(matrices, anchorsX[anchorNum] + offsetX + 11 + j, anchorsY[anchorNum], 73 + i*60, v, Math.min(58, fill_width - 1 - j), 9); + context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 11 + j, anchorsY[anchorNum], 73 + i*60, v, Math.min(58, fill_width - 1 - j), 9); if (fill_width == bar_width - 2) - drawTexture(matrices, anchorsX[anchorNum] + offsetX + 11 + fill_width - 1, anchorsY[anchorNum], 131 + i*60, v, 1, 9); + context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 11 + fill_width - 1, anchorsY[anchorNum], 131 + i*60, v, 1, 9); } } - public void drawText(MatrixStack matrices) { + public void drawText(DrawContext context) { // Dont draw if anchorNum is outside of range if (anchorNum < 0 || anchorNum > 2) return; @@ -179,10 +176,10 @@ public class FancyStatusBars extends DrawableHelper { final int[] offsets = new int[]{-1, 1}; for (int i : offsets) { - textRenderer.draw(matrices, text, (float) (x + i), (float) y, 0); - textRenderer.draw(matrices, text, (float) x, (float) (y + i), 0); + context.drawText(textRenderer, text, x + i, y, 0, false); + context.drawText(textRenderer, text, x, y + i, 0, false); } - textRenderer.draw(matrices, text, (float) x, (float) y, text_color); + context.drawText(textRenderer, text, x, y, text_color, false); } } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java index 790b27bf..d82464e1 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java @@ -8,8 +8,10 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.FishingRodItem; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; +import net.minecraft.sound.SoundEvent; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import net.minecraft.util.Identifier; import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -51,6 +53,7 @@ public class FishingHelper { if (Math.abs(normalYawVector.x * soundToFishHook.z - normalYawVector.z * soundToFishHook.x) < 0.2D && Math.abs(normalYawVector.dotProduct(soundToFishHook)) < 4D && player.getPos().squaredDistanceTo(packet.getX(), packet.getY(), packet.getZ()) > 1D) { client.inGameHud.setTitleTicks(0, 10, 5) |
