Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.20.2] Add BlueMap integration #3

Open
wants to merge 3 commits into
base: 1.20.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ build
# other
eclipse
run
runs
1 change: 1 addition & 0 deletions Common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
7 changes: 7 additions & 0 deletions Common/src/main/java/com/natamus/areas/ModCommon.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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");
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
}
5 changes: 5 additions & 0 deletions Common/src/main/java/com/natamus/areas/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions Fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions Forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
implementation fg.deobf("com.github.BlueMap-Minecraft:BlueMapAPI:v${bluemap_version}")
}

tasks.withType(Jar).configureEach {
Expand Down
1 change: 1 addition & 0 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ org.gradle.jvmargs=-Xmx6G
org.gradle.daemon=false

collective_version=7.15

# Mod dependencies
bluemap_version = 2.6.1