Increased world value cache and changed map rendering.
This commit is contained in:
parent
df605880b7
commit
1b4fbd05f4
@ -27,12 +27,14 @@ import org.bukkit.map.MapView.Scale;
|
||||
import ca.recrown.islandsurvivalcraft.IslandSurvivalCraft;
|
||||
import ca.recrown.islandsurvivalcraft.interaction.items.VariationItemIdentifier;
|
||||
import ca.recrown.islandsurvivalcraft.interaction.items.VariedItem;
|
||||
import ca.recrown.islandsurvivalcraft.utilities.GeneralUtilities;
|
||||
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
|
||||
import ca.recrown.islandsurvivalcraft.world.WorldInfo;
|
||||
import ca.recrown.islandsurvivalcraft.world.Information.IslandInformation;
|
||||
import ca.recrown.islandsurvivalcraft.world.Information.IslandInformationManager;
|
||||
|
||||
public class IslandMapItem extends MapRenderer implements VariedItem {
|
||||
Color mainColor = new Color(0, 180, 0);
|
||||
private Material[] baseItems;
|
||||
private VariationItemIdentifier identifier;
|
||||
private IslandSurvivalCraft islandSurvivalCraft;
|
||||
@ -64,27 +66,22 @@ public class IslandMapItem extends MapRenderer implements VariedItem {
|
||||
WorldInfo worldInfo = islandSurvivalCraft.getWorldInfoManager().retrieve(map.getWorld().getName());
|
||||
IslandInformationManager islandInformationManager = worldInfo.getIslandInfoManager();
|
||||
int blocksPerPixel = (int) (1 * Math.pow(2, map.getScale().getValue()));
|
||||
for (int x = 0; x < 128; x ++) {
|
||||
for (int y = 0; y < 128; y ++) {
|
||||
for (int x = 0; x < 128; x += 1) {
|
||||
for (int y = x % 2; y < 128; y += 2) {
|
||||
if (canvas.getPixel(x, y) != MapPalette.matchColor(mainColor)) {
|
||||
int actualX = blocksPerPixel * (x - Byte.MAX_VALUE/2) + map.getCenterX();
|
||||
int actualZ = blocksPerPixel * (y - Byte.MAX_VALUE/2) + map.getCenterZ();
|
||||
Point2 pCoords = new Point2(actualX, actualZ);
|
||||
if (islandInformationManager.isChunkIslandInformationLoaded(GeneralUtilities.worldToChunkCoordinates(pCoords), false)) {
|
||||
IslandInformation info = islandInformationManager.getIslandInformation(pCoords, false);
|
||||
if (info != null) {
|
||||
byte baseColorVal = canvas.getBasePixel(x, y);
|
||||
Color mainColor = new Color(255, 120, 70);
|
||||
Color baseColor = null;
|
||||
if (baseColorVal != 0) {
|
||||
baseColor = MapPalette.getColor(baseColorVal);
|
||||
canvas.setPixel(x, y, MapPalette.matchColor(mainColor));
|
||||
} else {
|
||||
baseColor = new Color(1f, 1f, 1f);
|
||||
canvas.setPixel(x, y, canvas.getBasePixel(x, y));
|
||||
}
|
||||
} else if (worldInfo.getIslandMap().isIsland(actualX, actualZ)) {
|
||||
canvas.setPixel(x, y, MapPalette.matchColor(mainColor));
|
||||
}
|
||||
Color resultingColor = new Color(
|
||||
(mainColor.getRed() * baseColor.getRed())/(255f * 255f),
|
||||
(mainColor.getGreen() * baseColor.getGreen())/(255f * 255f),
|
||||
(mainColor.getBlue() * baseColor.getBlue())/(255f * 255f)
|
||||
);
|
||||
canvas.setPixel(x, y, MapPalette.matchColor(resultingColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,7 +112,7 @@ public class IslandMapItem extends MapRenderer implements VariedItem {
|
||||
if (item.getType() != Material.FILLED_MAP) return false;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(islandSurvivalCraft, () -> {
|
||||
initializeInstanceOfItem(item);
|
||||
});
|
||||
}, 15);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -144,8 +141,8 @@ public class IslandMapItem extends MapRenderer implements VariedItem {
|
||||
mapMeta.getPersistentDataContainer().set(getNamespacedKey(), getIdentifier(), getIdentifier().getID());
|
||||
MapView mapView = Bukkit.createMap(clicker.getWorld());
|
||||
mapView.setTrackingPosition(true);
|
||||
mapView.setCenterX(Math.round(clicker.getLocation().getBlockX() / 128f) * 128);
|
||||
mapView.setCenterZ(Math.round(clicker.getLocation().getBlockZ() / 128f) * 128);
|
||||
mapView.setCenterX((Math.round(clicker.getLocation().getBlockX() / 128f) * 128) - 1);
|
||||
mapView.setCenterZ((Math.round(clicker.getLocation().getBlockZ() / 128f) * 128) - 1);
|
||||
mapView.setScale(Scale.CLOSEST);
|
||||
mapMeta.setMapView(mapView);
|
||||
freshMap.setItemMeta(mapMeta);
|
||||
@ -163,7 +160,7 @@ public class IslandMapItem extends MapRenderer implements VariedItem {
|
||||
if (item.getType() != Material.FILLED_MAP) return;
|
||||
MapMeta mapMeta = (MapMeta) item.getItemMeta();
|
||||
MapView mapView = mapMeta.getMapView();
|
||||
mapView.removeRenderer(this);
|
||||
if (mapView.getRenderers().contains(this)) return;
|
||||
mapView.addRenderer(this);
|
||||
mapMeta.setMapView(mapView);
|
||||
item.setItemMeta(mapMeta);
|
||||
@ -171,6 +168,7 @@ public class IslandMapItem extends MapRenderer implements VariedItem {
|
||||
|
||||
@Override
|
||||
public void onItemHeld(ItemStack heldItem, HumanEntity holder) {
|
||||
initializeInstanceOfItem(heldItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,6 +130,10 @@ public class IslandInformationManager implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isChunkIslandInformationLoaded(Point2 chunkCoords, boolean checkLoading) {
|
||||
return islandSets.containsKey(chunkCoords) || buildingCache.contains(chunkCoords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
|
@ -29,7 +29,7 @@ public class IslandWorldMap {
|
||||
public IslandWorldMap(Random random) {
|
||||
this.noiseGenerator = new SimplexOctaveGenerator(random, NOISE_OCTAVES);
|
||||
noiseGenerator.setScale(SCALE);
|
||||
this.blockValueCache = new Cache<>(131072);
|
||||
this.blockValueCache = new Cache<>(256000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user