Skip to content
New issue

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

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

Already on GitHub? # to your account

Add Visual Prospecting/Journeymap Integration #9

Merged
merged 5 commits into from
Nov 14, 2023
Merged
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
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1697697256
//version: 1699290261
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -646,7 +646,7 @@ repositories {

def mixinProviderGroup = "io.github.legacymoddingmc"
def mixinProviderModule = "unimixins"
def mixinProviderVersion = "0.1.7.1"
def mixinProviderVersion = "0.1.13"
def mixinProviderSpecNoClassifer = "${mixinProviderGroup}:${mixinProviderModule}:${mixinProviderVersion}"
def mixinProviderSpec = "${mixinProviderSpecNoClassifer}:dev"
ext.mixinProviderSpec = mixinProviderSpec
Expand Down Expand Up @@ -1187,9 +1187,8 @@ publishing {
version = System.getenv("RELEASE_VERSION") ?: identifiedVersion
}
}

repositories {
if (usesMavenPublishing.toBoolean()) {
if (usesMavenPublishing.toBoolean() && System.getenv("MAVEN_USER") != null) {
maven {
url = mavenPublishUrl
allowInsecureProtocol = mavenPublishUrl.startsWith("http://") // Mostly for the GTNH maven
Expand Down
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
dependencies {

compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.3.81-GTNH:dev")
compileOnly("com.github.GTNewHorizons:VisualProspecting:1.2.0:dev")

runtimeOnlyNonPublishable("com.github.GTNewHorizons:waila:1.6.2:dev")
// runtimeOnlyNonPublishable("com.github.GTNewHorizons:VisualProspecting:1.2.0:dev")

shadowCompile("it.unimi.dsi:fastutil:8.5.12")
}
2 changes: 1 addition & 1 deletion src/main/java/serverutils/ServerUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
name = ServerUtilities.MOD_NAME,
version = ServerUtilities.VERSION,
acceptableRemoteVersions = "*",
dependencies = "")
dependencies = "after:visualprospecting;")
public class ServerUtilities {

public static final String MOD_ID = "serverutilities";
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/serverutils/ServerUtilitiesCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import serverutils.handlers.ServerUtilitiesServerEventHandler;
import serverutils.handlers.ServerUtilitiesWorldEventHandler;
import serverutils.lib.EnumReloadType;
import serverutils.lib.OtherMods;
import serverutils.lib.config.ConfigBoolean;
import serverutils.lib.config.ConfigColor;
import serverutils.lib.config.ConfigDouble;
Expand Down Expand Up @@ -90,6 +91,7 @@ public class ServerUtilitiesCommon {
public static final Map<ResourceLocation, TeamAction> TEAM_GUI_ACTIONS = new HashMap<>();
public static final Map<ResourceLocation, AdminPanelAction> ADMIN_PANEL_ACTIONS = new HashMap<>();
private static final Map<String, Function<ForgePlayer, IChatComponent>> CHAT_FORMATTING_SUBSTITUTES = new HashMap<>();
public static boolean isVPLoaded;

public static Function<String, IChatComponent> chatFormattingSubstituteFunction(ForgePlayer player) {
return s -> {
Expand All @@ -114,6 +116,8 @@ public void preInit(FMLPreInitializationEvent event) {
ServerUtilities.LOGGER.info("Loading ServerUtilities in development environment");
}

isVPLoaded = Loader.isModLoaded(OtherMods.VP);

ServerUtilitiesConfig.init(event);
AuroraConfig.init(event);

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/serverutils/ServerUtilitiesPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public class ServerUtilitiesPermissions {
public static final String AFK_TIMER = "serverutilities.afk.timer";
public static final String HEAL_OTHER = "serverutilities.other_player.heal";

public static final String CLAIMS_JOURNEYMAP = "serverutilities.journeymap.enable";
public static final String CLAIMS_JOURNEYMAP_OTHER = "serverutilities.journeymap.other";

@SubscribeEvent
public void registerRankConfigHandler(RegisterRankConfigHandlerEvent event) {
if (ServerUtilitiesConfig.ranks.enabled) {
Expand All @@ -128,7 +131,7 @@ public static void registerPermissions() {
PermissionAPI.registerNode(
CHAT_FORMATTING,
DefaultPermissionLevel.ALL,
"Allows to use **bold**, *italic* and ~~striketrough~~ in chat");
"Allows to use **bold**, *italic* and ~~strikethrough~~ in chat");
PermissionAPI.registerNode(CHAT_NICKNAME_SET, DefaultPermissionLevel.OP, "Allow to change nickname");
PermissionAPI.registerNode(
CHAT_NICKNAME_COLORS,
Expand Down Expand Up @@ -214,6 +217,14 @@ public static void registerPermissions() {
PermissionAPI
.registerNode(RTP_BACK, DefaultPermissionLevel.OP, "Allow player back to last time where /rtp is used");
PermissionAPI.registerNode(RESPAWN_BACK, DefaultPermissionLevel.ALL, "Allow player back to last death point");
PermissionAPI.registerNode(
CLAIMS_JOURNEYMAP,
DefaultPermissionLevel.ALL,
"Allow player to see own teams claims on JourneyMap overlay");
PermissionAPI.registerNode(
CLAIMS_JOURNEYMAP_OTHER,
DefaultPermissionLevel.ALL,
"Allow player to see other teams claims on JourneyMap overlay");

for (Block block : GameData.getBlockRegistry().typeSafeIterable()) {
String name = formatId(block);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/serverutils/client/ServerUtilitiesClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import serverutils.command.client.CommandPrintState;
import serverutils.command.client.CommandSimulateButton;
import serverutils.handlers.ServerUtilitiesClientEventHandler;
import serverutils.integration.vp.VPIntegration;
import serverutils.lib.client.ClientUtils;
import serverutils.lib.client.IncompatibleModException;
import serverutils.lib.client.ParticleColoredDust;
Expand Down Expand Up @@ -87,6 +88,10 @@ public void postInit(FMLPostInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new CommandPrintState());
ClientCommandHandler.instance.registerCommand(new CommandPing());

if (isVPLoaded && ServerUtilitiesClientConfig.general.journeymap_overlay) {
VPIntegration.init();
}

if (Loader.isModLoaded("FTBU") || Loader.isModLoaded("FTBL")) {
throw new IncompatibleModException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ public static boolean sync() {
general.show_shutdown_timer_ms = -1L;
// general.render_badges = config.get(Configuration.CATEGORY_GENERAL, "render_badges", false, "Render
// badges.").getBoolean();
// general.journeymap_overlay = config.get(
// Configuration.CATEGORY_GENERAL,
// "journeymap_overlay",
// false,
// "Enable JourneyMap overlay. Requires a restart to work.").getBoolean();
general.journeymap_overlay = config.get(
Configuration.CATEGORY_GENERAL,
"journeymap_overlay",
true,
"Enable JourneyMap overlay. Requires VisualProspecting installed. Changes will apply after restart.")
.getBoolean();
general.show_shutdown_timer = config
.get(
Configuration.CATEGORY_GENERAL,
Expand Down Expand Up @@ -111,7 +112,7 @@ public static boolean sync() {
public static class General {

// public boolean render_badges = false;
// public boolean journeymap_overlay;
public boolean journeymap_overlay;
public boolean show_shutdown_timer;
public String shutdown_timer_start;
private long show_shutdown_timer_ms = -1L;
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/serverutils/client/gui/ClientClaimedChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import serverutils.lib.EnumTeamColor;
import serverutils.lib.io.Bits;
import serverutils.lib.io.DataIn;
import serverutils.lib.io.DataOut;
import serverutils.lib.math.ChunkDimPos;

public class ClientClaimedChunks {

Expand All @@ -22,6 +25,8 @@ public static class Team {
data.writeTextComponent(team.nameComponent);
EnumTeamColor.NAME_MAP.write(data, team.color);
data.writeBoolean(team.isAlly);
data.writeBoolean(team.isMember);
data.writeMap(team.chunkPos, DataOut.CHUNK_DIM_POS, ChunkData.SERIALIZER);
data.writeMap(team.chunks, DataOut.INT, ChunkData.SERIALIZER);
};

Expand All @@ -30,7 +35,9 @@ public static class Team {
team.nameComponent = data.readTextComponent();
team.color = EnumTeamColor.NAME_MAP.read(data);
team.isAlly = data.readBoolean();
team.isMember = data.readBoolean();
currentTeam = team;
data.readMap(team.chunkPos, DataIn.CHUNK_DIM_POS, ChunkData.DESERIALIZER);
data.readMap(team.chunks, DataIn.INT, ChunkData.DESERIALIZER);
return team;
};
Expand All @@ -39,8 +46,9 @@ public static class Team {
public EnumTeamColor color;
public IChatComponent nameComponent;
public boolean isAlly;
public boolean isMember;
public final Int2ObjectMap<ChunkData> chunks = new Int2ObjectOpenHashMap<>();
public Object shapeProperties;
public final Object2ObjectMap<ChunkDimPos, ChunkData> chunkPos = new Object2ObjectOpenHashMap<>();

public Team(short id) {
uid = id;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/serverutils/data/ClaimedChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;

import serverutils.ServerUtilitiesCommon;
import serverutils.ServerUtilitiesConfig;
import serverutils.ServerUtilitiesNotifications;
import serverutils.ServerUtilitiesPermissions;
Expand All @@ -29,6 +30,7 @@
import serverutils.lib.math.ChunkDimPos;
import serverutils.lib.util.permission.PermissionAPI;
import serverutils.net.MessageClaimedChunksUpdate;
import serverutils.net.MessageJourneyMapRemove;

public class ClaimedChunks {

Expand Down Expand Up @@ -150,6 +152,14 @@ public void removeChunk(ChunkDimPos pos) {
prevChunk.setInvalid();
markDirty();
}
if (ServerUtilitiesCommon.isVPLoaded) {
for (EntityPlayerMP player : (List<EntityPlayerMP>) instance.universe.server
.getConfigurationManager().playerEntityList) {
if (PermissionAPI.hasPermission(player, ServerUtilitiesPermissions.CLAIMS_JOURNEYMAP)) {
new MessageJourneyMapRemove(pos).sendTo(player);
}
}
}
}

public void addChunk(ClaimedChunk chunk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import serverutils.ServerUtilities;
import serverutils.ServerUtilitiesCommon;
import serverutils.ServerUtilitiesConfig;
import serverutils.client.EnumSidebarButtonPlacement;
import serverutils.client.ServerUtilitiesClient;
Expand All @@ -51,6 +52,7 @@
import serverutils.client.gui.SidebarButtonManager;
import serverutils.events.chunks.UpdateClientDataEvent;
import serverutils.events.client.CustomClickEvent;
import serverutils.integration.vp.VPIntegration;
import serverutils.lib.OtherMods;
import serverutils.lib.client.ClientUtils;
import serverutils.lib.client.GlStateManager;
Expand Down Expand Up @@ -102,6 +104,9 @@ public static void setBadge(UUID id, String url) {
public void onClientDisconnected(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
BADGE_CACHE.clear();
shutdownTime = 0L;
if (ServerUtilitiesCommon.isVPLoaded) {
VPIntegration.CLAIMS.clear();
}
}

@SubscribeEvent
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/serverutils/integration/vp/VPButtonManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package serverutils.integration.vp;

import com.sinthoras.visualprospecting.integration.model.buttons.ButtonManager;

public class VPButtonManager extends ButtonManager {

public static final VPButtonManager INSTANCE = new VPButtonManager();

public VPButtonManager() {
super("serverutilities.vp.button", "team");
}
}
121 changes: 121 additions & 0 deletions src/main/java/serverutils/integration/vp/VPClaimsLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package serverutils.integration.vp;

import java.util.Collection;
import java.util.Collections;

import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.ChunkCoordIntPair;

import com.sinthoras.visualprospecting.Utils;
import com.sinthoras.visualprospecting.integration.model.locations.IWaypointAndLocationProvider;
import com.sinthoras.visualprospecting.integration.model.waypoints.Waypoint;

import serverutils.client.gui.ClientClaimedChunks;
import serverutils.lib.EnumTeamColor;
import serverutils.lib.math.ChunkDimPos;
import serverutils.net.MessageClaimedChunksModify;
import serverutils.net.MessageJourneyMapRequest;

public class VPClaimsLocation implements IWaypointAndLocationProvider {

private final int blockX;
private final int blockZ;
private final int dimensionId;
private final String teamName;
private final boolean loaded;
private final boolean ally;
private final boolean member;
private final EnumTeamColor color;

public VPClaimsLocation(ChunkDimPos chunk, ClientClaimedChunks.ChunkData data) {
blockX = Utils.coordChunkToBlock(chunk.posX);
blockZ = Utils.coordChunkToBlock(chunk.posZ);
dimensionId = chunk.dim;
teamName = data.team.nameComponent.getUnformattedText();
loaded = data.isLoaded();
color = data.team.color;
ally = data.team.isAlly;
member = data.team.isMember;
}

public double getBlockX() {
return blockX + 0.5;
}

public double getBlockZ() {
return blockZ + 0.5;
}

public int getDimensionId() {
return dimensionId;
}

public String getTeamName() {
return color.getEnumChatFormatting() + teamName;
}

public boolean isLoaded() {
return loaded;
}

public String loadedHint() {
return isLoaded() ? EnumChatFormatting.GREEN + "Loaded" : "";
}

public String teamHint() {
if (member) {
return EnumChatFormatting.DARK_AQUA + "Your Team";
} else if (ally) {
return EnumChatFormatting.YELLOW + "Ally";
} else {
return "";
}
}

public EnumTeamColor getTeamColor() {
return color;
}

public void toggleLoaded() {
// Double click loads/unloads the chunk
int selectionMode = isLoaded() ? MessageClaimedChunksModify.UNLOAD : MessageClaimedChunksModify.LOAD;
Collection<ChunkCoordIntPair> chunks = Collections
.singleton(new ChunkCoordIntPair(Utils.coordBlockToChunk(blockX), Utils.coordBlockToChunk(blockZ)));
new MessageClaimedChunksModify(
Utils.coordBlockToChunk(blockX),
Utils.coordBlockToChunk(blockZ),
selectionMode,
chunks).sendToServer();
new MessageJourneyMapRequest(blockX, blockX, blockZ, blockZ).sendToServer();
}

public void removeClaim() {
// Deplete/VP Action key unclaims the chunk
int selectionMode = MessageClaimedChunksModify.UNCLAIM;
Collection<ChunkCoordIntPair> chunks = Collections
.singleton(new ChunkCoordIntPair(Utils.coordBlockToChunk(blockX), Utils.coordBlockToChunk(blockZ)));
new MessageClaimedChunksModify(
Utils.coordBlockToChunk(blockX),
Utils.coordBlockToChunk(blockZ),
selectionMode,
chunks).sendToServer();
new MessageJourneyMapRequest(blockX, blockX, blockZ, blockZ).sendToServer();
}

@Override
public Waypoint toWaypoint() {
toggleLoaded();
return null;
}

@Override
public boolean isActiveAsWaypoint() {
return false;
}

@Override
public void onWaypointCleared() {}

@Override
public void onWaypointUpdated(Waypoint waypoint) {}
}
Loading