From 69ea5eb0302e69b252f8a9788ebd81e8ee5e9eba Mon Sep 17 00:00:00 2001 From: Plan3t Date: Tue, 17 Feb 2026 10:50:45 +0100 Subject: [PATCH] Remove faction-map Squaremap background integration --- .../client/FactionMapClientData.java | 19 +- .../client/gui/FactionMainScreen.java | 15 +- .../client/gui/FactionMapRenderer.java | 2 +- .../map/SquaremapTileBackgroundProvider.java | 166 ------------------ .../com/mcprotector/config/FactionConfig.java | 24 --- .../network/FactionClaimMapPacket.java | 21 +-- 6 files changed, 12 insertions(+), 235 deletions(-) delete mode 100644 src/main/java/com/mcprotector/client/map/SquaremapTileBackgroundProvider.java diff --git a/src/main/java/com/mcprotector/client/FactionMapClientData.java b/src/main/java/com/mcprotector/client/FactionMapClientData.java index 8b58a4f..0279f5c 100644 --- a/src/main/java/com/mcprotector/client/FactionMapClientData.java +++ b/src/main/java/com/mcprotector/client/FactionMapClientData.java @@ -10,8 +10,6 @@ public final class FactionMapClientData { private static MapSnapshot snapshot = MapSnapshot.empty(); - private static boolean backgroundEnabledPreference = true; - private static int zoomPreference = Integer.MIN_VALUE; private FactionMapClientData() { } @@ -39,18 +37,11 @@ public static void requestUpdate() { public static void cycleBackgroundMode() { MapBackgroundState state = snapshot.backgroundState(); boolean enabled = !(state != null && state.enabled()); - backgroundEnabledPreference = enabled; snapshot = snapshot.withBackgroundState(state.withEnabled(enabled)); } public static void adjustZoom(int delta) { - MapBackgroundState state = snapshot.backgroundState(); - if (state == null || state.providerType() == MapBackgroundProviderType.NONE) { - return; - } - int zoom = Math.max(state.minZoom(), Math.min(state.maxZoom(), state.zoom() + delta)); - zoomPreference = zoom; - snapshot = snapshot.withBackgroundState(state.withZoom(zoom)); + // Background zoom controls were removed. } public record MapSnapshot(int centerChunkX, int centerChunkZ, int radius, @@ -59,6 +50,10 @@ public record MapSnapshot(int centerChunkX, int centerChunkZ, int radius, public static MapSnapshot empty() { return new MapSnapshot(0, 0, 0, new HashMap<>(), MapBackgroundState.none()); } + + public MapSnapshot withBackgroundState(MapBackgroundState newBackgroundState) { + return new MapSnapshot(centerChunkX, centerChunkZ, radius, claims, newBackgroundState); + } } public enum MapBackgroundProviderType { @@ -77,5 +72,9 @@ public static MapBackgroundState auto() { ? new MapBackgroundState(MapBackgroundProviderType.XAERO, true) : none(); } + + public MapBackgroundState withEnabled(boolean value) { + return new MapBackgroundState(providerType, value); + } } } diff --git a/src/main/java/com/mcprotector/client/gui/FactionMainScreen.java b/src/main/java/com/mcprotector/client/gui/FactionMainScreen.java index 147dc09..9c67cf5 100644 --- a/src/main/java/com/mcprotector/client/gui/FactionMainScreen.java +++ b/src/main/java/com/mcprotector/client/gui/FactionMainScreen.java @@ -81,9 +81,6 @@ public class FactionMainScreen extends Screen { private EditBox safeZoneFactionField; private Button claimTypeButton; private Button submitClaimsButton; - private Button mapBackgroundButton; - private Button mapZoomOutButton; - private Button mapZoomInButton; private int roleIndex; private int permissionIndex; private int memberRoleIndex; @@ -852,7 +849,6 @@ private void updateClaimTypeOptions(FactionClientData.FactionSnapshot snapshot) selectedClaimType = options.get(0); } updateClaimTypeButtonLabel(snapshot); - updateMapBackgroundControls(); } private void updateClaimTypeButtonLabel() { @@ -1162,7 +1158,6 @@ private void renderFactionMap(GuiGraphics guiGraphics, FactionClientData.Faction FactionMapRenderer.renderMapTooltip(guiGraphics, mapSnapshot, hovered, mouseX, mouseY, this.font); } renderMapLegend(guiGraphics, region); - renderMapBackgroundStatus(guiGraphics, region, mapSnapshot.backgroundState()); mapClaimsScrollOffset = renderMapClaimsList(guiGraphics, snapshot.claims(), region, mapClaimsScrollOffset); if (!selectedChunks.isEmpty()) { guiGraphics.drawString(this.font, "Selected " + selectedChunks.size() + " chunk(s)", @@ -1296,17 +1291,9 @@ private void updateMapControlLayout() { claimTypeButton.setY(controlsY); submitClaimsButton.setX(claimTypeButton.getX() + claimTypeWidth + claimGap); submitClaimsButton.setY(controlsY); - int backgroundControlsY = Math.max(panelTop + CONTROL_TOP_OFFSET, controlsY - 18); - int bgX = getPanelLeft(); - mapBackgroundButton.setX(bgX); - mapBackgroundButton.setY(backgroundControlsY); - mapZoomOutButton.setX(bgX + mapBackgroundButton.getWidth() + 4); - mapZoomOutButton.setY(backgroundControlsY); - mapZoomInButton.setX(bgX + mapBackgroundButton.getWidth() + 24); - mapZoomInButton.setY(backgroundControlsY); - updateMapBackgroundControls(); } + private enum ClaimType { FACTION("Faction"), PERSONAL("Personal"), diff --git a/src/main/java/com/mcprotector/client/gui/FactionMapRenderer.java b/src/main/java/com/mcprotector/client/gui/FactionMapRenderer.java index c83bc79..8a2481b 100644 --- a/src/main/java/com/mcprotector/client/gui/FactionMapRenderer.java +++ b/src/main/java/com/mcprotector/client/gui/FactionMapRenderer.java @@ -82,7 +82,7 @@ public static void renderMapGrid(GuiGraphics guiGraphics, FactionMapClientData.M int halfCell = Math.max(1, region.cellSize() / 2); guiGraphics.fill(x, y, x + halfCell, y + halfCell, 0x18FFFFFF); guiGraphics.fill(x + halfCell, y + halfCell, x + region.cellSize(), y + region.cellSize(), 0x18000000); - int gridColor = shadeColor(guiColor, 0.75f); + int gridColor = shadeColor(color, 0.75f); guiGraphics.renderOutline(x, y, region.cellSize(), region.cellSize(), gridColor); } } diff --git a/src/main/java/com/mcprotector/client/map/SquaremapTileBackgroundProvider.java b/src/main/java/com/mcprotector/client/map/SquaremapTileBackgroundProvider.java deleted file mode 100644 index 3566fef..0000000 --- a/src/main/java/com/mcprotector/client/map/SquaremapTileBackgroundProvider.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.mcprotector.client.map; - -import com.mcprotector.McProtectorMod; -import com.mcprotector.client.FactionMapClientData; -import com.mcprotector.client.gui.FactionMapRenderer; -import com.mojang.blaze3d.platform.NativeImage; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.resources.ResourceLocation; - -import java.io.ByteArrayInputStream; -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.time.Duration; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public final class SquaremapTileBackgroundProvider implements MapBackgroundProvider { - public static final SquaremapTileBackgroundProvider INSTANCE = new SquaremapTileBackgroundProvider(); - private static final int TILE_TEXTURE_SIZE = 256; - private static final int MAX_CACHED_TILES = 128; - private static final HttpClient HTTP = HttpClient.newBuilder() - .connectTimeout(Duration.ofSeconds(3)) - .followRedirects(HttpClient.Redirect.NORMAL) - .build(); - private static final ExecutorService FETCH_EXECUTOR = Executors.newSingleThreadExecutor(r -> { - Thread thread = new Thread(r, "mcprotector-squaremap-fetch"); - thread.setDaemon(true); - return thread; - }); - private static final Map CACHE = new LinkedHashMap<>(128, 0.75f, true); - private static final Set IN_FLIGHT = java.util.concurrent.ConcurrentHashMap.newKeySet(); - - private SquaremapTileBackgroundProvider() { - } - - @Override - public void renderBackground(GuiGraphics guiGraphics, - FactionMapClientData.MapSnapshot mapSnapshot, - FactionMapRenderer.MapRegion region) { - FactionMapClientData.MapBackgroundState state = mapSnapshot.backgroundState(); - if (state == null || !state.enabled() || !state.available()) { - return; - } - int minChunkX = mapSnapshot.centerChunkX() - region.radius(); - int minChunkZ = mapSnapshot.centerChunkZ() - region.radius(); - int maxChunkX = mapSnapshot.centerChunkX() + region.radius() + 1; - int maxChunkZ = mapSnapshot.centerChunkZ() + region.radius() + 1; - - int minBlockX = minChunkX * 16; - int minBlockZ = minChunkZ * 16; - int maxBlockX = maxChunkX * 16; - int maxBlockZ = maxChunkZ * 16; - - int tileSpan = tileSpanBlocks(state); - int minTileX = floorDiv(minBlockX, tileSpan); - int minTileY = floorDiv(minBlockZ, tileSpan); - int maxTileX = floorDiv(maxBlockX - 1, tileSpan); - int maxTileY = floorDiv(maxBlockZ - 1, tileSpan); - - for (int tileY = minTileY; tileY <= maxTileY; tileY++) { - for (int tileX = minTileX; tileX <= maxTileX; tileX++) { - TileKey key = new TileKey(state.worldName(), state.zoom(), tileX, tileY, state.tileUrlTemplate(), state.tileBlockSpan()); - TileTexture texture = getOrQueue(key); - if (texture == null || texture.resource() == null) { - continue; - } - int tileMinBlockX = tileX * tileSpan; - int tileMinBlockZ = tileY * tileSpan; - int tileMaxBlockX = tileMinBlockX + tileSpan; - int tileMaxBlockZ = tileMinBlockZ + tileSpan; - - int drawX = region.originX() + Math.round(((tileMinBlockX - minBlockX) / 16f) * region.cellSize()); - int drawY = region.originY() + Math.round(((tileMinBlockZ - minBlockZ) / 16f) * region.cellSize()); - int drawEndX = region.originX() + Math.round(((tileMaxBlockX - minBlockX) / 16f) * region.cellSize()); - int drawEndY = region.originY() + Math.round(((tileMaxBlockZ - minBlockZ) / 16f) * region.cellSize()); - int width = drawEndX - drawX; - int height = drawEndY - drawY; - if (width <= 0 || height <= 0) { - continue; - } - guiGraphics.blit(texture.resource(), drawX, drawY, 0, 0.0f, 0.0f, width, height, TILE_TEXTURE_SIZE, TILE_TEXTURE_SIZE); - } - } - } - - private static int tileSpanBlocks(FactionMapClientData.MapBackgroundState state) { - return state.tileBlockSpan() * (1 << state.zoom()); - } - - private static int floorDiv(int value, int divisor) { - int result = value / divisor; - if ((value ^ divisor) < 0 && value % divisor != 0) { - result--; - } - return result; - } - - private static TileTexture getOrQueue(TileKey key) { - synchronized (CACHE) { - TileTexture existing = CACHE.get(key); - if (existing != null) { - return existing; - } - } - if (IN_FLIGHT.add(key)) { - FETCH_EXECUTOR.submit(() -> fetchTile(key)); - } - return null; - } - - private static void fetchTile(TileKey key) { - try { - String url = key.template() - .replace("{world}", key.world()) - .replace("{z}", String.valueOf(key.zoom())) - .replace("{x}", String.valueOf(key.tileX())) - .replace("{y}", String.valueOf(key.tileY())); - HttpRequest request = HttpRequest.newBuilder(URI.create(url)) - .timeout(Duration.ofSeconds(4)) - .GET() - .build(); - HttpResponse response = HTTP.send(request, HttpResponse.BodyHandlers.ofByteArray()); - if (response.statusCode() < 200 || response.statusCode() >= 300) { - return; - } - byte[] body = response.body(); - Minecraft.getInstance().execute(() -> registerTexture(key, body)); - } catch (Exception error) { - McProtectorMod.LOGGER.debug("Squaremap tile fetch failed for {}: {}", key, error.getMessage()); - } finally { - IN_FLIGHT.remove(key); - } - } - - private static void registerTexture(TileKey key, byte[] imageBytes) { - try (NativeImage image = NativeImage.read(new ByteArrayInputStream(imageBytes))) { - DynamicTexture texture = new DynamicTexture(image); - ResourceLocation textureId = Minecraft.getInstance().getTextureManager().register( - "mcprotector/squaremap_" + key.zoom() + "_" + key.tileX() + "_" + key.tileY(), texture - ); - synchronized (CACHE) { - CACHE.put(key, new TileTexture(textureId)); - while (CACHE.size() > MAX_CACHED_TILES) { - Map.Entry first = CACHE.entrySet().iterator().next(); - Minecraft.getInstance().getTextureManager().release(first.getValue().resource()); - CACHE.remove(first.getKey()); - } - } - } catch (Exception error) { - McProtectorMod.LOGGER.debug("Failed to decode Squaremap tile {}: {}", key, error.getMessage()); - } - } - - private record TileKey(String world, int zoom, int tileX, int tileY, String template, int baseTileSpan) { - } - - private record TileTexture(ResourceLocation resource) { - } -} diff --git a/src/main/java/com/mcprotector/config/FactionConfig.java b/src/main/java/com/mcprotector/config/FactionConfig.java index fc00b11..a564a43 100644 --- a/src/main/java/com/mcprotector/config/FactionConfig.java +++ b/src/main/java/com/mcprotector/config/FactionConfig.java @@ -242,12 +242,6 @@ public static final class Server { public final ModConfigSpec.ConfigValue dynmapFullSyncOnStart; public final ModConfigSpec.ConfigValue claimMapRadiusChunks; public final ModConfigSpec.ConfigValue claimMapFullSync; - public final ModConfigSpec.ConfigValue squaremapUiBackgroundEnabled; - public final ModConfigSpec.ConfigValue squaremapUiTileUrlTemplate; - public final ModConfigSpec.ConfigValue squaremapUiMinZoom; - public final ModConfigSpec.ConfigValue squaremapUiMaxZoom; - public final ModConfigSpec.ConfigValue squaremapUiDefaultZoom; - public final ModConfigSpec.ConfigValue squaremapUiTileBlockSpan; public final ModConfigSpec.ConfigValue> safeZoneDimensions; public final ModConfigSpec.ConfigValue> warZoneDimensions; @@ -380,24 +374,6 @@ private Server(ModConfigSpec.Builder builder) { claimMapFullSync = builder .comment("Send all claims to clients instead of only the radius (for larger map views).") .define("claimMapFullSync", false); - squaremapUiBackgroundEnabled = builder - .comment("Enable Squaremap tile metadata for the in-game faction map background.") - .define("squaremapUiBackgroundEnabled", false); - squaremapUiTileUrlTemplate = builder - .comment("Tile URL template with placeholders {world}, {z}, {x}, {y}.") - .define("squaremapUiTileUrlTemplate", ""); - squaremapUiMinZoom = builder - .comment("Minimum zoom level for in-game Squaremap background tiles.") - .defineInRange("squaremapUiMinZoom", 0, 0, 8); - squaremapUiMaxZoom = builder - .comment("Maximum zoom level for in-game Squaremap background tiles.") - .defineInRange("squaremapUiMaxZoom", 4, 0, 12); - squaremapUiDefaultZoom = builder - .comment("Default zoom level for in-game Squaremap background tiles.") - .defineInRange("squaremapUiDefaultZoom", 2, 0, 12); - squaremapUiTileBlockSpan = builder - .comment("Block span represented by a tile at zoom 0 for in-game background rendering.") - .defineInRange("squaremapUiTileBlockSpan", 256, 16, 4096); safeZoneDimensions = builder .comment("Dimensions treated as safe zones (no PvP, no claim interactions).") .defineListAllowEmpty("safeZoneDimensions", List.of(), value -> value instanceof String); diff --git a/src/main/java/com/mcprotector/network/FactionClaimMapPacket.java b/src/main/java/com/mcprotector/network/FactionClaimMapPacket.java index 87bb5ec..7e9963f 100644 --- a/src/main/java/com/mcprotector/network/FactionClaimMapPacket.java +++ b/src/main/java/com/mcprotector/network/FactionClaimMapPacket.java @@ -5,7 +5,6 @@ import com.mcprotector.data.Faction; import com.mcprotector.data.FactionData; import com.mcprotector.data.FactionRelation; -import com.mcprotector.webmap.SquaremapBridge; import net.minecraft.ChatFormatting; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; @@ -179,25 +178,7 @@ public MapBackgroundMetadata background() { private static MapBackgroundMetadata resolveBackgroundMetadata(net.minecraft.server.level.ServerLevel level) { - if (!FactionConfig.SERVER.squaremapUiBackgroundEnabled.get()) { - return MapBackgroundMetadata.none(); - } - if (!SquaremapBridge.isAvailable()) { - return MapBackgroundMetadata.none(); - } - String template = FactionConfig.SERVER.squaremapUiTileUrlTemplate.get(); - if (template == null || template.isBlank()) { - return MapBackgroundMetadata.none(); - } - int minZoom = FactionConfig.SERVER.squaremapUiMinZoom.get(); - int maxZoom = FactionConfig.SERVER.squaremapUiMaxZoom.get(); - int defaultZoom = FactionConfig.SERVER.squaremapUiDefaultZoom.get(); - int tileBlockSpan = FactionConfig.SERVER.squaremapUiTileBlockSpan.get(); - int clampedMin = Math.max(0, Math.min(minZoom, maxZoom)); - int clampedMax = Math.max(clampedMin, maxZoom); - int clampedDefault = Math.max(clampedMin, Math.min(clampedMax, defaultZoom)); - String worldName = level.dimension().location().toString(); - return new MapBackgroundMetadata(true, "SQUAREMAP", template, worldName, clampedMin, clampedMax, clampedDefault, tileBlockSpan); + return MapBackgroundMetadata.none(); } private static String resolveName(net.minecraft.server.MinecraftServer server, UUID playerId) {