diff --git a/.gitignore b/.gitignore index 778a722..461017f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ build # other eclipse run +runs diff --git a/Common/build.gradle b/Common/build.gradle index 24a2262..4628a78 100644 --- a/Common/build.gradle +++ b/Common/build.gradle @@ -17,5 +17,6 @@ dependencies { //compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5' implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' + compileOnly "com.github.BlueMap-Minecraft:BlueMapAPI:v${bluemap_version}" compileOnly("com.natamus.collective-ml:collective-common:${minecraft_version}-${collective_version}") } \ No newline at end of file diff --git a/Common/src/main/java/com/natamus/areas/ModCommon.java b/Common/src/main/java/com/natamus/areas/ModCommon.java index 0e96f3d..2b032ce 100644 --- a/Common/src/main/java/com/natamus/areas/ModCommon.java +++ b/Common/src/main/java/com/natamus/areas/ModCommon.java @@ -1,8 +1,10 @@ package com.natamus.areas; import com.natamus.areas.config.ConfigHandler; +import com.natamus.areas.integrations.BlueMapIntegration; import com.natamus.areas.util.Reference; import com.natamus.collective.config.GenerateJSONFiles; +import de.bluecolored.bluemap.api.BlueMapAPI; public class ModCommon { @@ -13,5 +15,10 @@ public static void init() { private static void load() { GenerateJSONFiles.requestJSONFile(Reference.MOD_ID, "area_names.json"); + try { + BlueMapAPI.onEnable(BlueMapIntegration::updateBlueMap); + } catch (NoClassDefFoundError | IllegalStateException ignored) { + System.out.println("BlueMap is not loaded"); + } } } \ No newline at end of file diff --git a/Common/src/main/java/com/natamus/areas/integrations/BlueMapIntegration.java b/Common/src/main/java/com/natamus/areas/integrations/BlueMapIntegration.java new file mode 100644 index 0000000..1229def --- /dev/null +++ b/Common/src/main/java/com/natamus/areas/integrations/BlueMapIntegration.java @@ -0,0 +1,60 @@ +package com.natamus.areas.integrations; + +import com.natamus.areas.data.AreaVariables; +import de.bluecolored.bluemap.api.BlueMapAPI; +import de.bluecolored.bluemap.api.BlueMapMap; +import de.bluecolored.bluemap.api.markers.Marker; +import de.bluecolored.bluemap.api.markers.MarkerSet; +import de.bluecolored.bluemap.api.markers.ShapeMarker; +import de.bluecolored.bluemap.api.math.Color; +import de.bluecolored.bluemap.api.math.Shape; + +public class BlueMapIntegration { + public static void updateBlueMap() { + try { + BlueMapAPI.getInstance().ifPresent(BlueMapIntegration::updateBlueMap); + } catch (NoClassDefFoundError | IllegalStateException ignore) { + System.out.println("BlueMap not loaded"); + } + } + + public static void updateBlueMap(BlueMapAPI api) { + final String areasId = "serilum-areas"; + final String areasLabel = "Areas"; + + AreaVariables.areaObjects.forEach((level, areaHashMap) -> { + final String worldId = level.dimension().location().getPath(); + final BlueMapMap map = api.getMaps().stream().filter(map1 -> worldId.contains(map1.getId())).findFirst().orElse(null); + if (map == null) { + return; + } + + MarkerSet markerSet = MarkerSet.builder().label(areasLabel).build(); + markerSet.getMarkers().clear(); + map.getMarkerSets().put(areasId, markerSet); + + areaHashMap.forEach((blockPos, area) -> { + Color fillColor = new Color(255, 255, 255, 0.5F); + Color lineColor = new Color(0, 0, 0, 1.0F); + if (area.customRGB != null && !area.customRGB.isEmpty()) { + String[] splits = area.customRGB.split(","); + java.awt.Color newColor = new java.awt.Color(Integer.parseInt(splits[0]), Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); + fillColor = new Color(newColor.getRGB(), 0.5F); + lineColor = new Color(newColor.darker().getRGB()); + } + + final Marker areaMarker = ShapeMarker.builder() + .shape(Shape.createCircle(area.location.getX(), area.location.getZ(), area.radius, 20), level.getSeaLevel()) + .centerPosition() + .label(area.areaName) + .depthTestEnabled(false) + .fillColor(fillColor) + .lineColor(lineColor) + .build(); + + String markerId = "areas_" + worldId + "_" + area.areaName + "_" + blockPos.toShortString(); + markerSet.getMarkers().put(markerId, areaMarker); + }); + }); + } +} diff --git a/Common/src/main/java/com/natamus/areas/util/Util.java b/Common/src/main/java/com/natamus/areas/util/Util.java index c3d29f7..5c5c4dd 100644 --- a/Common/src/main/java/com/natamus/areas/util/Util.java +++ b/Common/src/main/java/com/natamus/areas/util/Util.java @@ -5,6 +5,7 @@ import com.natamus.areas.data.ClientConstants; import com.natamus.areas.data.GUIVariables; import com.natamus.areas.functions.ZoneFunctions; +import com.natamus.areas.integrations.BlueMapIntegration; import com.natamus.areas.objects.AreaObject; import com.natamus.collective.data.GlobalVariables; import com.natamus.collective.functions.HashMapFunctions; @@ -164,6 +165,8 @@ public static void updateAreaSign(Level level, BlockPos signPos, SignBlockEntity if (shouldUpdateSign) { TileEntityFunctions.updateTileEntity(level, signPos, signBlockEntity); } + + BlueMapIntegration.updateBlueMap(); } public static void enterArea(AreaObject areaObject, Player player) { @@ -210,6 +213,8 @@ public static void removedArea(AreaObject areaObject, Player player) { String message = "The area " + areaObject.areaName + " no longer exists."; areaChangeMessage(player, message, areaObject.customRGB); } + + BlueMapIntegration.updateBlueMap(); } public static boolean playerIsEditingASign() { diff --git a/Fabric/build.gradle b/Fabric/build.gradle index 7d36e83..e7b18ec 100644 --- a/Fabric/build.gradle +++ b/Fabric/build.gradle @@ -26,6 +26,7 @@ dependencies { modImplementation "com.natamus.collective-ml:collective-fabric:${minecraft_version}-${collective_version}" modCompileOnly "com.natamus.collective-ml:collective:${minecraft_version}-${collective_version}" + modImplementation "com.github.BlueMap-Minecraft:BlueMapAPI:v${bluemap_version}" } loom { diff --git a/Forge/build.gradle b/Forge/build.gradle index 51003a8..040e57c 100644 --- a/Forge/build.gradle +++ b/Forge/build.gradle @@ -90,6 +90,7 @@ dependencies { runtimeOnly fg.deobf("com.natamus.collective-ml:collective-forge:${minecraft_version}-${collective_version}") compileOnly fg.deobf("com.natamus.collective-ml:collective-forge:${minecraft_version}-${collective_version}") compileOnly fg.deobf("com.natamus.collective-ml:collective:${minecraft_version}-${collective_version}") + compileOnly fg.deobf("com.github.BlueMap-Minecraft:BlueMapAPI:v${bluemap_version}") } tasks.withType(Jar).configureEach { diff --git a/NeoForge/build.gradle b/NeoForge/build.gradle index 0222d99..7d57fec 100644 --- a/NeoForge/build.gradle +++ b/NeoForge/build.gradle @@ -54,6 +54,7 @@ dependencies { runtimeOnly "com.natamus.collective-ml:collective-neoforge:${minecraft_version}-${collective_version}" compileOnly "com.natamus.collective-ml:collective-neoforge:${minecraft_version}-${collective_version}" compileOnly "com.natamus.collective-ml:collective:${minecraft_version}-${collective_version}" + implementation "com.github.BlueMap-Minecraft:BlueMapAPI:v${bluemap_version}" } tasks.named('compileJava', JavaCompile).configure { diff --git a/build.gradle b/build.gradle index ed8d6eb..b397229 100644 --- a/build.gradle +++ b/build.gradle @@ -42,6 +42,11 @@ subprojects { name = "Serilum Maven" url = "https://github.com/Serilum/.maven/raw/maven/" } + + maven { + name = "JitPack" + url = "https://jitpack.io" + } } tasks.withType(JavaCompile).configureEach { diff --git a/gradle.properties b/gradle.properties index 4f5a652..cc91199 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,3 +25,6 @@ org.gradle.jvmargs=-Xmx6G org.gradle.daemon=false collective_version=7.15 + +# Mod dependencies +bluemap_version = 2.6.1