From af3ee7975c89284f5c7e6a4a52502ae905a2bf8a Mon Sep 17 00:00:00 2001 From: katie Date: Mon, 27 May 2024 15:02:18 -0400 Subject: [PATCH] temporary to move to desktop --- .../command/MinesweeperCommand.java | 92 ++++++++++-------- .../gui/sprites/minesweeper/eight_tile.png | Bin 225 -> 256 bytes .../gui/sprites/minesweeper/empty_tile.png | Bin 156 -> 163 bytes .../gui/sprites/minesweeper/five_tile.png | Bin 203 -> 3490 bytes .../gui/sprites/minesweeper/four_tile.png | Bin 207 -> 3504 bytes .../gui/sprites/minesweeper/one_tile.png | Bin 208 -> 245 bytes .../gui/sprites/minesweeper/seven_tile.png | Bin 205 -> 248 bytes .../gui/sprites/minesweeper/six_tile.png | Bin 220 -> 256 bytes .../gui/sprites/minesweeper/three_tile.png | Bin 216 -> 253 bytes .../textures/gui/sprites/minesweeper/tile.png | Bin 180 -> 183 bytes .../gui/sprites/minesweeper/two_tile.png | Bin 234 -> 255 bytes 11 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/MinesweeperCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/MinesweeperCommand.java index 790d356d6..741211bb8 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/MinesweeperCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/MinesweeperCommand.java @@ -1,11 +1,12 @@ package net.earthcomputer.clientcommands.command; +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -16,31 +17,28 @@ import org.jetbrains.annotations.Nullable; import org.joml.Vector2i; -import java.util.OptionalInt; import java.util.Random; -import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; -import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +import static com.mojang.brigadier.arguments.IntegerArgumentType.*; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; public class MinesweeperCommand { private static final SimpleCommandExceptionType TOO_MANY_MINES_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.cminesweeper.too_many_mines")); public static void register(CommandDispatcher dispatcher) { dispatcher.register(literal("cminesweeper") - .then(literal("beginner") - .executes(ctx -> minesweeper(ctx.getSource(), 9, 9, 10))) - .executes(ctx -> minesweeper(ctx.getSource(), 9, 9, 10)) - .then(literal("intermediate") - .executes(ctx -> minesweeper(ctx.getSource(), 16, 16, 40))) - .then(literal("expert") - .executes(ctx -> minesweeper(ctx.getSource(), 32, 16, 99))) - .then(literal("custom") - .then(argument("width", integer(3, 128)) - .then(argument("height", integer(3, 128)) - .then(argument("mines", integer(0, 128 * 128 - 9)) - .executes(ctx -> minesweeper(ctx.getSource(), getInteger(ctx, "width"), getInteger(ctx, "height"), getInteger(ctx, "mines")))))))); + .executes(ctx -> minesweeper(ctx.getSource(), 9, 9, 10)) + .then(literal("beginner") + .executes(ctx -> minesweeper(ctx.getSource(), 9, 9, 10))) + .then(literal("intermediate") + .executes(ctx -> minesweeper(ctx.getSource(), 16, 16, 40))) + .then(literal("expert") + .executes(ctx -> minesweeper(ctx.getSource(), 32, 16, 99))) + .then(literal("custom") + .then(argument("width", integer(3, 128)) + .then(argument("height", integer(3, 128)) + .then(argument("mines", integer(0, 128 * 128 - 9)) + .executes(ctx -> minesweeper(ctx.getSource(), getInteger(ctx, "width"), getInteger(ctx, "height"), getInteger(ctx, "mines")))))))); } private static int minesweeper(FabricClientCommandSource source, int width, int height, int mines) throws CommandSyntaxException { @@ -50,7 +48,7 @@ private static int minesweeper(FabricClientCommandSource source, int width, int source.getClient().tell(() -> source.getClient().setScreen(new MinesweeperGameScreen(width, height, mines))); - return 0; + return Command.SINGLE_SUCCESS; } } @@ -90,8 +88,10 @@ class MinesweeperGameScreen extends Screen { int gameHeight; int topLeftX; int topLeftY; - @Nullable Integer dragging; - @Nullable Vector2i deathCoords; + @Nullable + Integer dragging; + @Nullable + Vector2i deathCoords; int minesLeft; int emptyTilesRemaining; @@ -124,16 +124,22 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float tickDelta graphics.drawCenteredString(minecraft.font, title.getString(), topLeftX + gameWidth / 2, topLeftY - 20, 0xff_ffffff); { String str = "Time Played: " + Math.ceilDiv(ticksPlaying, 20) + "s"; - graphics.drawString(minecraft.font, str, topLeftX + gameWidth - minecraft.font.width(str), topLeftY - 10, deathCoords != null ? ChatFormatting.RED.getColor() : (emptyTilesRemaining == 0 ? ChatFormatting.GREEN.getColor() : ChatFormatting.WHITE.getColor())); + graphics.drawString(minecraft.font, str, topLeftX + gameWidth - minecraft.font.width(str), topLeftY - 10, deathCoords != null ? ChatFormatting.RED.getColor() : (emptyTilesRemaining == 0 ? ChatFormatting.GREEN.getColor() : ChatFormatting.WHITE.getColor())); } graphics.blitSprite(TOP_LEFT, topLeftX, topLeftY, 12, 12); - for (int i = 0; i < boardWidth; i++) graphics.blitSprite(TOP, topLeftX + 12 + i * 16, topLeftY, 16, 12); + for (int i = 0; i < boardWidth; i++) { + graphics.blitSprite(TOP, topLeftX + 12 + i * 16, topLeftY, 16, 12); + } graphics.blitSprite(TOP_RIGHT, topLeftX + 12 + boardWidth * 16, topLeftY, 8, 12); - for (int i = 0; i < boardHeight; i++) graphics.blitSprite(LEFT, topLeftX, topLeftY + 12 + i * 16, 12, 16); - for (int i = 0; i < boardHeight; i++) graphics.blitSprite(RIGHT, topLeftX + 12 + boardWidth * 16, topLeftY + 12 + i * 16, 8, 16); + for (int i = 0; i < boardHeight; i++) { + graphics.blitSprite(LEFT, topLeftX, topLeftY + 12 + i * 16, 12, 16); + graphics.blitSprite(RIGHT, topLeftX + 12 + boardWidth * 16, topLeftY + 12 + i * 16, 8, 16); + } graphics.blitSprite(BOTTOM_LEFT, topLeftX, topLeftY + 12 + boardHeight * 16, 12, 8); - for (int i = 0; i < boardWidth; i++) graphics.blitSprite(BOTTOM, topLeftX + 12 + i * 16, topLeftY + 12 + boardHeight * 16, 16, 8); + for (int i = 0; i < boardWidth; i++) { + graphics.blitSprite(BOTTOM, topLeftX + 12 + i * 16, topLeftY + 12 + boardHeight * 16, 16, 8); + } graphics.blitSprite(BOTTOM_RIGHT, topLeftX + 12 + boardWidth * 16, topLeftY + 12 + boardHeight * 16, 8, 8); for (int x = 0; x < boardWidth; x++) { @@ -164,8 +170,8 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { int tileX = Mth.floorDiv((int) (mouseX - topLeftX - 12), 16); int tileY = Mth.floorDiv((int) (mouseY - topLeftY - 12), 16); - if (isWithinBounds(tileX, tileY)) { - if (button == 0 && !gameFinished()) { + if (isWithinBounds(tileX, tileY) && !gameFinished()) { + if (button == InputConstants.MOUSE_BUTTON_LEFT) { if (ticksPlaying == 0) { generateMines(tileX, tileY); ticksPlaying = 1; @@ -178,7 +184,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { } else if (deathCoords != null) { minecraft.player.playNotifySound(SoundEvents.NOTE_BLOCK_BASS.value(), SoundSource.MASTER, 1.0f, 1.0f); } - } else if (button == 1 && !gameFinished()) { + } else if (button == InputConstants.MOUSE_BUTTON_RIGHT) { flag(tileX, tileY); } } @@ -268,19 +274,19 @@ private void click(int x, int y) { queue[0] = y * boardWidth + x; while (queueIdx >= 0) { int idx = queue[queueIdx--]; - int x_part = idx % boardWidth; - int y_part = idx / boardWidth; + int xPart = idx % boardWidth; + int yPart = idx / boardWidth; for (Vector2i possibleNeighbour : new Vector2i[]{ - new Vector2i(x_part - 1, y_part - 1), - new Vector2i(x_part, y_part - 1), - new Vector2i(x_part + 1, y_part - 1), + new Vector2i(xPart - 1, yPart - 1), + new Vector2i(xPart, yPart - 1), + new Vector2i(xPart + 1, yPart - 1), - new Vector2i(x_part - 1, y_part), - new Vector2i(x_part + 1, y_part), + new Vector2i(xPart - 1, yPart), + new Vector2i(xPart + 1, yPart), - new Vector2i(x_part - 1, y_part + 1), - new Vector2i(x_part, y_part + 1), - new Vector2i(x_part + 1, y_part + 1), + new Vector2i(xPart - 1, yPart + 1), + new Vector2i(xPart, yPart + 1), + new Vector2i(xPart + 1, yPart + 1), }) { if (isWithinBounds(possibleNeighbour.x, possibleNeighbour.y)) { int pos = possibleNeighbour.y * boardWidth + possibleNeighbour.x; @@ -290,7 +296,9 @@ private void click(int x, int y) { if ((value & 0b1) == 0) { emptyTilesRemaining -= 1; // if it's an empty tile, we put it in the queue to go activate all its neighbours - if ((value & 0b11_0_0) >>> 2 == 0) queue[++queueIdx] = pos; + if ((value & 0b11_0_0) >>> 2 == 0) { + queue[++queueIdx] = pos; + } } } } @@ -299,7 +307,9 @@ private void click(int x, int y) { } private void flag(int x, int y) { - if ((board[y * boardWidth + x] & 0b1) > 0) return; + if ((board[y * boardWidth + x] & 0b1) > 0) { + return; + } minesLeft -= ((board[y * boardWidth + x] ^= 0b1_0) & 0b1_0) > 0 ? 1 : -1; } diff --git a/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/eight_tile.png b/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/eight_tile.png index 1bc586895b6e8b8d8fdd3f5e01b9dc72aad1bfbb..af2eb1128f9c3b688a7c794e0607f83c10ba9faf 100644 GIT binary patch delta 191 zcmV;w06_oY0e}LKNq@lr01m+cxRGn^0001$Nkl^Kt$xdZ)GtEIOkf=%+uY`&8-8A-jNxil{f)2x1LY{u`+lRqLl$+ thG>ByZo}yi=`GIaSNi>#D8^X-ume`Xpv7VrteOA-002ovPDHLkV1n?0P+$N6 delta 160 zcmV;R0AK%r0^tFWNq@os01mx4 diff --git a/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/empty_tile.png b/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/empty_tile.png index c0381c9d89f307d09f8c72a6b7241a1de3898f84..21a498265b32576d0b97020fd7d5d84d25f0ac95 100644 GIT binary patch delta 97 zcmbQkxR`N*XVgIk2EK!gJ0@noWnf^i@N{tuvG7keF*pBz-a(CnlQS^^#FiHlYSMET z(a_XPOmGrc5$%yO$YMCWf>GeY-MfG13o$TQzH*h->0!G=ss@)z4*}Q$iB}&chy_ delta 90 zcmV-g0Hyz<0h|GlNmIfA01m7~jRY5&!@I07*qoM6N<$f;#pdz5oCK diff --git a/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/five_tile.png b/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/five_tile.png index 1157341e66719c5d3058c0e51e2b90ea8af3999b..c4933821d5873464c71b4e87ce330a8bc7b97409 100644 GIT binary patch literal 3490 zcmd^B$!{A~7@ujpO`Foty#-O%LKRYi<9f*=#St^MW1QNKmpC*HQ97P^8BaWmJBt%@ z=z&9vgoK0&XAlUG_#coE2TmN2xFRIfg2bhjkdUehwS3=<9or?P1&LFhHE;Red%tge z-{(@g7`skWb1hNJsk}sj+p=gilA()JpVzt)D)Fha3 zxMa&5TYw>L#mHjSp*E7DGftLk~95zW1x;;v~6JC*!mzREUJ zY<_$u-IlWT+~yWCXEVyea=|dWXY+ZAh95;ef`%iu(F4#GOT4UE zY27LkE1c#nej?bj`LM|+f+<_EY=a~=_V0Qx|7raT1xCU7z?r!PnQ;QF)3Pfo`n(F<>i- z@j~ZC^4>PXGrksYfNREB!{9q;$ngysjeTT*V9IZiqXX-<`yxF6zo(yFUtrH*EHHlP zaDtx)nLg$wM~;mGzoi?#je@Mgs$vk0G)c$X#-~ctJ_ZPfUnV>9X4vAT$XaCGcMwSFIV1&TF&T zk;`EqP4>A&XQ6aCTmai;65D0MN~{a`dk^r)5MTlU@u^M^0L}oA131$I1Uj57f0-i$PV~+!aV9yFXhHur$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1vuk+WNWK? zv}75IR-XZycaqzlAmrfJj1n!0j?Pr41;vgkW)Jf8hdPjU@Eui$$|Br`!YQM|5QJ_zQCTx zSm1ro;RHVqGJV2LjvPCAa#J_BoxGyqAliy5^E*Ylr(hOeXWuu@M$rgwpV=>eY{0*)f^sV9L!uond$$G7U_j?)M{GI|Dvp#qW84cgC%|EWMA z^tr(-E-F@&w47Y-)QFa$x2Rz$)byFQaf3*7+}WJ!7ms5u!Kodi?%b^)-IIL?C*yc7 zKZD=Y0PoeuY%%Ok4c;iZVxToxzyH$Umdo7fhXI@fcouH(=b-DS=JT-dBK_aVgxS+q z14qg$Ezjhj1Qn>1qPt;E6?CIX)b0{RaKv~Sd7>Ck(+d4PRE0Scil9urrbM(bYp$bz`mgkL0Ak#=8e#@!ct2p>y)E~?b6>i^71n$BXc59@ iZXEIWGa;o^pKt(2L1M0F=tfKc0000D%PDHLkV1hc2GP(c& diff --git a/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/seven_tile.png b/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/seven_tile.png index ede2a6738593e3e8d52d78095e1499685e239abf..8a9035db46d12fe5152d2f9350ba946a8292acb0 100644 GIT binary patch delta 183 zcmV;o07(DM0r&xsNq@lr01m+cxRGn^0001uNklXl lKoTPII32+E&jgbF3m5PxV^vHX^BMpE002ovPDHLkV1i|BOC$gQ delta 140 zcmV;70CWHN0nGuBNq@os01m==~AKxG#on~V-{xsGBN5M=LGsCm5sI|%si@$QmLhBt%0WT%w zp@UDCMMT=Zhn!nDj`IMLg&E&AEG2jc>ng4H6bKg}pa>Uu<2ZdDBo}zj;1vum05f0& t0bG((z)pHbFC{GtGF!U*nZ(`46&|aff}DRb;GF;f002ovPDHLkV1gGPPGA54 delta 155 zcmV;M0A&Aw0^9+RNq@os01m-TTT z84GeYF>+5~WA@h8*5Ed`sCy$Zg_TidH^W^a5%C4H`*;d=_B}E C05W3$ diff --git a/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/tile.png b/src/main/resources/assets/clientcommands/textures/gui/sprites/minesweeper/tile.png index 14c626a0766b955c24db0955f280eee21d4c9107..a4de3c7dcde43cb4888a5f2242e7260e2f00672c 100644 GIT binary patch delta 117 zcmV-*0E+*#0k;8=Np8Ua01m+cxRGn^0000?NklfPq`0ShtU_w}j z4$j1~b0#0*L($;x%_JCLLJ;7EH8Q$8;KST9cax6bv!~*=NH=GY3U|c924_MR3mbGi sxA=C(MUD*;u07*XG~E770-)Yu0fv-q8}F8}}l delta 169 zcmV;a09OD10qOyeNq@os01m