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