Skip to content

Commit

Permalink
add fabric 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
kurrycat2004 committed Jun 27, 2024
1 parent 8138092 commit 4941a14
Show file tree
Hide file tree
Showing 21 changed files with 995 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ If you think that mpkmod should have a specific feature, encounter any bugs or i
- 1.19.4
- 1.20.4
- 1.20.6
- 1.21

---

Expand Down
40 changes: 40 additions & 0 deletions fabric-1.21/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# gradle

.gradle/
build/
out/
classes/

# eclipse

*.launch

# idea

.idea/
*.iml
*.ipr
*.iws

# vscode

.settings/
.vscode/
bin/
.classpath
.project

# macos

*.DS_Store

# fabric

run/

# java

hs_err_*.log
replay_*.log
*.hprof
*.jfr
21 changes: 21 additions & 0 deletions fabric-1.21/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
}

loom.runs.client.runDir = "../runs/run"

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
14 changes: 14 additions & 0 deletions fabric-1.21/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21
yarn_mappings=1.21+build.4
loader_version=0.15.11

# Fabric API
fabric_version=0.100.4+1.21

jdkVersion=21
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package io.github.kurrycat.mpkmod.compatibility.fabric_1_21;


import io.github.kurrycat.mpkmod.compatibility.API;
import io.github.kurrycat.mpkmod.compatibility.MCClasses.Player;
import io.github.kurrycat.mpkmod.compatibility.fabric_1_21.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.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 key The GLFW key code. See {@link net.minecraft.client.util.InputUtil}.
* @param scanCode
* @param action The action, where 0 = unpressed, 1 = pressed, 2 = held.
*/
public void onKey(int key, int scanCode, int action) {
GameOptions options = MinecraftClient.getInstance().options;
long eventNanos = Util.getMeasuringTimeNano();

InputUtil.Key inputKey = InputUtil.fromKeyCode(key, scanCode);

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 (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(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().push();
API.<FunctionCompatibility>getFunctionHolder().drawContext = drawContext;
API.Events.onRenderOverlay();
drawContext.getMatrices().pop();
}

public void onRenderWorldOverlay(MatrixStack matrixStack, float tickDelta) {
MPKMod.INSTANCE.matrixStack = matrixStack;
matrixStack.push();
Vec3d pos = MinecraftClient.getInstance().gameRenderer.getCamera().getPos();
MPKMod.INSTANCE.matrixStack.translate(-pos.x, -pos.y, -pos.z);
API.Events.onRenderWorldOverlay(tickDelta);
matrixStack.pop();
}

public void onClientTickStart(MinecraftClient mc) {
API.Events.onTickStart();
}

public void onClientTickEnd(MinecraftClient mc) {
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.prevX, mcPlayer.prevY, mcPlayer.prevZ))
.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)
))
.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();
}
}
Loading

0 comments on commit 4941a14

Please sign in to comment.