From 0c258f8680ab5fd3d434d230c058ac8b58676eb5 Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Sat, 10 May 2025 14:01:24 +0200 Subject: [PATCH] mod skeleton 1 this commit adds some skeleton using fabric-api for later implementation: - renderer - hypixel mod api - timer --- build.gradle | 10 ++--- .../zombiesutils/ZombiesUtilsClient.java | 17 ++++++++- .../xyz/stachel/zombiesutils/game/Timer.java | 38 +++++++++++++++++++ .../zombiesutils/handlers/Renderer.java | 29 ++++++++++++++ src/main/resources/fabric.mod.json | 3 +- 5 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 src/client/java/xyz/stachel/zombiesutils/game/Timer.java create mode 100644 src/client/java/xyz/stachel/zombiesutils/handlers/Renderer.java diff --git a/build.gradle b/build.gradle index 0b3665d..df8e22b 100644 --- a/build.gradle +++ b/build.gradle @@ -11,11 +11,7 @@ base { } repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. + maven { url 'https://repo.hypixel.net/repository/Hypixel/' } } loom { @@ -38,7 +34,7 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - + modImplementation 'net.hypixel:mod-api:1.0.1' } processResources { @@ -87,4 +83,4 @@ publishing { // The repositories here will be used for publishing your artifact, not for // retrieving dependencies. } -} \ No newline at end of file +} diff --git a/src/client/java/xyz/stachel/zombiesutils/ZombiesUtilsClient.java b/src/client/java/xyz/stachel/zombiesutils/ZombiesUtilsClient.java index f010da6..c17f259 100644 --- a/src/client/java/xyz/stachel/zombiesutils/ZombiesUtilsClient.java +++ b/src/client/java/xyz/stachel/zombiesutils/ZombiesUtilsClient.java @@ -1,11 +1,24 @@ package xyz.stachel.zombiesutils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.rendering.v1.HudLayerRegistrationCallback; +import net.hypixel.modapi.HypixelModAPI; +import net.hypixel.modapi.packet.impl.clientbound.event.ClientboundLocationPacket; +import xyz.stachel.zombiesutils.handlers.Renderer; public class ZombiesUtilsClient implements ClientModInitializer { + public static final String MOD_ID = "zombies-utils"; + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + @Override public void onInitializeClient() { - // This entrypoint is suitable for setting up client-specific logic, such as rendering. - System.out.println("Hello, Zombies!"); + HypixelModAPI.getInstance().subscribeToEventPacket(ClientboundLocationPacket.class); + //TODO: HypixelModAPI.getInstance().createHandler(ClientboundLocationPacket.class, todo); + LOGGER.info("initializing..."); + HudLayerRegistrationCallback.EVENT.register(new Renderer()); } + } diff --git a/src/client/java/xyz/stachel/zombiesutils/game/Timer.java b/src/client/java/xyz/stachel/zombiesutils/game/Timer.java new file mode 100644 index 0000000..9f0da8e --- /dev/null +++ b/src/client/java/xyz/stachel/zombiesutils/game/Timer.java @@ -0,0 +1,38 @@ +package xyz.stachel.zombiesutils.game; + +import net.minecraft.client.MinecraftClient; +import xyz.stachel.zombiesutils.ZombiesUtilsClient; + +class Timer { + // world-absolute tick the game started on + private long startTick; + // amount of ticks elapsed between startTick and last split + private long roundStart; + + public Timer() { + this.startTick = worldTick(); + } + + public long roundTime() { + return gameTime() - roundStart; + } + + public long gameTime() { + return worldTick() - startTick; + } + + public long split() { + final long rt = roundTime(); + this.roundStart = gameTime(); + return rt; + } + + private long worldTick() { + MinecraftClient mc = MinecraftClient.getInstance(); + if (mc == null || mc.world == null) { + ZombiesUtilsClient.LOGGER.warn("Timer is running, but the player is not in game."); + return 0; + } + return mc.world.getTime(); + } +} diff --git a/src/client/java/xyz/stachel/zombiesutils/handlers/Renderer.java b/src/client/java/xyz/stachel/zombiesutils/handlers/Renderer.java new file mode 100644 index 0000000..437f5ed --- /dev/null +++ b/src/client/java/xyz/stachel/zombiesutils/handlers/Renderer.java @@ -0,0 +1,29 @@ +package xyz.stachel.zombiesutils.handlers; + +import net.fabricmc.fabric.api.client.rendering.v1.HudLayerRegistrationCallback; +import net.fabricmc.fabric.api.client.rendering.v1.IdentifiedLayer; +import net.fabricmc.fabric.api.client.rendering.v1.LayeredDrawerWrapper; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.render.RenderTickCounter; +import net.minecraft.util.Identifier; + +public class Renderer implements HudLayerRegistrationCallback { + + @Override + public void register(LayeredDrawerWrapper layeredDrawer) { + layeredDrawer.attachLayerAfter(IdentifiedLayer.OVERLAY_MESSAGE, new ZombiesUtilsLayer()); + } + + class ZombiesUtilsLayer implements IdentifiedLayer { + + @Override + public void render(DrawContext context, RenderTickCounter tickCounter) { + // TODO Auto-generated method stub + } + + @Override + public Identifier id() { + return Identifier.of("zombies-utils", "main"); + } + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4616b9e..88e23be 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,8 @@ "fabricloader": ">=0.16.14", "minecraft": "~1.21.5", "java": ">=21", - "fabric-api": "*" + "fabric-api": "*", + "hypixel-mod-api": ">=1.0.1" }, "suggests": {} }