diff options
Diffstat (limited to 'src/main')
6 files changed, 48 insertions, 39 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java index 5aa97dd9..eeb6608f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java @@ -5,7 +5,6 @@ import java.util.Objects; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.dungeon.DungeonBoss; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; -import de.hysky.skyblocker.utils.Boxes; import de.hysky.skyblocker.utils.ColorUtils; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.RenderHelper; @@ -101,7 +100,7 @@ public class SimonSays { Box outline = RenderHelper.getBlockBoundingBox(world, state, buttonPos); float[] colour = buttonsRendered == 0 ? GREEN : YELLOW; - RenderHelper.renderFilled(context, Boxes.getMinVec(outline), Boxes.getLengthVec(outline), colour, 0.5f, true); + RenderHelper.renderFilled(context, outline, colour, 0.5f, true); RenderHelper.renderOutline(context, outline, colour, 5f, true); if (++buttonsRendered == 2) return; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java index 98d32c68..d703acb6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java @@ -8,6 +8,7 @@ import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; @@ -15,7 +16,6 @@ import net.minecraft.util.Formatting; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; -import net.minecraft.world.World; import java.util.List; import java.util.regex.Matcher; @@ -25,11 +25,12 @@ public class ThreeWeirdos extends DungeonPuzzle { protected static final Pattern PATTERN = Pattern.compile("^\\[NPC] ([A-Z][a-z]+): (?:The reward is(?: not in my chest!|n't in any of our chests\\.)|My chest (?:doesn't have the reward\\. We are all telling the truth\\.|has the reward and I'm telling the truth!)|At least one of them is lying, and the reward is not in [A-Z][a-z]+'s chest!|Both of them are telling the truth\\. Also, [A-Z][a-z]+ has the reward in their chest!)$"); private static final float[] GREEN_COLOR_COMPONENTS = new float[]{0, 1, 0}; private static BlockPos pos; + static Box boundingBox; private ThreeWeirdos() { super("three-weirdos", "three-chests"); ClientReceiveMessageEvents.GAME.register((message, overlay) -> { - World world = MinecraftClient.getInstance().world; + ClientWorld world = MinecraftClient.getInstance().world; if (overlay || !shouldSolve() || !SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveThreeWeirdos || world == null || !DungeonManager.isCurrentRoomMatched()) return; @SuppressWarnings("DataFlowIssue") @@ -54,7 +55,7 @@ public class ThreeWeirdos extends DungeonPuzzle { new ThreeWeirdos(); } - private void checkForNPC(World world, Room room, BlockPos relative, String name) { + private void checkForNPC(ClientWorld world, Room room, BlockPos relative, String name) { BlockPos npcPos = room.relativeToActual(relative); List<ArmorStandEntity> npcs = world.getEntitiesByClass( ArmorStandEntity.class, @@ -63,6 +64,7 @@ public class ThreeWeirdos extends DungeonPuzzle { ); if (!npcs.isEmpty()) { pos = room.relativeToActual(relative.add(1, 0, 0)); + boundingBox = RenderHelper.getBlockBoundingBox(world, pos); npcs.forEach(entity -> entity.setCustomName(Text.literal(name).formatted(Formatting.GREEN))); } } @@ -72,8 +74,8 @@ public class ThreeWeirdos extends DungeonPuzzle { @Override public void render(WorldRenderContext context) { - if (shouldSolve() && pos != null) { - RenderHelper.renderFilled(context, pos, GREEN_COLOR_COMPONENTS, 0.5f, true); + if (shouldSolve() && boundingBox != null) { + RenderHelper.renderFilled(context, boundingBox, GREEN_COLOR_COMPONENTS, 0.5f, false); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TicTacToe.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TicTacToe.java index 5a497c19..9e9d20f6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TicTacToe.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TicTacToe.java @@ -23,6 +23,7 @@ import java.util.List; public class TicTacToe extends DungeonPuzzle { private static final Logger LOGGER = LoggerFactory.getLogger(TicTacToe.class); private static final float[] RED_COLOR_COMPONENTS = { 1.0F, 0.0F, 0.0F }; + private static final float[] GREEN_COLOR_COMPONENTS = { 0.0F, 1.0F, 0.0F }; @SuppressWarnings("unused") private static final TicTacToe INSTANCE = new TicTacToe(); private static Box nextBestMoveToMake = null; @@ -101,7 +102,7 @@ public class TicTacToe extends DungeonPuzzle { double nextZ = 17 - bestMove.column(); BlockPos nextPos = DungeonManager.getCurrentRoom().relativeToActual(BlockPos.ofFloored(nextX, nextY, nextZ)); - nextBestMoveToMake = new Box(nextPos); + nextBestMoveToMake = RenderHelper.getBlockBoundingBox(client.world, nextPos); } } catch (Exception e) { LOGGER.error("[Skyblocker Tic Tac Toe] Encountered an exception while determining a tic tac toe solution!", e); @@ -112,7 +113,7 @@ public class TicTacToe extends DungeonPuzzle { public void render(WorldRenderContext context) { try { if (SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveTicTacToe && nextBestMoveToMake != null) { - RenderHelper.renderOutline(context, nextBestMoveToMake, RED_COLOR_COMPONENTS, 5, false); + RenderHelper.renderFilled(context, nextBestMoveToMake, GREEN_COLOR_COMPONENTS, 0.5f, false); } } catch (Exception e) { LOGGER.error("[Skyblocker Tic Tac Toe] Encountered an exception while rendering the tic tac toe solution!", e); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/boulder/Boulder.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/boulder/Boulder.java index aef9109f..2b61940b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/boulder/Boulder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/boulder/Boulder.java @@ -9,7 +9,6 @@ import de.hysky.skyblocker.utils.render.RenderHelper; import de.hysky.skyblocker.utils.render.title.Title; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.block.Block; -import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.client.world.ClientWorld; @@ -18,7 +17,6 @@ import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.BlockView; import java.util.Arrays; import java.util.List; @@ -106,7 +104,7 @@ public class Boulder extends DungeonPuzzle { button = checkForButtonBlocksOnLine(client.world, point1, point2); if (button != null) { // If a button is found, calculate its bounding box - boundingBox = getBlockBoundingBox(client.world, button); + boundingBox = RenderHelper.getBlockBoundingBox(client.world, button); break; } } @@ -179,18 +177,6 @@ public class Boulder extends DungeonPuzzle { return null; } - /** - * Retrieves the bounding box of a block in the world. - * - * @param world The client world. - * @param pos The position of the block. - * @return The bounding box of the block. - */ - public static Box getBlockBoundingBox(BlockView world, BlockPos pos) { - BlockState blockState = world.getBlockState(pos); - return blockState.getOutlineShape(world, pos).getBoundingBox().offset(pos); - } - @Override public void render(WorldRenderContext context) { if (!shouldSolve() || !SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveBoulder || !DungeonManager.isCurrentRoomMatched()) diff --git a/src/main/java/de/hysky/skyblocker/utils/Boxes.java b/src/main/java/de/hysky/skyblocker/utils/Boxes.java index cd944a46..c50d9bcf 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Boxes.java +++ b/src/main/java/de/hysky/skyblocker/utils/Boxes.java @@ -5,14 +5,22 @@ import net.minecraft.util.math.Direction.Axis; import net.minecraft.util.math.Vec3d; public class Boxes { - /** Returns the vector of the min pos of this box. **/ + /** + * Returns the vector of the min pos of this box. + * @deprecated Use {@link Box#getMinPos()} instead. + */ + @Deprecated(since = "1.22") public static Vec3d getMinVec(Box box) { - return new Vec3d(box.minX, box.minY, box.minZ); + return box.getMinPos(); } - /** Returns the vector of the max pos of this box. **/ + /** + * Returns the vector of the max pos of this box. + * @deprecated Use {@link Box#getMaxPos()} instead. + */ + @Deprecated(since = "1.22") public static Vec3d getMaxVec(Box box) { - return new Vec3d(box.maxX, box.maxY, box.maxZ); + return box.getMaxPos(); } /** Returns the vector of the side lengths of this box. **/ @@ -22,12 +30,12 @@ public class Boxes { /** Offsets this box so that minX, minY and minZ are all zero. **/ public static Box moveToZero(Box box) { - return box.offset(getMinVec(box).negate()); + return box.offset(box.getMinPos().negate()); } /** Returns the distance between to oppisite corners of the box. **/ public static double getCornerLength(Box box) { - return getMinVec(box).distanceTo(getMaxVec(box)); + return box.getMinPos().distanceTo(box.getMaxPos()); } /** Returns the length of an axis in the box. **/ diff --git a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java index 1b16b138..20d8157a 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java @@ -5,6 +5,7 @@ import com.mojang.logging.LogUtils; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.mixins.accessors.BeaconBlockEntityRendererInvoker; import de.hysky.skyblocker.mixins.accessors.DrawContextInvoker; +import de.hysky.skyblocker.utils.Boxes; import de.hysky.skyblocker.utils.render.culling.OcclusionCulling; import de.hysky.skyblocker.utils.render.title.Title; import de.hysky.skyblocker.utils.render.title.TitleContainer; @@ -30,7 +31,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.ColorHelper; import net.minecraft.util.math.Vec3d; - import org.joml.Matrix3f; import org.joml.Matrix4f; import org.joml.Vector3f; @@ -61,6 +61,10 @@ public class RenderHelper { renderBeaconBeam(context, pos, colorComponents); } + public static void renderFilled(WorldRenderContext context, Box box, float[] colorComponents, float alpha, boolean throughWalls) { + renderFilled(context, box.getMinPos(), Boxes.getLengthVec(box), colorComponents, alpha, throughWalls); + } + public static void renderFilled(WorldRenderContext context, BlockPos pos, float[] colorComponents, float alpha, boolean throughWalls) { renderFilled(context, Vec3d.of(pos), ONE, colorComponents, alpha, throughWalls); } @@ -72,11 +76,11 @@ public class RenderHelper { public static void renderFilled(WorldRenderContext context, Vec3d pos, Vec3d dimensions, float[] colorComponents, float alpha, boolean throughWalls) { if (throughWalls) { if (FrustumUtils.isVisible(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + dimensions.x, pos.getY() + dimensions.y, pos.getZ() + dimensions.z)) { - renderFilledInternal(context, pos, dimensions, colorComponents, alpha, true); + renderFilledInternal(context, pos, dimensions, colorComponents, alpha, true); } } else { if (OcclusionCulling.getRegularCuller().isVisible(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + dimensions.x, pos.getY() + dimensions.y, pos.getZ() + dimensions.z)) { - renderFilledInternal(context, pos, dimensions, colorComponents, alpha, false); + renderFilledInternal(context, pos, dimensions, colorComponents, alpha, false); } } } @@ -228,7 +232,7 @@ public class RenderHelper { Vector3f normal = new Vector3f((float) offset.x, (float) offset.y, (float) offset.z); buffer - .vertex(positionMatrix, (float) cameraPoint.x , (float) cameraPoint.y, (float) cameraPoint.z) + .vertex(positionMatrix, (float) cameraPoint.x, (float) cameraPoint.y, (float) cameraPoint.z) .color(colorComponents[0], colorComponents[1], colorComponents[2], alpha) .normal(normal.x, normal.y, normal.z); @@ -298,9 +302,9 @@ public class RenderHelper { scale *= 0.025f; positionMatrix - .translate((float) (pos.getX() - cameraPos.getX()), (float) (pos.getY() - cameraPos.getY()), (float) (pos.getZ() - cameraPos.getZ())) - .rotate(camera.getRotation()) - .scale(scale, -scale, scale); + .translate((float) (pos.getX() - cameraPos.getX()), (float) (pos.getY() - cameraPos.getY()), (float) (pos.getZ() - cameraPos.getZ())) + .rotate(camera.getRotation()) + .scale(scale, -scale, scale); float xOffset = -textRenderer.getWidth(text) / 2f; @@ -336,6 +340,13 @@ public class RenderHelper { } } + /** + * Retrieves the bounding box of a block in the world. + * + * @param world The client world. + * @param pos The position of the block. + * @return The bounding box of the block. + */ public static Box getBlockBoundingBox(ClientWorld world, BlockPos pos) { return getBlockBoundingBox(world, world.getBlockState(pos), pos); } @@ -383,8 +394,9 @@ public class RenderHelper { if (width == 0 || height == 0) { return; } - ((DrawContextInvoker) context).invokeDrawTexturedQuad(sprite.getAtlasId(), x, x + width, y, y + height, z, sprite.getFrameU((float)k / (float)i), sprite.getFrameU((float)(k + width) / (float)i), sprite.getFrameV((float)l / (float)j), sprite.getFrameV((float)(l + height) / (float)j), red, green, blue, alpha); + ((DrawContextInvoker) context).invokeDrawTexturedQuad(sprite.getAtlasId(), x, x + width, y, y + height, z, sprite.getFrameU((float) k / (float) i), sprite.getFrameU((float) (k + width) / (float) i), sprite.getFrameV((float) l / (float) j), sprite.getFrameV((float) (l + height) / (float) j), red, green, blue, alpha); } + private static void drawSpriteTiled(DrawContext context, Sprite sprite, int x, int y, int z, int width, int height, int i, int j, int tileWidth, int tileHeight, int k, int l, float red, float green, float blue, float alpha) { if (width <= 0 || height <= 0) { return; @@ -440,9 +452,10 @@ public class RenderHelper { } private static final float[] colorBuffer = new float[4]; + public static void renderNineSliceColored(DrawContext context, Identifier texture, int x, int y, int width, int height, Color color) { color.getComponents(colorBuffer); - renderNineSliceColored(context, texture, x, y, width, height, colorBuffer[0],colorBuffer[1],colorBuffer[2],colorBuffer[3]); + renderNineSliceColored(context, texture, x, y, width, height, colorBuffer[0], colorBuffer[1], colorBuffer[2], colorBuffer[3]); } // TODO Get rid of reflection once the new Sodium is released |