forked from ldtteam/minecolonies
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to render borders of colonies on Dynmap using a new marker set "Colonies". Renders the colony name, owner and population count on the description of the colony. Automatically updates Dynmap when the following occur: The colony name gets changed The colony it's team color is changed The colony borders change when a building is constructured/repaired/removed The colony it's population count changes, either when colonists are born or die. What is not added in the pull request: Ability for Minecolonies specific blocks (primarly hut blocks) to render on Dynmap Ability for DO blocks to render on Dynmap (this would have to be implemented from within DO, should not appear here)
- Loading branch information
Showing
21 changed files
with
855 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/api/java/com/minecolonies/api/compatibility/dynmap/ColonyChunkClaimCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.minecolonies.api.compatibility.dynmap; | ||
|
||
import com.minecolonies.api.IMinecoloniesAPI; | ||
import com.minecolonies.api.colony.IColony; | ||
import com.minecolonies.api.colony.buildings.IBuilding; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.util.Tuple; | ||
import net.minecraft.world.level.ChunkPos; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Utility class responsible for calculating all claims that are claimed by a colony. | ||
*/ | ||
public class ColonyChunkClaimCalculator | ||
{ | ||
private ColonyChunkClaimCalculator() {} | ||
|
||
/** | ||
* Fetches a collection of {@link ChunkPos}'s depending on what chunks a colony has claimed. | ||
* | ||
* @param colony The colony to calculate the claimed chunks for. | ||
* @return A collection of claimed chunks. | ||
*/ | ||
public static Collection<ChunkPos> getAllClaimedChunks(final IColony colony) | ||
{ | ||
HashSet<ChunkPos> claimedChunks = new HashSet<>(); | ||
|
||
// Claim the protection area | ||
getProtectionArea(colony, claimedChunks); | ||
|
||
// Claim all the buildings | ||
colony.getBuildingManager().getBuildings().values().forEach(f -> claimBuilding(f, claimedChunks)); | ||
|
||
return claimedChunks; | ||
} | ||
|
||
/** | ||
* Calculate the claimed chunks regarding the protection area (the initial claim size after creating the colony) | ||
* | ||
* @param colony The colony to calculate the protection area for. | ||
* @param claimedChunks The internal set to add the chunks to. | ||
*/ | ||
private static void getProtectionArea(final IColony colony, Set<ChunkPos> claimedChunks) | ||
{ | ||
ChunkPos protectionAreaCenterChunk = new ChunkPos(colony.getCenter()); | ||
Integer protectionAreaRadius = IMinecoloniesAPI.getInstance().getConfig().getServer().initialColonySize.get(); | ||
for (int i = -protectionAreaRadius; i <= protectionAreaRadius; i++) | ||
{ | ||
for (int j = -protectionAreaRadius; j <= protectionAreaRadius; j++) | ||
{ | ||
claimedChunks.add(new ChunkPos(protectionAreaCenterChunk.x + i, protectionAreaCenterChunk.z + j)); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Calculate the claimed chunks regarding all buildings in the colony. | ||
* | ||
* @param building Which building in the colony to check for. | ||
* @param claimedChunks The internal set to add the chunks to. | ||
*/ | ||
private static void claimBuilding(final IBuilding building, Set<ChunkPos> claimedChunks) | ||
{ | ||
// Add the building center to the claimed chunks | ||
ChunkPos buildingCenterChunk = new ChunkPos(building.getPosition()); | ||
claimedChunks.add(buildingCenterChunk); | ||
|
||
// Add the overlaying schematic to the claimed chunks | ||
Tuple<BlockPos, BlockPos> corners = building.getCorners(); | ||
ChunkPos bottomLeft = new ChunkPos(corners.getA()); | ||
ChunkPos topRight = new ChunkPos(corners.getB()); | ||
if (!bottomLeft.equals(topRight)) | ||
{ | ||
// Chunks do not appear on the same XZ coordinate, so this means the building uses multiple chunks | ||
int chunksHorizontal = ((topRight.getMinBlockX() - bottomLeft.getMinBlockX()) / 16) + 1; | ||
int chunksVertical = ((topRight.getMinBlockZ() - bottomLeft.getMinBlockZ()) / 16) + 1; | ||
for (int i = 0; i < chunksHorizontal; i++) | ||
{ | ||
for (int j = 0; j < chunksVertical; j++) | ||
{ | ||
claimedChunks.add(new ChunkPos(bottomLeft.x + i, bottomLeft.z + j)); | ||
} | ||
} | ||
} | ||
|
||
// Add the claim radius to the claimed chunks | ||
int radius = building.getClaimRadius(building.getBuildingLevel()); | ||
for (int i = -radius; i <= radius; i++) | ||
{ | ||
for (int j = -radius; j <= radius; j++) | ||
{ | ||
claimedChunks.add(new ChunkPos(buildingCenterChunk.x + i, buildingCenterChunk.z + j)); | ||
} | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/api/java/com/minecolonies/api/compatibility/dynmap/DynmapApiListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.minecolonies.api.compatibility.dynmap; | ||
|
||
import com.minecolonies.api.util.Log; | ||
import org.dynmap.DynmapCommonAPI; | ||
import org.dynmap.DynmapCommonAPIListener; | ||
import org.dynmap.markers.MarkerAPI; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Dynmap integration class to connect Minecolonies to Dynmap it's API listening system. | ||
* This way Dynmap can invoke {@link DynmapApiListener#apiEnabled} in order to | ||
* start generating markers. | ||
*/ | ||
public class DynmapApiListener extends DynmapCommonAPIListener | ||
{ | ||
private final Consumer<DynmapIntegration> integrationConsumer; | ||
|
||
/** | ||
* Constructor containing a consumer callback which is invoked whenever Dynmap is ready | ||
* to start creating markers. | ||
* | ||
* @param integrationConsumer The consumer instance. | ||
*/ | ||
public DynmapApiListener(Consumer<DynmapIntegration> integrationConsumer) | ||
{ | ||
this.integrationConsumer = integrationConsumer; | ||
} | ||
|
||
public void registerListener() | ||
{ | ||
DynmapCommonAPIListener.register(this); | ||
} | ||
|
||
@Override | ||
public void apiEnabled(final DynmapCommonAPI dynmapCommonAPI) | ||
{ | ||
Log.getLogger().info("Dynmap API enabled, registering markers..."); | ||
MarkerAPI markerApi = dynmapCommonAPI.getMarkerAPI(); | ||
|
||
integrationConsumer.accept(new DynmapIntegration(markerApi)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/api/java/com/minecolonies/api/compatibility/dynmap/DynmapCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.minecolonies.api.compatibility.dynmap; | ||
|
||
/** | ||
* Compat class for when Dynmap is detected and the integration should be enabled. | ||
*/ | ||
public class DynmapCompat extends DynmapProxy | ||
{ | ||
@Override | ||
public boolean isDynmapPresent() | ||
{ | ||
return true; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/api/java/com/minecolonies/api/compatibility/dynmap/DynmapConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.minecolonies.api.compatibility.dynmap; | ||
|
||
/** | ||
* A small set of constant declarations that the Dynmap plugin uses to handle content towards Dynmap it's map system. | ||
*/ | ||
public final class DynmapConstants | ||
{ | ||
public static final String DYNMAP_COLONY_MARKER_SET_ID = "minecolonies:colony_markers"; | ||
public static final String DYNMAP_COLONY_MARKER_SET_NAME = "Colonies"; | ||
public static final String DYNMAP_COLONY_MARKER_FORMAT = "minecolonies:colony:%d"; | ||
public static final String DYNMAP_COLONY_DESCRIPTION_FORMAT = "<h2>%s</h2><p>Mayor: %s</p><p>Population: %d</p>"; | ||
|
||
private DynmapConstants() {} | ||
} |
Oops, something went wrong.