-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8138092
commit 4941a14
Showing
21 changed files
with
995 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
122 changes: 122 additions & 0 deletions
122
...-1.21/src/main/java/io/github/kurrycat/mpkmod/compatibility/fabric_1_21/EventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.