Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.21.1' into 1.21.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/me/senseiwells/chunkdebug/client/gui/ChunkDebugScreen.java
  • Loading branch information
senseiwells committed Oct 24, 2024
2 parents 934c4bf + 8bba22b commit b5903cf
Show file tree
Hide file tree
Showing 6 changed files with 592 additions and 283 deletions.
24 changes: 20 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {
java
}

val modVersion = "2.1.0"
val releaseVersion = "${modVersion}+mc${libs.versions.minecraft.get()}"
val modVersion = "2.1.1"
val releaseVersion = "${modVersion}+${libs.versions.minecraft.get()}"
version = releaseVersion
group = "me.senseiwells"

Expand All @@ -26,8 +26,6 @@ dependencies {
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)

runtimeOnly(libs.luckperms)

includeModImplementation(libs.permissions) {
exclude(libs.fabric.api.get().group)
}
Expand Down Expand Up @@ -103,6 +101,24 @@ tasks {
publications {
create<MavenPublication>("mavenJava") {
from(project.components.getByName("java"))
artifactId = "chunk-debug"
}
}

repositories {
val mavenUrl = System.getenv("MAVEN_URL")
if (mavenUrl != null) {
maven {
url = uri(mavenUrl)
val mavenUsername = System.getenv("MAVEN_USERNAME")
val mavenPassword = System.getenv("MAVEN_PASSWORD")
if (mavenUsername != null && mavenPassword != null) {
credentials {
username = mavenUsername
password = mavenPassword
}
}
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ fabric-api = "0.106.0+1.21.2"
permissions = "0.3.1"
mod-publish = "0.7.0"
parchment = "1.21:2024.07.28"
luckperms = "v5.4.140-fabric"

[libraries]
minecraft = { module = "com.mojang:minecraft" , version.ref = "minecraft" }
fabric-loader = { module = "net.fabricmc:fabric-loader" , version.ref = "fabric-loader" }
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" }
permissions = { module = "me.lucko:fabric-permissions-api" , version.ref = "permissions" }
luckperms = { module = "maven.modrinth:luckperms" , version.ref = "luckperms" }

[plugins]
mod-publish = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.senseiwells.chunkdebug.ChunkDebug;
import me.senseiwells.chunkdebug.client.config.ChunkDebugClientConfig;
import me.senseiwells.chunkdebug.client.gui.ChunkDebugMap;
import me.senseiwells.chunkdebug.client.gui.ChunkDebugScreen;
import me.senseiwells.chunkdebug.common.network.*;
import net.fabricmc.api.ClientModInitializer;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
Expand All @@ -31,11 +33,10 @@ public class ChunkDebugClient implements ClientModInitializer {
private static ChunkDebugClient instance;

public final KeyMapping keybind = new KeyMapping("chunk-debug.key", GLFW.GLFW_KEY_F6, "key.categories.misc");

private final ChunkDebugClientConfig config = ChunkDebugClientConfig.read();
public final ChunkDebugClientConfig config = ChunkDebugClientConfig.read();

@Nullable
private ChunkDebugScreen screen;
private ChunkDebugMap map;

public static ChunkDebugClient getInstance() {
return instance;
Expand All @@ -56,6 +57,14 @@ public void onInitializeClient() {
ClientPlayNetworking.registerGlobalReceiver(ChunkUnloadPayload.TYPE, this::handleChunkUnload);
}

@Nullable
public ChunkDebugScreen createChunkDebugScreen(@Nullable Screen parent) {
if (this.map == null) {
return null;
}
return new ChunkDebugScreen(this.map, parent);
}

public void startWatching(ResourceKey<Level> dimension) {
this.trySendPayload(() -> new StartWatchingPayload(List.of(dimension)));
}
Expand All @@ -66,41 +75,42 @@ public void stopWatching() {

@ApiStatus.Internal
public void onGuiRender(GuiGraphics graphics, @SuppressWarnings("unused") DeltaTracker tracker) {
if (this.screen != null) {
this.screen.renderMinimap(graphics);
if (this.map != null) {
this.map.renderMinimap(graphics);
}
}

@ApiStatus.Internal
public void onGuiResize(Minecraft minecraft, int width, int height) {
if (this.screen != null) {
this.screen.resize(minecraft, width, height);
public void onGuiResize(int width, int height) {
if (this.map != null) {
this.map.resize(width, height);
}
}

private void onClientTick(Minecraft minecraft) {
if (this.screen != null) {
this.screen.clientTick();
if (this.map != null) {
this.map.tick();
}
if (this.keybind.consumeClick() && minecraft.screen == null) {
if (this.screen != null) {
minecraft.setScreen(this.screen);
} else {
ChunkDebugScreen screen = this.createChunkDebugScreen(null);
if (screen == null) {
minecraft.gui.getChat().addMessage(
Component.translatable("chunk-debug.screen.unavailable").withStyle(ChatFormatting.RED)
);
} else {
minecraft.setScreen(screen);
}
}
}

private void onClientStopping(Minecraft minecraft) {
this.setScreen(null);
this.setChunkMap(null);
ChunkDebugClientConfig.write(this.config);
}

private void handleHello(HelloPayload payload, ClientPlayNetworking.Context context) {
if (payload.version() == ChunkDebug.PROTOCOL_VERSION) {
this.setScreen(new ChunkDebugScreen(this.config));
this.setChunkMap(new ChunkDebugMap(context.client(), this));
ChunkDebug.LOGGER.info("ChunkDebug connection successful");
} else if (payload.version() < ChunkDebug.PROTOCOL_VERSION) {
ChunkDebug.LOGGER.info("ChunkDebug failed to connect, server is out of date!");
Expand All @@ -111,21 +121,21 @@ private void handleHello(HelloPayload payload, ClientPlayNetworking.Context cont

private void handleBye(ByePayload payload, ClientPlayNetworking.Context context) {
Minecraft minecraft = context.client();
if (minecraft.screen == this.screen) {
minecraft.setScreen(null);
if (minecraft.screen instanceof ChunkDebugScreen screen) {
screen.onClose();
}
this.setScreen(null);
this.setChunkMap(null);
}

private void handleChunkData(ChunkDataPayload payload, ClientPlayNetworking.Context context) {
if (this.screen != null) {
this.screen.updateChunks(payload.dimension(), payload.chunks());
if (this.map != null) {
this.map.updateChunks(payload.dimension(), payload.chunks());
}
}

private void handleChunkUnload(ChunkUnloadPayload payload, ClientPlayNetworking.Context context) {
if (this.screen != null) {
this.screen.unloadChunks(payload.dimension(), payload.positions());
if (this.map != null) {
this.map.unloadChunks(payload.dimension(), payload.positions());
}
}

Expand All @@ -137,10 +147,10 @@ private void trySendPayload(Supplier<CustomPacketPayload> supplier) {
}
}

private void setScreen(@Nullable ChunkDebugScreen screen) {
if (this.screen != null) {
this.screen.shutdown();
private void setChunkMap(@Nullable ChunkDebugMap map) {
if (this.map != null) {
this.map.close();
}
this.screen = screen;
this.map = map;
}
}
Loading

0 comments on commit b5903cf

Please sign in to comment.