diff --git a/build.gradle b/build.gradle index 2a1bb796..e44a78a5 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,9 @@ configure( group = $group version = $version - archivesBaseName = $modBaseName + tasks.withType(Jar).configureEach { + archiveBaseName.set("${$modBaseName}") + } configurations { library diff --git a/common/build.gradle b/common/build.gradle index d8fd35fa..163f12a8 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -2,7 +2,9 @@ apply plugin: 'maven-publish' group = $group version = $version -archivesBaseName = $commonBaseName +tasks.withType(Jar).configureEach { + archiveBaseName.set("${$commonBaseName}") +} dependencies { compileOnly 'org.apache.logging.log4j:log4j-api:2.0-beta9' diff --git a/common/src/test/java/CodeTesting.java b/common/src/test/java/CodeTesting.java deleted file mode 100644 index 141f8f1f..00000000 --- a/common/src/test/java/CodeTesting.java +++ /dev/null @@ -1,12 +0,0 @@ -import org.junit.jupiter.api.Test; - - -public class CodeTesting { - public static boolean test = false; - - @Test - public void testAdd() { - - } - -} diff --git a/fabric-1.21.9/.gitignore b/fabric-1.21.11/.gitignore similarity index 100% rename from fabric-1.21.9/.gitignore rename to fabric-1.21.11/.gitignore diff --git a/fabric-1.21.9/build.gradle b/fabric-1.21.11/build.gradle similarity index 82% rename from fabric-1.21.9/build.gradle rename to fabric-1.21.11/build.gradle index dd3a297c..08bd95dc 100644 --- a/fabric-1.21.9/build.gradle +++ b/fabric-1.21.11/build.gradle @@ -1,14 +1,14 @@ plugins { - id 'fabric-loom' version "1.11-SNAPSHOT" + id 'fabric-loom' version "1.14-SNAPSHOT" - id "me.modmuss50.mod-publish-plugin" version "0.8.4" + id "me.modmuss50.mod-publish-plugin" version "1.1.0" } loom.runs.client.runDir = "../runs/run" dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" @@ -34,7 +34,7 @@ publishMods { modrinth { projectId = "412tAvWq" accessToken = providers.environmentVariable("MODRINTH_TOKEN") - minecraftVersions.add("1.21.9") + minecraftVersions.add("1.21.11") } /*github { repository = "MPKMod/MPKMod2" diff --git a/fabric-1.21.9/gradle.properties b/fabric-1.21.11/gradle.properties similarity index 56% rename from fabric-1.21.9/gradle.properties rename to fabric-1.21.11/gradle.properties index 1b215788..67a97799 100644 --- a/fabric-1.21.9/gradle.properties +++ b/fabric-1.21.11/gradle.properties @@ -1,14 +1,13 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs=-Xmx3G org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.9 -yarn_mappings=1.21.9+build.1 -loader_version=0.17.2 +minecraft_version=1.21.11 +loader_version=0.18.2 # Fabric API -fabric_version=0.133.14+1.21.9 +fabric_version=0.139.5+1.21.11 jdkVersion=21 diff --git a/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/EventHandler.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/EventHandler.java new file mode 100644 index 00000000..7fbc949e --- /dev/null +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/EventHandler.java @@ -0,0 +1,124 @@ +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11; + +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.kurrycat.mpkmod.compatibility.API; +import io.github.kurrycat.mpkmod.compatibility.MCClasses.Player; +import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin.KeyMappingAccessor; +import io.github.kurrycat.mpkmod.ticks.ButtonMS; +import io.github.kurrycat.mpkmod.ticks.ButtonMSList; +import io.github.kurrycat.mpkmod.util.BoundingBox3D; +import io.github.kurrycat.mpkmod.util.Vector3D; +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.minecraft.client.DeltaTracker; +import net.minecraft.client.Minecraft; +import net.minecraft.client.Options; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.util.Util; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; + +public class EventHandler { + private static final ButtonMSList timeQueue = new ButtonMSList(); + + /** + * @param keyInput The Minecraft {@link KeyEvent} object. + * @param action The action, where 0 = unpressed, 1 = pressed, 2 = held. + */ + public void onKey(KeyEvent keyInput, int action) { + Options options = Minecraft.getInstance().options; + long eventNanos = Util.getNanos(); + + InputConstants.Key inputKey = InputConstants.getKey(new KeyEvent(keyInput.key(), keyInput.scancode(), keyInput.modifiers())); + + int[] keys = { + ((KeyMappingAccessor) options.keyUp).getKey().getValue(), + ((KeyMappingAccessor) options.keyLeft).getKey().getValue(), + ((KeyMappingAccessor) options.keyDown).getKey().getValue(), + ((KeyMappingAccessor) options.keyRight).getKey().getValue(), + ((KeyMappingAccessor) options.keySprint).getKey().getValue(), + ((KeyMappingAccessor) options.keyShift).getKey().getValue(), + ((KeyMappingAccessor) options.keyJump).getKey().getValue() + }; + + for (int i = 0; i < keys.length; i++) { + if (keyInput.key() == keys[i]) { + timeQueue.add(ButtonMS.of(ButtonMS.Button.values()[i], eventNanos, action == 1)); + } + } + + if (action == 1) { + FunctionCompatibility.pressedButtons.add(inputKey.getValue()); + } else if (action == 0) { + FunctionCompatibility.pressedButtons.remove(inputKey.getValue()); + } + + API.Events.onKeyInput(keyInput.key(), inputKey.getDisplayName().getString(), action == 1); + + MPKMod.keyBindingMap.forEach((id, keyBinding) -> { + if (keyBinding.isDown()) { + API.Events.onKeybind(id); + } + }); + } + + public void onInGameOverlayRender(GuiGraphics drawContext, DeltaTracker renderTickCounter) { + drawContext.pose().pushMatrix(); + API.getFunctionHolder().drawContext = drawContext; + API.Events.onRenderOverlay(); + drawContext.pose().popMatrix(); + } + + public void onRenderWorldOverlay(PoseStack matrixStack, float tickDelta) { + MPKMod.INSTANCE.matrixStack = matrixStack; + matrixStack.pushPose(); + Vec3 pos = Minecraft.getInstance().gameRenderer.getMainCamera().position().reverse(); + MPKMod.INSTANCE.matrixStack.translate(pos); + API.Events.onRenderWorldOverlay(tickDelta); + matrixStack.popPose(); + } + + public void onClientTickStart(Minecraft mc) { + if (mc.isPaused() || mc.level == null) return; + API.Events.onTickStart(); + } + + public void onClientTickEnd(Minecraft mc) { + if (mc.isPaused() || mc.level == null) return; + LocalPlayer mcPlayer = mc.player; + + if (mcPlayer != null) { + AABB playerBB = mcPlayer.getBoundingBox(); + new Player() + .setPos(new Vector3D(mcPlayer.getX(), mcPlayer.getY(), mcPlayer.getZ())) + .setLastPos(new Vector3D(mcPlayer.xo, mcPlayer.yo, mcPlayer.zo)) + .setMotion(new Vector3D(mcPlayer.getDeltaMovement().x, mcPlayer.getDeltaMovement().y, mcPlayer.getDeltaMovement().z)) + .setRotation(mcPlayer.getRotationVector().y, mcPlayer.getRotationVector().x) + .setOnGround(mcPlayer.onGround()) + .setSprinting(mcPlayer.isSprinting()) + .setBoundingBox(new BoundingBox3D( + new Vector3D(playerBB.minX, playerBB.minY, playerBB.minZ), + new Vector3D(playerBB.maxX, playerBB.maxY, playerBB.maxZ) + )) + .setFlying(mcPlayer.getAbilities().flying) + .constructKeyInput() + .setKeyMSList(timeQueue) + .buildAndSave(); + timeQueue.clear(); + } + + API.Events.onTickEnd(); + } + + + public void onServerConnect(ClientPacketListener clientPlayNetworkHandler, PacketSender packetSender, Minecraft minecraftClient) { + API.Events.onServerConnect(clientPlayNetworkHandler.getConnection().isMemoryConnection()); + } + + public void onServerDisconnect(ClientPacketListener clientPlayNetworkHandler, Minecraft minecraftClient) { + API.Events.onServerDisconnect(); + } +} diff --git a/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/FunctionCompatibility.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/FunctionCompatibility.java new file mode 100644 index 00000000..4b596a79 --- /dev/null +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/FunctionCompatibility.java @@ -0,0 +1,457 @@ +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11; + +import com.mojang.blaze3d.pipeline.RenderPipeline; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import io.github.kurrycat.mpkmod.compatibility.MCClasses.*; +import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin.KeyMappingAccessor; +import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.network.DataCustomPayload; +import io.github.kurrycat.mpkmod.gui.MPKGuiScreen; +import io.github.kurrycat.mpkmod.util.BoundingBox3D; +import io.github.kurrycat.mpkmod.util.Debug; +import io.github.kurrycat.mpkmod.util.Vector2D; +import io.github.kurrycat.mpkmod.util.Vector3D; +import io.github.kurrycat.mpknetapi.common.network.packet.MPKPacket; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Options; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.navigation.ScreenRectangle; +import net.minecraft.client.gui.render.TextureSetup; +import net.minecraft.client.gui.render.state.GuiElementRenderState; +import net.minecraft.client.gui.render.state.pip.PictureInPictureRenderState; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.multiplayer.ServerData; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.client.renderer.ShapeRenderer; +import net.minecraft.client.renderer.rendertype.RenderTypes; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.util.Mth; +import net.minecraft.util.Util; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; +import java.util.*; + +public class FunctionCompatibility implements FunctionHolder, + SoundManager.Interface, + WorldInteraction.Interface, + Renderer3D.Interface, + Renderer2D.Interface, + FontRenderer.Interface, + Minecraft.Interface, + Keyboard.Interface, + Profiler.Interface { + public static final Set pressedButtons = new HashSet<>(); + public GuiGraphics drawContext = null; + + public void playButtonSound() { + net.minecraft.client.Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + } + + public ArrayList getCollisionBoundingBoxes(Vector3D blockPosVector) { + final Vector3D blockPosVec = blockPosVector.copy(); + BlockPos blockPos = new BlockPos(blockPosVec.getXI(), blockPosVec.getYI(), blockPosVec.getZI()); + if (net.minecraft.client.Minecraft.getInstance().level == null) return null; + ArrayList boundingBoxes = new ArrayList<>(); + BlockState blockState = net.minecraft.client.Minecraft.getInstance().level.getBlockState(blockPos); + + blockState.getCollisionShape(net.minecraft.client.Minecraft.getInstance().level, blockPos).optimize().forAllBoxes( + ((minX, minY, minZ, maxX, maxY, maxZ) -> boundingBoxes.add( + new BoundingBox3D(new Vector3D(minX, minY, minZ), new Vector3D(maxX, maxY, maxZ)).move(blockPosVec) + )) + ); + + return boundingBoxes; + } + + public Vector3D getLookingAt() { + if (net.minecraft.client.Minecraft.getInstance().getCameraEntity() == null) + return null; + + HitResult hitResult = net.minecraft.client.Minecraft.getInstance().getCameraEntity().pick(20, 0, false); + if (hitResult instanceof BlockHitResult) { + BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos(); + return new Vector3D(blockPos.getX(), blockPos.getY(), blockPos.getZ()); + } + + return null; + } + + @Override + public String getBlockName(Vector3D blockPos) { + BlockPos blockpos = new BlockPos(blockPos.getXI(), blockPos.getYI(), blockPos.getZI()); + if (net.minecraft.client.Minecraft.getInstance().level == null) + return null; + + return BuiltInRegistries.BLOCK.getResourceKey( + net.minecraft.client.Minecraft.getInstance().level.getBlockState(blockpos).getBlock() + ).get().identifier().toString(); + } + + @Override + public HashMap getBlockProperties(Vector3D blockPos) { + HashMap properties = new HashMap<>(); + if (net.minecraft.client.Minecraft.getInstance().level == null) + return properties; + + BlockPos blockpos = new BlockPos(blockPos.getXI(), blockPos.getYI(), blockPos.getZI()); + BlockState blockState = net.minecraft.client.Minecraft.getInstance().level.getBlockState(blockpos); + blockState.getValues().forEach((key, value) -> + properties.put(key.getName(), Util.getPropertyName(key, value)) + ); + return null; + } + + /** + * Is called in {@link WorldInteraction.Interface WorldInteraction.Interface} + */ + public String getLookingAtBlock() { + if (net.minecraft.client.Minecraft.getInstance().getCameraEntity() == null) + return null; + + HitResult hitResult = net.minecraft.client.Minecraft.getInstance().getCameraEntity().pick(20, 0, false); + if (hitResult.getType() == HitResult.Type.BLOCK && net.minecraft.client.Minecraft.getInstance().level != null) { + return BuiltInRegistries.BLOCK.getResourceKey( + net.minecraft.client.Minecraft.getInstance().level.getBlockState(((BlockHitResult) hitResult).getBlockPos()).getBlock() + ).get().identifier().toLanguageKey(); + } + return null; + } + + public void drawBox(BoundingBox3D bb, Color color, float partialTicks) { + var ms = MPKMod.INSTANCE.matrixStack; + ms.pushPose(); + ms.translate((float) bb.minX(), (float) bb.minY(), (float) bb.minZ()); + + VoxelShape shape = Shapes.box( + 0.0, 0.0, 0.0, + bb.maxX() - bb.minX(), + bb.maxY() - bb.minY(), + bb.maxZ() - bb.minZ() + ); + + VertexConsumer buf = net.minecraft.client.Minecraft.getInstance() + .renderBuffers().bufferSource().getBuffer(RenderTypes.debugFilledBox()); + + renderFilled(ms, buf, shape, 0, 0, 0, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); + ms.popPose(); + } + + public static void renderFilled(PoseStack poseStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double x, double y, double z, float r, float g, float b, float a) { + PoseStack.Pose pose = poseStack.last(); + voxelShape.forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> { + float x1 = (float)(minX + x); + float y1 = (float)(minY + y); + float z1 = (float)(minZ + z); + float x2 = (float)(maxX + x); + float y2 = (float)(maxY + y); + float z2 = (float)(maxZ + z); + + // Draw all 6 faces of the box + // Down + vertexConsumer.addVertex(pose, x1, y1, z1).setColor(r, g, b, a).setNormal(pose, 0, -1, 0); + vertexConsumer.addVertex(pose, x2, y1, z1).setColor(r, g, b, a).setNormal(pose, 0, -1, 0); + vertexConsumer.addVertex(pose, x2, y1, z2).setColor(r, g, b, a).setNormal(pose, 0, -1, 0); + vertexConsumer.addVertex(pose, x1, y1, z2).setColor(r, g, b, a).setNormal(pose, 0, -1, 0); + + // Up + vertexConsumer.addVertex(pose, x1, y2, z2).setColor(r, g, b, a).setNormal(pose, 0, 1, 0); + vertexConsumer.addVertex(pose, x2, y2, z2).setColor(r, g, b, a).setNormal(pose, 0, 1, 0); + vertexConsumer.addVertex(pose, x2, y2, z1).setColor(r, g, b, a).setNormal(pose, 0, 1, 0); + vertexConsumer.addVertex(pose, x1, y2, z1).setColor(r, g, b, a).setNormal(pose, 0, 1, 0); + + // North + vertexConsumer.addVertex(pose, x1, y1, z1).setColor(r, g, b, a).setNormal(pose, 0, 0, -1); + vertexConsumer.addVertex(pose, x1, y2, z1).setColor(r, g, b, a).setNormal(pose, 0, 0, -1); + vertexConsumer.addVertex(pose, x2, y2, z1).setColor(r, g, b, a).setNormal(pose, 0, 0, -1); + vertexConsumer.addVertex(pose, x2, y1, z1).setColor(r, g, b, a).setNormal(pose, 0, 0, -1); + + // South + vertexConsumer.addVertex(pose, x2, y1, z2).setColor(r, g, b, a).setNormal(pose, 0, 0, 1); + vertexConsumer.addVertex(pose, x2, y2, z2).setColor(r, g, b, a).setNormal(pose, 0, 0, 1); + vertexConsumer.addVertex(pose, x1, y2, z2).setColor(r, g, b, a).setNormal(pose, 0, 0, 1); + vertexConsumer.addVertex(pose, x1, y1, z2).setColor(r, g, b, a).setNormal(pose, 0, 0, 1); + + // West + vertexConsumer.addVertex(pose, x1, y1, z2).setColor(r, g, b, a).setNormal(pose, -1, 0, 0); + vertexConsumer.addVertex(pose, x1, y2, z2).setColor(r, g, b, a).setNormal(pose, -1, 0, 0); + vertexConsumer.addVertex(pose, x1, y2, z1).setColor(r, g, b, a).setNormal(pose, -1, 0, 0); + vertexConsumer.addVertex(pose, x1, y1, z1).setColor(r, g, b, a).setNormal(pose, -1, 0, 0); + + // East + vertexConsumer.addVertex(pose, x2, y1, z1).setColor(r, g, b, a).setNormal(pose, 1, 0, 0); + vertexConsumer.addVertex(pose, x2, y2, z1).setColor(r, g, b, a).setNormal(pose, 1, 0, 0); + vertexConsumer.addVertex(pose, x2, y2, z2).setColor(r, g, b, a).setNormal(pose, 1, 0, 0); + vertexConsumer.addVertex(pose, x2, y1, z2).setColor(r, g, b, a).setNormal(pose, 1, 0, 0); + }); + } + + + /** + * Is called in {@link Renderer2D.Interface} + */ + public void drawRect(Vector2D pos, Vector2D size, Color color) { + if (drawContext == null) return; + drawContext.fill( + (int) pos.getX(), (int) pos.getY(), + (int) (pos.getX() + size.getX()), (int) (pos.getY() + size.getY()), + color.getRGB() + ); + } + + /** + * Is called in {@link Renderer2D.Interface} + */ + public void drawLines(Collection points, Color color) { + if (points.size() < 2) { + Debug.stacktrace("At least two points expected, got: " + points.size()); + return; + } + int r = color.getRed(), g = color.getGreen(), b = color.getBlue(), a = color.getAlpha(); + + var window = net.minecraft.client.Minecraft.getInstance().getWindow(); + var bounds = new ScreenRectangle(0, 0, window.getGuiScaledWidth(), window.getGuiScaledHeight()); + + drawContext.guiRenderState.submitGuiElement(new PointsRenderState( + points, + r, g, b, a, + PictureInPictureRenderState.getBounds(bounds.left(), bounds.top(), bounds.right(), bounds.bottom(), drawContext.scissorStack.peek()), + drawContext.scissorStack.peek() + )); + } + + public Vector2D getScaledSize() { + return new Vector2D( + net.minecraft.client.Minecraft.getInstance().getWindow().getGuiScaledWidth(), + net.minecraft.client.Minecraft.getInstance().getWindow().getGuiScaledHeight() + ); + } + + public Vector2D getScreenSize() { + return new Vector2D(net.minecraft.client.Minecraft.getInstance().getWindow().getScreenWidth(), net.minecraft.client.Minecraft.getInstance().getWindow().getScreenHeight()); + } + + public void enableScissor(double x, double y, double w, double h) { + int x1 = (int) x; + int y1 = (int) y; + int x2 = (int) (x + w); + int y2 = (int) (y + h); + drawContext.enableScissor(x1, y1, x2, y2); + } + + public void disableScissor() { + try { + drawContext.disableScissor(); + } catch (IllegalStateException ignored) {} + } + + public void clearScissors() { + boolean clearedAll = false; + while (!clearedAll) { + try { + drawContext.disableScissor(); + } catch (IllegalStateException e) { + clearedAll = true; + } + } + } + + public boolean scissorContains(Vector2D point) { + return drawContext.containsPointInScissor(point.getXI(), point.getYI()); + } + + public void drawString(String text, double x, double y, Color color, double fontSize, boolean shadow) { + if (drawContext == null) return; + var matrixStack = drawContext.pose(); + matrixStack.pushMatrix(); + matrixStack.translate((float) x, (float) y); + double scale = fontSize / net.minecraft.client.Minecraft.getInstance().font.lineHeight; + matrixStack.scale((float) scale, (float) scale); + drawContext.drawString( + net.minecraft.client.Minecraft.getInstance().font, text, + 0, 0, color.getRGB(), shadow + ); + matrixStack.popMatrix(); + } + + public Vector2D getStringSize(String text, double fontSize) { + return new Vector2D( + net.minecraft.client.Minecraft.getInstance().font.width(text) * + (float) (fontSize / net.minecraft.client.Minecraft.getInstance().font.lineHeight), + (float) fontSize + ); + } + + public String getIP() { + ServerData d = net.minecraft.client.Minecraft.getInstance().getCurrentServer(); + + if (d == null) + return "Multiplayer"; + else + return d.ip; + } + + public String getFPS() { + return String.valueOf(net.minecraft.client.Minecraft.getInstance().getFps()); + } + + public void displayGuiScreen(MPKGuiScreen screen) { + net.minecraft.client.Minecraft.getInstance().setScreen( + screen == null + ? null + : new io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.MPKGuiScreen(screen)); + } + + public String getCurrentGuiScreen() { + Screen curr = net.minecraft.client.Minecraft.getInstance().screen; + + if (curr == null) + return null; + else if (curr instanceof io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.MPKGuiScreen) { + String id = ((io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.MPKGuiScreen) curr).eventReceiver.getID(); + if (id == null) + id = "unknown"; + + return id; + } + + return curr.getClass().getSimpleName(); + } + + /** + * Is called in {@link Minecraft.Interface Minecraft.Interface} + */ + public String getUserName() { + if (net.minecraft.client.Minecraft.getInstance().player == null) return null; + return net.minecraft.client.Minecraft.getInstance().player.getName().getString(); + } + + public void copyToClipboard(String content) { + net.minecraft.client.Minecraft.getInstance().keyboardHandler.setClipboard(content); + } + + public boolean setInputs(Float yaw, boolean relYaw, Float pitch, boolean relPitch, int pressedInputs, int releasedInputs, int L, int R) { + if (!Minecraft.isSingleplayer()) return false; + LocalPlayer player = net.minecraft.client.Minecraft.getInstance().player; + if (player == null) return false; + Options op = net.minecraft.client.Minecraft.getInstance().options; + + float prevYaw = player.getYRot(); + float prevPitch = player.getXRot(); + + if (yaw != null) { + player.setYRot(relYaw ? (player.getYRot() + yaw) : yaw); + player.yRotO += player.getYRot() - prevYaw; + } + if (pitch != null) { + player.setXRot(relPitch ? (player.getXRot() + pitch) : pitch); + player.setXRot(Mth.clamp(player.getXRot(), -90.0F, 90.0F)); + + player.xRotO += player.getXRot() - prevPitch; + player.xRotO = Mth.clamp(player.xRotO, -90.0F, 90.0F); + } + + if (player.getVehicle() != null) { + player.getVehicle().onPassengerTurned(player); + } + + KeyMapping[] keys = new KeyMapping[]{ + op.keyUp, + op.keyLeft, + op.keyDown, + op.keyRight, + op.keySprint, + op.keyShift, + op.keyJump + }; + + for (int i = 0; i < keys.length; i++) { + if ((releasedInputs & 1 << i) != 0) { + KeyMapping.set(((KeyMappingAccessor) keys[i]).getKey(), false); + } + if ((pressedInputs & 1 << i) != 0) { + KeyMapping.set(((KeyMappingAccessor) keys[i]).getKey(), true); + KeyMapping.click(((KeyMappingAccessor) keys[i]).getKey()); + } + } + + KeyMapping.set(((KeyMappingAccessor) op.keyAttack).getKey(), L > 0); + for (int i = 0; i < L; i++) + KeyMapping.click(((KeyMappingAccessor) op.keyAttack).getKey()); + + KeyMapping.set(((KeyMappingAccessor) op.keyUse).getKey(), R > 0); + for (int i = 0; i < R; i++) + KeyMapping.click(((KeyMappingAccessor) op.keyUse).getKey()); + + return true; + } + + public boolean isF3Enabled() { + return net.minecraft.client.Minecraft.getInstance().debugEntries.isOverlayVisible(); + } + + public void sendPacket(MPKPacket packet) { + ClientPlayNetworking.send(new DataCustomPayload(packet.getData())); + } + + public ArrayList getPressedButtons() { + return new ArrayList<>(pressedButtons); + } + + public void startSection(String name) { + net.minecraft.util.profiling.Profiler.get().push(name); + } + + public void endStartSection(String name) { + net.minecraft.util.profiling.Profiler.get().popPush(name); + } + + public void endSection() { + net.minecraft.util.profiling.Profiler.get().pop(); + } + + private record PointsRenderState( + Collection points, + int r, int g, int b, int a, + ScreenRectangle bounds, + ScreenRectangle scissor + ) implements GuiElementRenderState { + + @Override + public @Nullable ScreenRectangle bounds() { + return this.bounds; + } + + @Override + public void buildVertices(VertexConsumer consumer) { + for (Vector2D p : this.points) { + consumer.addVertex((float) p.getX(), (float) p.getY(), 0).setColor(r, g, b, a); + } + } + + @Override + public RenderPipeline pipeline() { + return RenderPipelines.GUI; + } + + @Override + public TextureSetup textureSetup() { + return TextureSetup.noTexture(); + } + + @Override + public @Nullable ScreenRectangle scissorArea() { + return this.scissor; + } + } +} diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/MPKGuiScreen.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/MPKGuiScreen.java similarity index 68% rename from fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/MPKGuiScreen.java rename to fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/MPKGuiScreen.java index c39e79d4..714d0d57 100644 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/MPKGuiScreen.java +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/MPKGuiScreen.java @@ -1,22 +1,22 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9; +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11; import io.github.kurrycat.mpkmod.compatibility.API; import io.github.kurrycat.mpkmod.compatibility.MCClasses.Profiler; import io.github.kurrycat.mpkmod.util.MathUtil; import io.github.kurrycat.mpkmod.util.Vector2D; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.input.CharInput; -import net.minecraft.client.input.KeyInput; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.network.chat.Component; public class MPKGuiScreen extends Screen { public io.github.kurrycat.mpkmod.gui.MPKGuiScreen eventReceiver; public MPKGuiScreen(io.github.kurrycat.mpkmod.gui.MPKGuiScreen screen) { - super(Text.translatable(API.MODID + ".gui.title")); + super(Component.translatable(API.MODID + ".gui.title")); eventReceiver = screen; } @@ -26,14 +26,14 @@ public void init() { } @Override - public void resize(MinecraftClient client, int width, int height) { - super.resize(client, width, height); + public void resize(int width, int height) { + super.resize(width, height); eventReceiver.onResize(width, height); } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - drawContext.getMatrices().pushMatrix(); + public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) { + drawContext.pose().pushMatrix(); API.getFunctionHolder().drawContext = drawContext; Profiler.startSection(eventReceiver.getID() == null ? "mpk_gui" : eventReceiver.getID()); try { @@ -42,46 +42,46 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) API.LOGGER.warn("Error in drawScreen with id: " + eventReceiver.getID(), e); } Profiler.endSection(); - drawContext.getMatrices().popMatrix(); + drawContext.pose().popMatrix(); } @Override - public void close() { - super.close(); + public void onClose() { + super.onClose(); eventReceiver.onGuiClosed(); } @Override - public boolean shouldPause() { + public boolean isPauseScreen() { return false; } @Override - public boolean mouseClicked(Click click, boolean doubled) { + public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { eventReceiver.onMouseClicked(new Vector2D(click.x(), click.y()), click.button()); return super.mouseClicked(click, doubled); } @Override - public boolean mouseReleased(Click click) { + public boolean mouseReleased(MouseButtonEvent click) { eventReceiver.onMouseReleased(new Vector2D(click.x(), click.y()), click.button()); return super.mouseReleased(click); } @Override - public boolean mouseDragged(Click click, double offsetX, double offsetY) { + public boolean mouseDragged(MouseButtonEvent click, double offsetX, double offsetY) { eventReceiver.onMouseClickMove(new Vector2D(click.x(), click.y()), click.button(), 0); return super.mouseDragged(click, offsetX, offsetY); } @Override - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { eventReceiver.onKeyEvent(input.key(), input.scancode(), input.modifiers(), false); return super.keyPressed(input); } @Override - public boolean charTyped(CharInput input) { + public boolean charTyped(CharacterEvent input) { eventReceiver.onKeyEvent(input.codepoint(), 0, input.modifiers(), true); return super.charTyped(input); } diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/MPKMod.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/MPKMod.java similarity index 75% rename from fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/MPKMod.java rename to fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/MPKMod.java index 3ef388d0..e87ddfcc 100644 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/MPKMod.java +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/MPKMod.java @@ -1,8 +1,9 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9; +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11; +import com.mojang.blaze3d.vertex.PoseStack; import io.github.kurrycat.mpkmod.compatibility.API; import io.github.kurrycat.mpkmod.compatibility.MCClasses.KeyBinding; -import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.network.DataCustomPayload; +import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.network.DataCustomPayload; import io.github.kurrycat.mpknetapi.common.network.packet.MPKPacket; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; @@ -11,20 +12,18 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry; import net.minecraft.SharedConstants; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.KeyBinding.Category; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; - +import net.minecraft.client.KeyMapping.Category; +import net.minecraft.client.Minecraft; +import net.minecraft.resources.Identifier; import java.util.HashMap; import java.util.Map; public class MPKMod implements ModInitializer { public static final MPKMod INSTANCE = new MPKMod(); - public static Map keyBindingMap = new HashMap<>(); + public static Map keyBindingMap = new HashMap<>(); public final EventHandler eventHandler = new EventHandler(); - public MatrixStack matrixStack; - public static final Category KEYBINDING_CATEGORY = Category.create(Identifier.of(API.MODID, "mpkmod_2")); + public PoseStack matrixStack; + public static final Category KEYBINDING_CATEGORY = Category.register(Identifier.fromNamespaceAndPath(API.MODID, "mpkmod_2")); @Override public void onInitialize() { @@ -34,7 +33,7 @@ public void onInitialize() { API.preInit(getClass()); registerKeybindingsFromGUIs(); - HudElementRegistry.addLast(Identifier.of(API.MODID, "hud_layer"), eventHandler::onInGameOverlayRender); + HudElementRegistry.addLast(Identifier.fromNamespaceAndPath(API.MODID, "hud_layer"), eventHandler::onInGameOverlayRender); ClientTickEvents.START_CLIENT_TICK.register(eventHandler::onClientTickStart); ClientTickEvents.END_CLIENT_TICK.register(eventHandler::onClientTickEnd); ClientPlayConnectionEvents.JOIN.register(eventHandler::onServerConnect); @@ -60,7 +59,7 @@ private void registerKeybindingsFromGUIs() { } public void registerKeyBinding(String id) { - net.minecraft.client.option.KeyBinding keyBinding = new net.minecraft.client.option.KeyBinding( + net.minecraft.client.KeyMapping keyBinding = new net.minecraft.client.KeyMapping( API.MODID + ".key." + id + ".desc", -1, KEYBINDING_CATEGORY @@ -75,17 +74,17 @@ public void init() { API.LOGGER.info(API.COMPATIBILITY_MARKER, "Registered compatibility functions."); registerKeyBindings(); - API.init(SharedConstants.getGameVersion().name()); + API.init(SharedConstants.getCurrentVersion().name()); API.Events.onLoadComplete(); } private void registerKeyBindings() { - for (net.minecraft.client.option.KeyBinding k : MinecraftClient.getInstance().options.allKeys) { + for (net.minecraft.client.KeyMapping k : Minecraft.getInstance().options.keyMappings) { new KeyBinding( - () -> k.getBoundKeyLocalizedText().getString(), - k.getId(), - k::isPressed + () -> k.getTranslatedKeyMessage().getString(), + k.getName(), + k::isDown ); } diff --git a/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/KeyMappingAccessor.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/KeyMappingAccessor.java new file mode 100644 index 00000000..ec39381c --- /dev/null +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/KeyMappingAccessor.java @@ -0,0 +1,12 @@ +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin; + +import com.mojang.blaze3d.platform.InputConstants; +import net.minecraft.client.KeyMapping; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(KeyMapping.class) +public interface KeyMappingAccessor { + @Accessor + InputConstants.Key getKey(); +} diff --git a/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/KeyboardHandlerMixin.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/KeyboardHandlerMixin.java new file mode 100644 index 00000000..018a692d --- /dev/null +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/KeyboardHandlerMixin.java @@ -0,0 +1,19 @@ +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin; + +import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.MPKMod; +import net.minecraft.client.KeyboardHandler; +import net.minecraft.client.input.KeyEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(KeyboardHandler.class) +public class KeyboardHandlerMixin { + @Inject(method = "keyPress", at = @At(value = "RETURN")) + private void onKey(long window, int action, KeyEvent keyInput, CallbackInfo ci) { + if (keyInput.key() != -1) { + MPKMod.INSTANCE.eventHandler.onKey(keyInput, action); + } + } +} diff --git a/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/LevelRendererMixin.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/LevelRendererMixin.java new file mode 100644 index 00000000..c170ed9b --- /dev/null +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/LevelRendererMixin.java @@ -0,0 +1,23 @@ +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin; + +import com.mojang.blaze3d.vertex.PoseStack; +import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.MPKMod; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.SubmitNodeStorage; +import net.minecraft.client.renderer.state.LevelRenderState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = LevelRenderer.class) +public class LevelRendererMixin { + @Inject(method = "submitBlockEntities", at = @At("HEAD")) + public void render(PoseStack matrices, LevelRenderState renderState, SubmitNodeStorage orderedRenderCommandQueueImpl, CallbackInfo ci) { + MPKMod.INSTANCE.eventHandler.onRenderWorldOverlay( + new PoseStack(), + Minecraft.getInstance().getDeltaTracker().getGameTimeDeltaPartialTick(true) + ); + } +} diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/MinecraftClientMixin.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/MinecraftMixin.java similarity index 57% rename from fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/MinecraftClientMixin.java rename to fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/MinecraftMixin.java index 0d7a676c..500fc75f 100644 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/MinecraftClientMixin.java +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/MinecraftMixin.java @@ -1,14 +1,14 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.mixin; +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin; -import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.MPKMod; -import net.minecraft.client.MinecraftClient; +import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.MPKMod; +import net.minecraft.client.Minecraft; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(MinecraftClient.class) -public class MinecraftClientMixin { +@Mixin(Minecraft.class) +public class MinecraftMixin { @Inject(at = @At("TAIL"), method = "") private void init(CallbackInfo info) { MPKMod.INSTANCE.init(); diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/MouseMixin.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/MouseHandlerMixin.java similarity index 61% rename from fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/MouseMixin.java rename to fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/MouseHandlerMixin.java index 80293cd5..58d30f22 100644 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/MouseMixin.java +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/mixin/MouseHandlerMixin.java @@ -1,55 +1,55 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.mixin; +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin; import io.github.kurrycat.mpkmod.compatibility.API; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.Mouse; -import net.minecraft.client.input.MouseInput; +import net.minecraft.client.Minecraft; +import net.minecraft.client.MouseHandler; +import net.minecraft.client.input.MouseButtonInfo; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(Mouse.class) -public class MouseMixin { +@Mixin(MouseHandler.class) +public class MouseHandlerMixin { @Shadow - private double cursorDeltaX; + private double accumulatedDX; @Shadow - private double cursorDeltaY; + private double accumulatedDY; @Shadow - private double x; + private double xpos; @Shadow - private double y; + private double ypos; - @Inject(method = "onCursorPos", at = @At(value = "TAIL")) + @Inject(method = "onMove", at = @At(value = "TAIL")) private void onCursorPos(long window, double x, double y, CallbackInfo ci) { - if (window == MinecraftClient.getInstance().getWindow().getHandle()) { + if (window == Minecraft.getInstance().getWindow().handle()) { API.Events.onMouseInput( io.github.kurrycat.mpkmod.util.Mouse.Button.NONE, io.github.kurrycat.mpkmod.util.Mouse.State.NONE, - (int) x, (int) y, (int) cursorDeltaX, (int) -cursorDeltaY, + (int) x, (int) y, (int) accumulatedDX, (int) -accumulatedDY, 0, System.nanoTime() ); } } - @Inject(method = "onMouseScroll", at = @At(value = "TAIL")) + @Inject(method = "onScroll", at = @At(value = "TAIL")) private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci) { API.Events.onMouseInput( io.github.kurrycat.mpkmod.util.Mouse.Button.NONE, io.github.kurrycat.mpkmod.util.Mouse.State.NONE, - (int) x, (int) y, 0, 0, + (int) xpos, (int) ypos, 0, 0, (int) vertical, System.nanoTime() ); } - @Inject(method = "onMouseButton", at = @At(value = "TAIL")) - private void onMouseButton(long window, MouseInput input, int action, CallbackInfo ci) { + @Inject(method = "onButton", at = @At(value = "TAIL")) + private void onMouseButton(long window, MouseButtonInfo input, int action, CallbackInfo ci) { API.Events.onMouseInput( io.github.kurrycat.mpkmod.util.Mouse.Button.fromInt(input.button()), input.button() == -1 ? io.github.kurrycat.mpkmod.util.Mouse.State.NONE : (action == 1 ? io.github.kurrycat.mpkmod.util.Mouse.State.DOWN : io.github.kurrycat.mpkmod.util.Mouse.State.UP), - (int) x, (int) y, 0, 0, + (int) xpos, (int) ypos, 0, 0, 0, System.nanoTime() ); } diff --git a/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/network/DataCustomPayload.java b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/network/DataCustomPayload.java new file mode 100644 index 00000000..03423724 --- /dev/null +++ b/fabric-1.21.11/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_11/network/DataCustomPayload.java @@ -0,0 +1,36 @@ +package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.network; + +import io.github.kurrycat.mpknetapi.common.MPKNetworking; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; + +public record DataCustomPayload(byte[] data) implements CustomPacketPayload { + public static final Type MPK_ID = new Type<>(Identifier.fromNamespaceAndPath(MPKNetworking.CHANNEL_NAMESPACE, MPKNetworking.CHANNEL_PATH)); + + public static final StreamCodec CODEC = StreamCodec.ofMember( + (payload, buf) -> buf.writeBytes(payload.data()), + buf -> { + byte[] data = new byte[buf.readableBytes()]; + buf.readBytes(data); + return new DataCustomPayload(data); + } + ); + + @Override + public Type type() { + return MPK_ID; + } + + public static Type registerClientboundPayload() { + PayloadTypeRegistry.playS2C().register(MPK_ID, DataCustomPayload.CODEC); + return MPK_ID; + } + + public static Type registerServerboundPayload() { + PayloadTypeRegistry.playC2S().register(MPK_ID, DataCustomPayload.CODEC); + return MPK_ID; + } +} \ No newline at end of file diff --git a/fabric-1.21.11/src/main/resources/assets/mpkmod/icon.png b/fabric-1.21.11/src/main/resources/assets/mpkmod/icon.png new file mode 100644 index 00000000..e69de29b diff --git a/fabric-1.21.9/src/main/resources/assets/mpkmod/lang/en_us.json b/fabric-1.21.11/src/main/resources/assets/mpkmod/lang/en_us.json similarity index 100% rename from fabric-1.21.9/src/main/resources/assets/mpkmod/lang/en_us.json rename to fabric-1.21.11/src/main/resources/assets/mpkmod/lang/en_us.json diff --git a/fabric-1.21.11/src/main/resources/assets/mpkmod/lang/pl_pl.json b/fabric-1.21.11/src/main/resources/assets/mpkmod/lang/pl_pl.json new file mode 100644 index 00000000..e69de29b diff --git a/fabric-1.21.9/src/main/resources/fabric.mod.json b/fabric-1.21.11/src/main/resources/fabric.mod.json similarity index 74% rename from fabric-1.21.9/src/main/resources/fabric.mod.json rename to fabric-1.21.11/src/main/resources/fabric.mod.json index 8cc89a6d..5b93be26 100644 --- a/fabric-1.21.9/src/main/resources/fabric.mod.json +++ b/fabric-1.21.11/src/main/resources/fabric.mod.json @@ -2,7 +2,6 @@ "schemaVersion": 1, "id": "mpkmod", "version": "${version}", - "name": "MPK Mod", "description": "A Mod that adds some features that help parkour to the game.", "authors": [ @@ -13,25 +12,23 @@ "Contributors" ], "contact": { - "sources": "https://github.com/kurrycat2004/MPKMod_2" + "sources": "https://github.com/MPKMod/MPKMod2" }, - "license": "MIT", "icon": "assets/mpkmod/icon.png", "environment": "client", "entrypoints": { "main": [ - "io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.MPKMod" + "io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.MPKMod" ] }, "mixins": [ "mpkmod.mixins.json" ], - "depends": { - "fabricloader": ">=0.17.2", + "fabricloader": ">=0.18.0", "fabric-api": "*", - "minecraft": ">=1.21.9", + "minecraft": ">=1.21.11", "java": ">=21" }, "suggests": {} diff --git a/fabric-1.21.9/src/main/resources/mpkmod.mixins.json b/fabric-1.21.11/src/main/resources/mpkmod.mixins.json similarity index 62% rename from fabric-1.21.9/src/main/resources/mpkmod.mixins.json rename to fabric-1.21.11/src/main/resources/mpkmod.mixins.json index 82c84991..5a973cb1 100644 --- a/fabric-1.21.9/src/main/resources/mpkmod.mixins.json +++ b/fabric-1.21.11/src/main/resources/mpkmod.mixins.json @@ -1,16 +1,16 @@ { "required": true, "minVersion": "0.8", - "package": "io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.mixin", + "package": "io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin", "compatibilityLevel": "JAVA_21", "mixins": [ ], "client": [ - "GameRendererMixin", - "KeyBindingAccessor", - "KeyboardMixin", - "MinecraftClientMixin", - "MouseMixin" + "LevelRendererMixin", + "KeyMappingAccessor", + "KeyboardHandlerMixin", + "MinecraftMixin", + "MouseHandlerMixin" ], "injectors": { "defaultRequire": 1 diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/EventHandler.java b/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/EventHandler.java deleted file mode 100644 index edbcc808..00000000 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/EventHandler.java +++ /dev/null @@ -1,124 +0,0 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9; - -import io.github.kurrycat.mpkmod.compatibility.API; -import io.github.kurrycat.mpkmod.compatibility.MCClasses.Player; -import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.mixin.KeyBindingAccessor; -import io.github.kurrycat.mpkmod.ticks.ButtonMS; -import io.github.kurrycat.mpkmod.ticks.ButtonMSList; -import io.github.kurrycat.mpkmod.util.BoundingBox3D; -import io.github.kurrycat.mpkmod.util.Vector3D; -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.option.GameOptions; -import net.minecraft.client.render.RenderTickCounter; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Util; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.Vec3d; - -public class EventHandler { - private static final ButtonMSList timeQueue = new ButtonMSList(); - - /** - * @param keyInput The Minecraft {@link KeyInput} object. - * @param action The action, where 0 = unpressed, 1 = pressed, 2 = held. - */ - public void onKey(KeyInput keyInput, int action) { - GameOptions options = MinecraftClient.getInstance().options; - long eventNanos = Util.getMeasuringTimeNano(); - - InputUtil.Key inputKey = InputUtil.fromKeyCode(new KeyInput(keyInput.key(), keyInput.scancode(), keyInput.modifiers())); - - int[] keys = { - ((KeyBindingAccessor) options.forwardKey).getBoundKey().getCode(), - ((KeyBindingAccessor) options.leftKey).getBoundKey().getCode(), - ((KeyBindingAccessor) options.backKey).getBoundKey().getCode(), - ((KeyBindingAccessor) options.rightKey).getBoundKey().getCode(), - ((KeyBindingAccessor) options.sprintKey).getBoundKey().getCode(), - ((KeyBindingAccessor) options.sneakKey).getBoundKey().getCode(), - ((KeyBindingAccessor) options.jumpKey).getBoundKey().getCode() - }; - - for (int i = 0; i < keys.length; i++) { - if (keyInput.key() == keys[i]) { - timeQueue.add(ButtonMS.of(ButtonMS.Button.values()[i], eventNanos, action == 1)); - } - } - - if (action == 1) { - FunctionCompatibility.pressedButtons.add(inputKey.getCode()); - } else if (action == 0) { - FunctionCompatibility.pressedButtons.remove(inputKey.getCode()); - } - - API.Events.onKeyInput(keyInput.key(), inputKey.getLocalizedText().getString(), action == 1); - - MPKMod.keyBindingMap.forEach((id, keyBinding) -> { - if (keyBinding.isPressed()) { - API.Events.onKeybind(id); - } - }); - } - - public void onInGameOverlayRender(DrawContext drawContext, RenderTickCounter renderTickCounter) { - drawContext.getMatrices().pushMatrix(); - API.getFunctionHolder().drawContext = drawContext; - API.Events.onRenderOverlay(); - drawContext.getMatrices().popMatrix(); - } - - public void onRenderWorldOverlay(MatrixStack matrixStack, float tickDelta) { - MPKMod.INSTANCE.matrixStack = matrixStack; - matrixStack.push(); - Vec3d pos = MinecraftClient.getInstance().gameRenderer.getCamera().getPos().negate(); - MPKMod.INSTANCE.matrixStack.translate(pos); - API.Events.onRenderWorldOverlay(tickDelta); - matrixStack.pop(); - } - - public void onClientTickStart(MinecraftClient mc) { - if (mc.isPaused() || mc.world == null) return; - API.Events.onTickStart(); - } - - public void onClientTickEnd(MinecraftClient mc) { - if (mc.isPaused() || mc.world == null) return; - ClientPlayerEntity mcPlayer = mc.player; - - if (mcPlayer != null) { - Box playerBB = mcPlayer.getBoundingBox(); - new Player() - .setPos(new Vector3D(mcPlayer.getX(), mcPlayer.getY(), mcPlayer.getZ())) - .setLastPos(new Vector3D(mcPlayer.lastX, mcPlayer.lastY, mcPlayer.lastZ)) - .setMotion(new Vector3D(mcPlayer.getVelocity().x, mcPlayer.getVelocity().y, mcPlayer.getVelocity().z)) - .setRotation(mcPlayer.getRotationClient().y, mcPlayer.getRotationClient().x) - .setOnGround(mcPlayer.isOnGround()) - .setSprinting(mcPlayer.isSprinting()) - .setBoundingBox(new BoundingBox3D( - new Vector3D(playerBB.minX, playerBB.minY, playerBB.minZ), - new Vector3D(playerBB.maxX, playerBB.maxY, playerBB.maxZ) - )) - .setFlying(mcPlayer.getAbilities().flying) - .constructKeyInput() - .setKeyMSList(timeQueue) - .buildAndSave(); - timeQueue.clear(); - } - - API.Events.onTickEnd(); - } - - - public void onServerConnect(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender, MinecraftClient minecraftClient) { - API.Events.onServerConnect(clientPlayNetworkHandler.getConnection().isLocal()); - } - - public void onServerDisconnect(ClientPlayNetworkHandler clientPlayNetworkHandler, MinecraftClient minecraftClient) { - API.Events.onServerDisconnect(); - } -} diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/FunctionCompatibility.java b/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/FunctionCompatibility.java deleted file mode 100644 index 7ce47d10..00000000 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/FunctionCompatibility.java +++ /dev/null @@ -1,410 +0,0 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9; - -import com.mojang.blaze3d.pipeline.RenderPipeline; -import com.mojang.blaze3d.systems.RenderSystem; -import io.github.kurrycat.mpkmod.compatibility.MCClasses.*; -import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.mixin.KeyBindingAccessor; -import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.network.DataCustomPayload; -import io.github.kurrycat.mpkmod.gui.MPKGuiScreen; -import io.github.kurrycat.mpkmod.util.BoundingBox3D; -import io.github.kurrycat.mpkmod.util.Debug; -import io.github.kurrycat.mpkmod.util.Vector2D; -import io.github.kurrycat.mpkmod.util.Vector3D; -import io.github.kurrycat.mpknetapi.common.network.packet.MPKPacket; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.minecraft.block.BlockState; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gl.RenderPipelines; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.ScreenRect; -import net.minecraft.client.gui.render.state.SimpleGuiElementRenderState; -import net.minecraft.client.gui.render.state.special.SpecialGuiElementRenderState; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.ServerInfo; -import net.minecraft.client.option.GameOptions; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexRendering; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.texture.TextureSetup; -import net.minecraft.registry.Registries; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.Util; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.hit.HitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.profiler.Profilers; -import org.jetbrains.annotations.Nullable; - -import java.awt.*; -import java.util.*; -import java.util.List; - -public class FunctionCompatibility implements FunctionHolder, - SoundManager.Interface, - WorldInteraction.Interface, - Renderer3D.Interface, - Renderer2D.Interface, - FontRenderer.Interface, - Minecraft.Interface, - Keyboard.Interface, - Profiler.Interface { - public static final Set pressedButtons = new HashSet<>(); - public DrawContext drawContext = null; - - public void playButtonSound() { - MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); - } - - public List getCollisionBoundingBoxes(Vector3D blockPosVector) { - final Vector3D blockPosVec = blockPosVector.copy(); - BlockPos blockPos = new BlockPos(blockPosVec.getXI(), blockPosVec.getYI(), blockPosVec.getZI()); - if (MinecraftClient.getInstance().world == null) return null; - ArrayList boundingBoxes = new ArrayList<>(); - BlockState blockState = MinecraftClient.getInstance().world.getBlockState(blockPos); - - blockState.getCollisionShape(MinecraftClient.getInstance().world, blockPos).simplify().forEachBox( - ((minX, minY, minZ, maxX, maxY, maxZ) -> boundingBoxes.add( - new BoundingBox3D(new Vector3D(minX, minY, minZ), new Vector3D(maxX, maxY, maxZ)).move(blockPosVec) - )) - ); - - return boundingBoxes; - } - - public Vector3D getLookingAt() { - if (MinecraftClient.getInstance().getCameraEntity() == null) - return null; - - HitResult hitResult = MinecraftClient.getInstance().getCameraEntity().raycast(20, 0, false); - if (hitResult instanceof BlockHitResult) { - BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos(); - return new Vector3D(blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - return null; - } - - @Override - public String getBlockName(Vector3D blockPos) { - BlockPos blockpos = new BlockPos(blockPos.getXI(), blockPos.getYI(), blockPos.getZI()); - if (MinecraftClient.getInstance().world == null) - return null; - - return Registries.BLOCK.getKey( - MinecraftClient.getInstance().world.getBlockState(blockpos).getBlock() - ).get().getValue().toString(); - } - - @Override - public HashMap getBlockProperties(Vector3D blockPos) { - HashMap properties = new HashMap<>(); - if (MinecraftClient.getInstance().world == null) - return properties; - - BlockPos blockpos = new BlockPos(blockPos.getXI(), blockPos.getYI(), blockPos.getZI()); - BlockState blockState = MinecraftClient.getInstance().world.getBlockState(blockpos); - blockState.getEntries().forEach((key, value) -> - properties.put(key.getName(), Util.getValueAsString(key, value)) - ); - return null; - } - - /** - * Is called in {@link WorldInteraction.Interface WorldInteraction.Interface} - */ - public String getLookingAtBlock() { - if (MinecraftClient.getInstance().getCameraEntity() == null) - return null; - - HitResult hitResult = MinecraftClient.getInstance().getCameraEntity().raycast(20, 0, false); - if (hitResult.getType() == HitResult.Type.BLOCK && MinecraftClient.getInstance().world != null) { - return Registries.BLOCK.getKey( - MinecraftClient.getInstance().world.getBlockState(((BlockHitResult) hitResult).getBlockPos()).getBlock() - ).get().getValue().toTranslationKey(); - } - return null; - } - - public void drawBox(BoundingBox3D bb, Color color, float partialTicks) { - int r = color.getRed(), g = color.getGreen(), b = color.getBlue(), a = color.getAlpha(); - - RenderSystem.lineWidth(1.0F); - - float minX = (float) bb.minX(); - float minY = (float) bb.minY(); - float minZ = (float) bb.minZ(); - float maxX = (float) bb.maxX(); - float maxY = (float) bb.maxY(); - float maxZ = (float) bb.maxZ(); - - VertexRendering.drawFilledBox( - MPKMod.INSTANCE.matrixStack, - MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers().getBuffer(RenderLayer.getDebugFilledBox()), - minX, minY, minZ, - maxX, maxY, maxZ, - r / 255f, g / 255f, b / 255f, a / 255f - ); - } - - /** - * Is called in {@link Renderer2D.Interface} - */ - public void drawRect(Vector2D pos, Vector2D size, Color color) { - if (drawContext == null) return; - drawContext.fill( - (int) pos.getX(), (int) pos.getY(), - (int) (pos.getX() + size.getX()), (int) (pos.getY() + size.getY()), - color.getRGB() - ); - } - - /** - * Is called in {@link Renderer2D.Interface} - */ - public void drawLines(Collection points, Color color) { - if (points.size() < 2) { - Debug.stacktrace("At least two points expected, got: " + points.size()); - return; - } - int r = color.getRed(), g = color.getGreen(), b = color.getBlue(), a = color.getAlpha(); - - var window = MinecraftClient.getInstance().getWindow(); - var bounds = new ScreenRect(0, 0, window.getScaledWidth(), window.getScaledHeight()); - - drawContext.state.addSimpleElement(new PointsRenderState( - points, - r, g, b, a, - SpecialGuiElementRenderState.createBounds(bounds.getLeft(), bounds.getTop(), bounds.getRight(), bounds.getBottom(), drawContext.scissorStack.peekLast()), - drawContext.scissorStack.peekLast() - )); - } - - public Vector2D getScaledSize() { - return new Vector2D( - MinecraftClient.getInstance().getWindow().getScaledWidth(), - MinecraftClient.getInstance().getWindow().getScaledHeight() - ); - } - - public Vector2D getScreenSize() { - return new Vector2D(MinecraftClient.getInstance().getWindow().getWidth(), MinecraftClient.getInstance().getWindow().getHeight()); - } - - public void enableScissor(double x, double y, double w, double h) { - int x1 = (int) x; - int y1 = (int) y; - int x2 = (int) (x + w); - int y2 = (int) (y + h); - drawContext.enableScissor(x1, y1, x2, y2); - } - - public void disableScissor() { - try { - drawContext.disableScissor(); - } catch (IllegalStateException ignored) {} - } - - public void clearScissors() { - boolean clearedAll = false; - while (!clearedAll) { - try { - drawContext.disableScissor(); - } catch (IllegalStateException e) { - clearedAll = true; - } - } - } - - public boolean scissorContains(Vector2D point) { - return drawContext.scissorContains(point.getXI(), point.getYI()); - } - - public void drawString(String text, double x, double y, Color color, double fontSize, boolean shadow) { - if (drawContext == null) return; - var matrixStack = drawContext.getMatrices(); - matrixStack.pushMatrix(); - matrixStack.translate((float) x, (float) y); - double scale = fontSize / MinecraftClient.getInstance().textRenderer.fontHeight; - matrixStack.scale((float) scale, (float) scale); - drawContext.drawText( - MinecraftClient.getInstance().textRenderer, text, - 0, 0, color.getRGB(), shadow - ); - matrixStack.popMatrix(); - } - - public Vector2D getStringSize(String text, double fontSize) { - return new Vector2D( - MinecraftClient.getInstance().textRenderer.getWidth(text) * - (float) (fontSize / MinecraftClient.getInstance().textRenderer.fontHeight), - (float) fontSize - ); - } - - public String getIP() { - ServerInfo d = MinecraftClient.getInstance().getCurrentServerEntry(); - - if (d == null) - return "Multiplayer"; - else - return d.address; - } - - public String getFPS() { - return String.valueOf(MinecraftClient.getInstance().getCurrentFps()); - } - - public void displayGuiScreen(MPKGuiScreen screen) { - MinecraftClient.getInstance().setScreen( - screen == null - ? null - : new io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.MPKGuiScreen(screen)); - } - - public String getCurrentGuiScreen() { - Screen curr = MinecraftClient.getInstance().currentScreen; - - if (curr == null) - return null; - else if (curr instanceof io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.MPKGuiScreen) { - String id = ((io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.MPKGuiScreen) curr).eventReceiver.getID(); - if (id == null) - id = "unknown"; - - return id; - } - - return curr.getClass().getSimpleName(); - } - - /** - * Is called in {@link Minecraft.Interface Minecraft.Interface} - */ - public String getUserName() { - if (MinecraftClient.getInstance().player == null) return null; - return MinecraftClient.getInstance().player.getName().getString(); - } - - public void copyToClipboard(String content) { - MinecraftClient.getInstance().keyboard.setClipboard(content); - } - - public boolean setInputs(Float yaw, boolean relYaw, Float pitch, boolean relPitch, int pressedInputs, int releasedInputs, int L, int R) { - if (!Minecraft.isSingleplayer()) return false; - ClientPlayerEntity player = MinecraftClient.getInstance().player; - if (player == null) return false; - GameOptions op = MinecraftClient.getInstance().options; - - float prevYaw = player.getYaw(); - float prevPitch = player.getPitch(); - - if (yaw != null) { - player.setYaw(relYaw ? (player.getYaw() + yaw) : yaw); - player.lastYaw += player.getYaw() - prevYaw; - } - if (pitch != null) { - player.setPitch(relPitch ? (player.getPitch() + pitch) : pitch); - player.setPitch(MathHelper.clamp(player.getPitch(), -90.0F, 90.0F)); - - player.lastPitch += player.getPitch() - prevPitch; - player.lastPitch = MathHelper.clamp(player.lastPitch, -90.0F, 90.0F); - } - - if (player.getVehicle() != null) { - player.getVehicle().onPassengerLookAround(player); - } - - KeyBinding[] keys = new KeyBinding[]{ - op.forwardKey, - op.leftKey, - op.backKey, - op.rightKey, - op.sprintKey, - op.sneakKey, - op.jumpKey - }; - - for (int i = 0; i < keys.length; i++) { - if ((releasedInputs & 1 << i) != 0) { - KeyBinding.setKeyPressed(((KeyBindingAccessor) keys[i]).getBoundKey(), false); - } - if ((pressedInputs & 1 << i) != 0) { - KeyBinding.setKeyPressed(((KeyBindingAccessor) keys[i]).getBoundKey(), true); - KeyBinding.onKeyPressed(((KeyBindingAccessor) keys[i]).getBoundKey()); - } - } - - KeyBinding.setKeyPressed(((KeyBindingAccessor) op.attackKey).getBoundKey(), L > 0); - for (int i = 0; i < L; i++) - KeyBinding.onKeyPressed(((KeyBindingAccessor) op.attackKey).getBoundKey()); - - KeyBinding.setKeyPressed(((KeyBindingAccessor) op.useKey).getBoundKey(), R > 0); - for (int i = 0; i < R; i++) - KeyBinding.onKeyPressed(((KeyBindingAccessor) op.useKey).getBoundKey()); - - return true; - } - - public boolean isF3Enabled() { - return MinecraftClient.getInstance().debugHudEntryList.isF3Enabled(); - } - - public void sendPacket(MPKPacket packet) { - ClientPlayNetworking.send(new DataCustomPayload(packet.getData())); - } - - public List getPressedButtons() { - return new ArrayList<>(pressedButtons); - } - - public void startSection(String name) { - Profilers.get().push(name); - } - - public void endStartSection(String name) { - Profilers.get().swap(name); - } - - public void endSection() { - Profilers.get().pop(); - } - - private record PointsRenderState( - Collection points, - int r, int g, int b, int a, - ScreenRect bounds, - ScreenRect scissor - ) implements SimpleGuiElementRenderState { - - @Override - public @Nullable ScreenRect bounds() { - return this.bounds; - } - - @Override - public void setupVertices(VertexConsumer consumer) { - for (Vector2D p : this.points) { - consumer.vertex((float) p.getX(), (float) p.getY(), 0).color(r, g, b, a); - } - } - - @Override - public RenderPipeline pipeline() { - return RenderPipelines.GUI; - } - - @Override - public TextureSetup textureSetup() { - return TextureSetup.empty(); - } - - @Override - public @Nullable ScreenRect scissorArea() { - return this.scissor; - } - } -} diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/GameRendererMixin.java b/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/GameRendererMixin.java deleted file mode 100644 index 151b0dd2..00000000 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/GameRendererMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.mixin; - -import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.MPKMod; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.WorldRenderer; -import net.minecraft.client.render.command.OrderedRenderCommandQueueImpl; -import net.minecraft.client.render.state.WorldRenderState; -import net.minecraft.client.util.math.MatrixStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = WorldRenderer.class) -public class GameRendererMixin { - @Inject(method = "renderBlockEntities", at = @At("HEAD")) - public void render(MatrixStack matrices, WorldRenderState renderState, OrderedRenderCommandQueueImpl orderedRenderCommandQueueImpl, CallbackInfo ci) { - MPKMod.INSTANCE.eventHandler.onRenderWorldOverlay( - new MatrixStack(), - MinecraftClient.getInstance().getRenderTickCounter().getTickProgress(true) - ); - } -} diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/KeyBindingAccessor.java b/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/KeyBindingAccessor.java deleted file mode 100644 index 4076bc74..00000000 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/KeyBindingAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.mixin; - -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(KeyBinding.class) -public interface KeyBindingAccessor { - @Accessor - InputUtil.Key getBoundKey(); -} diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/KeyboardMixin.java b/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/KeyboardMixin.java deleted file mode 100644 index 1375fc3a..00000000 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/mixin/KeyboardMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.mixin; - -import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.MPKMod; -import net.minecraft.client.Keyboard; -import net.minecraft.client.input.KeyInput; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(Keyboard.class) -public class KeyboardMixin { - @Inject(method = "onKey", at = @At(value = "RETURN")) - private void onKey(long window, int action, KeyInput keyInput, CallbackInfo ci) { - if (keyInput.key() != -1) { - MPKMod.INSTANCE.eventHandler.onKey(keyInput, action); - } - } -} diff --git a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/network/DataCustomPayload.java b/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/network/DataCustomPayload.java deleted file mode 100644 index 97c954b6..00000000 --- a/fabric-1.21.9/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21_9/network/DataCustomPayload.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_9.network; - -import io.github.kurrycat.mpknetapi.common.MPKNetworking; -import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.packet.CustomPayload; -import net.minecraft.util.Identifier; - -public record DataCustomPayload(byte[] data) implements CustomPayload { - public static final Id MPK_ID = new Id<>(Identifier.of(MPKNetworking.CHANNEL_NAMESPACE, MPKNetworking.CHANNEL_PATH)); - - public static final PacketCodec CODEC = PacketCodec.of( - (payload, buf) -> buf.writeBytes(payload.data()), - buf -> { - byte[] data = new byte[buf.readableBytes()]; - buf.readBytes(data); - return new DataCustomPayload(data); - } - ); - - @Override - public Id getId() { - return MPK_ID; - } - - public static Id registerClientboundPayload() { - PayloadTypeRegistry.playS2C().register(MPK_ID, DataCustomPayload.CODEC); - return MPK_ID; - } - - public static Id registerServerboundPayload() { - PayloadTypeRegistry.playC2S().register(MPK_ID, DataCustomPayload.CODEC); - return MPK_ID; - } -} \ No newline at end of file diff --git a/fabric-1.21.9/src/main/resources/assets/mpkmod/icon.png b/fabric-1.21.9/src/main/resources/assets/mpkmod/icon.png deleted file mode 100644 index 48bcd55b..00000000 Binary files a/fabric-1.21.9/src/main/resources/assets/mpkmod/icon.png and /dev/null differ diff --git a/fabric-1.21.9/src/main/resources/assets/mpkmod/lang/pl_pl.json b/fabric-1.21.9/src/main/resources/assets/mpkmod/lang/pl_pl.json deleted file mode 100644 index 886d7746..00000000 --- a/fabric-1.21.9/src/main/resources/assets/mpkmod/lang/pl_pl.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "mpkmod.key.main_gui.desc": "Otwórz menu MPK", - "mpkmod.key.lb_gui.desc": "Otwórz menu Bloku Lądowania", - "mpkmod.key.lb_set.desc": "Ustaw Blok Lądowania", - "mpkmod.key.options_gui.desc": "Otwórz menu opcji", - "mpkmod.main_gui.title": "Menu MPK", - "mpkmod.lb_gui.title": "Menu Bloku Lądowania" -} \ No newline at end of file diff --git a/forge-1.12.2/build.gradle b/forge-1.12.2/build.gradle index 77e8def1..4e19568f 100644 --- a/forge-1.12.2/build.gradle +++ b/forge-1.12.2/build.gradle @@ -1,7 +1,7 @@ plugins { - id 'xyz.wagyourtail.unimined' version '1.2.6' + id 'xyz.wagyourtail.unimined' version '1.4.1' - id "me.modmuss50.mod-publish-plugin" version "0.8.4" + id "me.modmuss50.mod-publish-plugin" version "1.1.0" } unimined.useGlobalCache = false diff --git a/forge-1.12.2/src/main/resources/mcmod.info b/forge-1.12.2/src/main/resources/mcmod.info index ad9ca163..f74306ba 100644 --- a/forge-1.12.2/src/main/resources/mcmod.info +++ b/forge-1.12.2/src/main/resources/mcmod.info @@ -5,7 +5,7 @@ "description": "A Mod that adds some pk features to the game", "version": "${version}", "mcversion": "", - "url": "https://github.com/kurrycat2004/MpkMod_2", + "url": "https://github.com/MPKMod/MPKMod2", "updateUrl": "", "authorList": ["kurrycat", "Exterminate", "Zpiboo", "Contributors"], "credits": "", diff --git a/forge-1.8.9/build.gradle b/forge-1.8.9/build.gradle index c27899dc..03204c49 100644 --- a/forge-1.8.9/build.gradle +++ b/forge-1.8.9/build.gradle @@ -1,7 +1,7 @@ plugins { - id 'xyz.wagyourtail.unimined' version '1.2.6' + id 'xyz.wagyourtail.unimined' version '1.4.1' - id "me.modmuss50.mod-publish-plugin" version "0.8.4" + id "me.modmuss50.mod-publish-plugin" version "1.1.0" } unimined.useGlobalCache = false diff --git a/forge-1.8.9/src/main/resources/mcmod.info b/forge-1.8.9/src/main/resources/mcmod.info index ad9ca163..f74306ba 100644 --- a/forge-1.8.9/src/main/resources/mcmod.info +++ b/forge-1.8.9/src/main/resources/mcmod.info @@ -5,7 +5,7 @@ "description": "A Mod that adds some pk features to the game", "version": "${version}", "mcversion": "", - "url": "https://github.com/kurrycat2004/MpkMod_2", + "url": "https://github.com/MPKMod/MPKMod2", "updateUrl": "", "authorList": ["kurrycat", "Exterminate", "Zpiboo", "Contributors"], "credits": "", diff --git a/gradle.properties b/gradle.properties index 9c3761f4..9b43c3b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ $group=io.github.kurrycat.mpkmod -$jitpackGroup=com.github.kurrycat2004 -$version=2.2.0 +$jitpackGroup=com.github.mpkmod +$version=2.3.0 $apiVersion=1.0 $modBaseName=mpkmod $commonBaseName=mpkmod-common -$vendor=kurrycat +$vendor=mpkmod networkApiVersion=1.0.1 -org.gradle.jvmargs=-Xmx4096m \ No newline at end of file +org.gradle.jvmargs=-Xmx4096m diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 42f0071e..d205b54b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle.kts b/settings.gradle.kts index 7891e6d1..1806e58d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,5 +26,5 @@ include("common") if (System.getenv("JITPACK") == null) { include("forge-1.8.9") include("forge-1.12.2") - include("fabric-1.21.9") + include("fabric-1.21.11") } \ No newline at end of file