This commit is contained in:
Daniel Mills 2021-08-07 08:16:24 -04:00
parent 6683eee49a
commit 6a68da0559
14 changed files with 138 additions and 237 deletions

View File

@ -524,30 +524,18 @@ public class Iris extends VolmitPlugin implements Listener {
return; return;
} }
try try {
{
throw new RuntimeException(); throw new RuntimeException();
} } catch (Throwable e) {
try {
catch(Throwable e)
{
try
{
String[] cc = e.getStackTrace()[1].getClassName().split("\\Q.\\E"); String[] cc = e.getStackTrace()[1].getClassName().split("\\Q.\\E");
if(cc.length > 5) if (cc.length > 5) {
{ debug(cc[3] + "/" + cc[4] + "/" + cc[cc.length - 1], e.getStackTrace()[1].getLineNumber(), string);
debug(cc[3] + "/" + cc[4] + "/" + cc[cc.length-1], e.getStackTrace()[1].getLineNumber(), string); } else {
}
else
{
debug(cc[3] + "/" + cc[4], e.getStackTrace()[1].getLineNumber(), string); debug(cc[3] + "/" + cc[4], e.getStackTrace()[1].getLineNumber(), string);
} }
} } catch (Throwable ex) {
catch(Throwable ex)
{
debug("Origin", -1, string); debug("Origin", -1, string);
} }
} }

View File

@ -102,40 +102,29 @@ public class CommandIrisStudioBeautify extends MortarCommand {
} }
private void fixBlocks(JSONObject obj, File f) { private void fixBlocks(JSONObject obj, File f) {
for(String i : obj.keySet()) for (String i : obj.keySet()) {
{
Object o = obj.get(i); Object o = obj.get(i);
if(i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) if (i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) {
{
obj.put(i, "minecraft:" + o); obj.put(i, "minecraft:" + o);
Iris.debug("Updated Block Key: " + o + " to " + obj.getString(i) + " in " + f.getPath()); Iris.debug("Updated Block Key: " + o + " to " + obj.getString(i) + " in " + f.getPath());
} }
if(o instanceof JSONObject) if (o instanceof JSONObject) {
{
fixBlocks((JSONObject) o, f); fixBlocks((JSONObject) o, f);
} } else if (o instanceof JSONArray) {
else if(o instanceof JSONArray)
{
fixBlocks((JSONArray) o, f); fixBlocks((JSONArray) o, f);
} }
} }
} }
private void fixBlocks(JSONArray obj, File f) { private void fixBlocks(JSONArray obj, File f) {
for(int i = 0; i < obj.length(); i++) for (int i = 0; i < obj.length(); i++) {
{
Object o = obj.get(i); Object o = obj.get(i);
if(o instanceof JSONObject) if (o instanceof JSONObject) {
{
fixBlocks((JSONObject) o, f); fixBlocks((JSONObject) o, f);
} } else if (o instanceof JSONArray) {
else if(o instanceof JSONArray)
{
fixBlocks((JSONArray) o, f); fixBlocks((JSONArray) o, f);
} }
} }

View File

@ -20,7 +20,6 @@ package com.volmit.iris.engine;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.events.IrisEngineHotloadEvent; import com.volmit.iris.core.events.IrisEngineHotloadEvent;
import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.*; import com.volmit.iris.engine.framework.*;
@ -29,13 +28,9 @@ import com.volmit.iris.engine.object.biome.IrisBiomePaletteLayer;
import com.volmit.iris.engine.object.decoration.IrisDecorator; import com.volmit.iris.engine.object.decoration.IrisDecorator;
import com.volmit.iris.engine.object.engine.IrisEngineData; import com.volmit.iris.engine.object.engine.IrisEngineData;
import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.objects.IrisObjectPlacement;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.context.IrisContext; import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.io.IO; import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;

View File

@ -36,7 +36,6 @@ import com.volmit.iris.util.math.BlockPosition;
import com.volmit.iris.util.math.Position2; import com.volmit.iris.util.math.Position2;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.IrisLock; import com.volmit.iris.util.scheduling.IrisLock;
import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View File

@ -1069,6 +1069,7 @@ public interface Hunk<T> {
/** /**
* Create a hunk that is optimized for specific uses * Create a hunk that is optimized for specific uses
*
* @param w width * @param w width
* @param h height * @param h height
* @param d depth * @param d depth
@ -1078,32 +1079,28 @@ public interface Hunk<T> {
* @param <T> the type * @param <T> the type
* @return the hunk * @return the hunk
*/ */
static <T> Hunk<T> newHunk(int w, int h, int d, Class<T> type, boolean packed, boolean concurrent) static <T> Hunk<T> newHunk(int w, int h, int d, Class<T> type, boolean packed, boolean concurrent) {
{ if (type.equals(Double.class)) {
if(type.equals(Double.class))
{
return concurrent ? return concurrent ?
packed ? (Hunk<T>) newAtomicDoubleHunk(w,h,d) : newMappedHunk(w,h,d) packed ? (Hunk<T>) newAtomicDoubleHunk(w, h, d) : newMappedHunk(w, h, d)
: packed ? newArrayHunk(w,h,d) : newMappedHunkSynced(w,h,d); : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
} }
if(type.equals(Integer.class)) if (type.equals(Integer.class)) {
{
return concurrent ? return concurrent ?
packed ? (Hunk<T>) newAtomicIntegerHunk(w,h,d) : newMappedHunk(w,h,d) packed ? (Hunk<T>) newAtomicIntegerHunk(w, h, d) : newMappedHunk(w, h, d)
: packed ? newArrayHunk(w,h,d) : newMappedHunkSynced(w,h,d); : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
} }
if(type.equals(Long.class)) if (type.equals(Long.class)) {
{
return concurrent ? return concurrent ?
packed ? (Hunk<T>) newAtomicLongHunk(w,h,d) : newMappedHunk(w,h,d) packed ? (Hunk<T>) newAtomicLongHunk(w, h, d) : newMappedHunk(w, h, d)
: packed ? newArrayHunk(w,h,d) : newMappedHunkSynced(w,h,d); : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
} }
return concurrent ? return concurrent ?
packed ? newAtomicHunk(w,h,d) : newMappedHunk(w,h,d) packed ? newAtomicHunk(w, h, d) : newMappedHunk(w, h, d)
: packed ? newArrayHunk(w,h,d) : newMappedHunkSynced(w,h,d); : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
} }
default void setIfExists(int x, int y, int z, T t) { default void setIfExists(int x, int y, int z, T t) {
@ -1449,8 +1446,7 @@ public interface Hunk<T> {
c[1] = y; c[1] = y;
} }
default boolean isEmpty() default boolean isEmpty() {
{
return false; return false;
} }
} }

View File

@ -20,7 +20,6 @@ package com.volmit.iris.util.hunk.storage;
import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.hunk.HunkFactory;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;

View File

@ -47,8 +47,7 @@ public class MappedHunk<T> extends StorageHunk<T> implements Hunk<T> {
return true; return true;
} }
public boolean isEmpty() public boolean isEmpty() {
{
return data.isEmpty(); return data.isEmpty();
} }

View File

@ -31,7 +31,10 @@ import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.HyperLock; import com.volmit.iris.util.parallel.HyperLock;
import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.parallel.MultiBurst;
import java.io.*; import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -43,8 +46,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* The mantle can store any type of data slice anywhere and manage regions & IO on it's own. * The mantle can store any type of data slice anywhere and manage regions & IO on it's own.
* This class is fully thread safe read & write * This class is fully thread safe read & write
*/ */
public class Mantle public class Mantle {
{
private final File dataFolder; private final File dataFolder;
private final int worldHeight; private final int worldHeight;
private final Map<Long, Long> lastUse; private final Map<Long, Long> lastUse;
@ -56,12 +58,12 @@ public class Mantle
/** /**
* Create a new mantle * Create a new mantle
*
* @param dataFolder the data folder * @param dataFolder the data folder
* @param worldHeight the world's height (in blocks) * @param worldHeight the world's height (in blocks)
*/ */
@BlockCoordinates @BlockCoordinates
public Mantle(File dataFolder, int worldHeight) public Mantle(File dataFolder, int worldHeight) {
{
this.hyperLock = new HyperLock(); this.hyperLock = new HyperLock();
this.closed = new AtomicBoolean(false); this.closed = new AtomicBoolean(false);
this.dataFolder = dataFolder; this.dataFolder = dataFolder;
@ -89,10 +91,8 @@ public class Mantle
* @param <T> the type of data (generic method) * @param <T> the type of data (generic method)
*/ */
@BlockCoordinates @BlockCoordinates
public <T> void set(int x, int y, int z, T t) public <T> void set(int x, int y, int z, T t) {
{ if (closed.get()) {
if(closed.get())
{
throw new RuntimeException("The Mantle is closed"); throw new RuntimeException("The Mantle is closed");
} }
@ -111,8 +111,7 @@ public class Mantle
e.printStackTrace(); e.printStackTrace();
} }
if(matter == null) if (matter == null) {
{
return; return;
} }
@ -137,10 +136,8 @@ public class Mantle
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@BlockCoordinates @BlockCoordinates
public <T> T get(int x, int y, int z, Class<T> t) public <T> T get(int x, int y, int z, Class<T> t) {
{ if (closed.get()) {
if(closed.get())
{
throw new RuntimeException("The Mantle is closed"); throw new RuntimeException("The Mantle is closed");
} }
@ -167,18 +164,15 @@ public class Mantle
* any data to the mantle or it's Tectonic Plates. Closing will also flush any * any data to the mantle or it's Tectonic Plates. Closing will also flush any
* loaded regions to the disk in parallel. * loaded regions to the disk in parallel.
*/ */
public synchronized void close() public synchronized void close() {
{
Iris.debug("Closing The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath()); Iris.debug("Closing The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath());
if(closed.get()) if (closed.get()) {
{
throw new RuntimeException("The Mantle is closed"); throw new RuntimeException("The Mantle is closed");
} }
closed.set(true); closed.set(true);
BurstExecutor b = ioBurst.burst(loadedRegions.size()); BurstExecutor b = ioBurst.burst(loadedRegions.size());
for(Long i : loadedRegions.keySet()) for (Long i : loadedRegions.keySet()) {
{
b.queue(() -> { b.queue(() -> {
try { try {
loadedRegions.get(i).write(fileForRegion(dataFolder, i)); loadedRegions.get(i).write(fileForRegion(dataFolder, i));
@ -196,34 +190,29 @@ public class Mantle
/** /**
* Save & unload regions that have not been used for more than the * Save & unload regions that have not been used for more than the
* specified amount of milliseconds * specified amount of milliseconds
*
* @param idleDuration the duration * @param idleDuration the duration
*/ */
public synchronized void trim(long idleDuration) public synchronized void trim(long idleDuration) {
{ if (closed.get()) {
if(closed.get())
{
throw new RuntimeException("The Mantle is closed"); throw new RuntimeException("The Mantle is closed");
} }
Iris.debug("Trimming Tectonic Plates older than " + Form.duration((double)idleDuration, 0)); Iris.debug("Trimming Tectonic Plates older than " + Form.duration((double) idleDuration, 0));
unload.clear(); unload.clear();
for(Long i : lastUse.keySet()) for (Long i : lastUse.keySet()) {
{ if (M.ms() - lastUse.get(i) >= idleDuration) {
if(M.ms() - lastUse.get(i) >= idleDuration)
{
unload.add(i); unload.add(i);
} }
} }
for(Long i : unload) for (Long i : unload) {
{
TectonicPlate m = loadedRegions.remove(i); TectonicPlate m = loadedRegions.remove(i);
lastUse.remove(i); lastUse.remove(i);
Iris.debug("Unloaded Tectonic Plate " + C.DARK_GREEN + i); Iris.debug("Unloaded Tectonic Plate " + C.DARK_GREEN + i);
if(m != null) if (m != null) {
{
ioBurst.lazy(() -> { ioBurst.lazy(() -> {
try { try {
m.write(fileForRegion(dataFolder, i)); m.write(fileForRegion(dataFolder, i));
@ -238,39 +227,33 @@ public class Mantle
/** /**
* This retreives a future of the Tectonic Plate at the given coordinates. * This retreives a future of the Tectonic Plate at the given coordinates.
* All methods accessing tectonic plates should go through this method * All methods accessing tectonic plates should go through this method
*
* @param x the region x * @param x the region x
* @param z the region z * @param z the region z
* @return the future of a tectonic plate. * @return the future of a tectonic plate.
*/ */
@RegionCoordinates @RegionCoordinates
private CompletableFuture<TectonicPlate> get(int x, int z) private CompletableFuture<TectonicPlate> get(int x, int z) {
{
return ioBurst.completeValue(() -> hyperLock.withResult(x, z, () -> { return ioBurst.completeValue(() -> hyperLock.withResult(x, z, () -> {
Long k = key(x, z); Long k = key(x, z);
lastUse.put(k, M.ms()); lastUse.put(k, M.ms());
TectonicPlate region = loadedRegions.get(k); TectonicPlate region = loadedRegions.get(k);
if(region != null) if (region != null) {
{
return region; return region;
} }
File file = fileForRegion(dataFolder, x, z); File file = fileForRegion(dataFolder, x, z);
if(file.exists()) if (file.exists()) {
{ try {
try
{
FileInputStream fin = new FileInputStream(file); FileInputStream fin = new FileInputStream(file);
DataInputStream din = new DataInputStream(fin); DataInputStream din = new DataInputStream(fin);
region = new TectonicPlate(worldHeight, din); region = new TectonicPlate(worldHeight, din);
din.close(); din.close();
loadedRegions.put(k, region); loadedRegions.put(k, region);
Iris.debug("Loaded Tectonic Plate " + C.DARK_GREEN + x + " " + z + C.DARK_AQUA + " " + file.getName()); Iris.debug("Loaded Tectonic Plate " + C.DARK_GREEN + x + " " + z + C.DARK_AQUA + " " + file.getName());
} } catch (Throwable e) {
catch(Throwable e)
{
Iris.error("Failed to read Tectonic Plate " + file.getAbsolutePath() + " creating a new chunk instead."); Iris.error("Failed to read Tectonic Plate " + file.getAbsolutePath() + " creating a new chunk instead.");
Iris.reportError(e); Iris.reportError(e);
e.printStackTrace(); e.printStackTrace();
@ -300,8 +283,7 @@ public class Mantle
return f; return f;
} }
public static Long key(int x, int z) public static Long key(int x, int z) {
{
return Cache.key(x, z); return Cache.key(x, z);
} }
} }

View File

@ -18,13 +18,10 @@
package com.volmit.iris.util.mantle; package com.volmit.iris.util.mantle;
import com.volmit.iris.engine.data.chunk.MCATerrainChunk;
import com.volmit.iris.util.data.Varint; import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.matter.IrisMatter; import com.volmit.iris.util.matter.IrisMatter;
import com.volmit.iris.util.matter.Matter; import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.nbt.mca.Section;
import lombok.Data;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -40,16 +37,17 @@ public class MantleChunk {
/** /**
* Create a mantle chunk * Create a mantle chunk
*
* @param sectionHeight the height of the world in sections (blocks >> 4) * @param sectionHeight the height of the world in sections (blocks >> 4)
*/ */
@ChunkCoordinates @ChunkCoordinates
public MantleChunk(int sectionHeight) public MantleChunk(int sectionHeight) {
{
sections = new AtomicReferenceArray<>(sectionHeight); sections = new AtomicReferenceArray<>(sectionHeight);
} }
/** /**
* Load a mantle chunk from a data stream * Load a mantle chunk from a data stream
*
* @param sectionHeight the height of the world in sections (blocks >> 4) * @param sectionHeight the height of the world in sections (blocks >> 4)
* @param din the data input * @param din the data input
* @throws IOException shit happens * @throws IOException shit happens
@ -59,10 +57,8 @@ public class MantleChunk {
this(sectionHeight); this(sectionHeight);
int s = Varint.readUnsignedVarInt(din); int s = Varint.readUnsignedVarInt(din);
for(int i = 0; i < s; i++) for (int i = 0; i < s; i++) {
{ if (din.readBoolean()) {
if(din.readBoolean())
{
sections.set(i, Matter.read(din)); sections.set(i, Matter.read(din));
} }
} }
@ -70,59 +66,56 @@ public class MantleChunk {
/** /**
* Check if a section exists (same as get(section) != null) * Check if a section exists (same as get(section) != null)
*
* @param section the section (0 - (worldHeight >> 4)) * @param section the section (0 - (worldHeight >> 4))
* @return true if it exists * @return true if it exists
*/ */
@ChunkCoordinates @ChunkCoordinates
public boolean exists(int section) public boolean exists(int section) {
{
return get(section) != null; return get(section) != null;
} }
/** /**
* Get thje matter at the given section or null if it doesnt exist * Get thje matter at the given section or null if it doesnt exist
*
* @param section the section (0 - (worldHeight >> 4)) * @param section the section (0 - (worldHeight >> 4))
* @return the matter or null if it doesnt exist * @return the matter or null if it doesnt exist
*/ */
@ChunkCoordinates @ChunkCoordinates
public Matter get(int section) public Matter get(int section) {
{
return sections.get(section); return sections.get(section);
} }
/** /**
* Clear all matter from this chunk * Clear all matter from this chunk
*/ */
public void clear() public void clear() {
{ for (int i = 0; i < sections.length(); i++) {
for(int i = 0; i < sections.length(); i++)
{
delete(i); delete(i);
} }
} }
/** /**
* Delete the matter from the given section * Delete the matter from the given section
*
* @param section the section (0 - (worldHeight >> 4)) * @param section the section (0 - (worldHeight >> 4))
*/ */
@ChunkCoordinates @ChunkCoordinates
public void delete(int section) public void delete(int section) {
{
sections.set(section, null); sections.set(section, null);
} }
/** /**
* Get or create a new matter section at the given section * Get or create a new matter section at the given section
*
* @param section the section (0 - (worldHeight >> 4)) * @param section the section (0 - (worldHeight >> 4))
* @return the matter * @return the matter
*/ */
@ChunkCoordinates @ChunkCoordinates
public Matter getOrCreate(int section) public Matter getOrCreate(int section) {
{
Matter matter = get(section); Matter matter = get(section);
if(matter == null) if (matter == null) {
{
matter = new IrisMatter(16, 16, 16); matter = new IrisMatter(16, 16, 16);
sections.set(section, matter); sections.set(section, matter);
} }
@ -132,23 +125,19 @@ public class MantleChunk {
/** /**
* Write this chunk to a data stream * Write this chunk to a data stream
*
* @param dos the stream * @param dos the stream
* @throws IOException shit happens * @throws IOException shit happens
*/ */
public void write(DataOutputStream dos) throws IOException { public void write(DataOutputStream dos) throws IOException {
Varint.writeUnsignedVarInt(sections.length(), dos); Varint.writeUnsignedVarInt(sections.length(), dos);
for(int i = 0; i < sections.length(); i++) for (int i = 0; i < sections.length(); i++) {
{ if (exists(i)) {
if(exists(i))
{
dos.writeBoolean(true); dos.writeBoolean(true);
Matter matter = get(i); Matter matter = get(i);
matter.writeDos(dos); matter.writeDos(dos);
} } else {
else
{
dos.writeBoolean(false); dos.writeBoolean(false);
} }
} }

View File

@ -35,16 +35,17 @@ public class TectonicPlate {
/** /**
* Create a new tectonic plate * Create a new tectonic plate
*
* @param worldHeight the height of the world * @param worldHeight the height of the world
*/ */
public TectonicPlate(int worldHeight) public TectonicPlate(int worldHeight) {
{
this.sectionHeight = worldHeight >> 4; this.sectionHeight = worldHeight >> 4;
this.chunks = new AtomicReferenceArray<>(1024); this.chunks = new AtomicReferenceArray<>(1024);
} }
/** /**
* Load a tectonic plate from a data stream * Load a tectonic plate from a data stream
*
* @param worldHeight the height of the world * @param worldHeight the height of the world
* @param din the data input * @param din the data input
* @throws IOException shit happens yo * @throws IOException shit happens yo
@ -53,10 +54,8 @@ public class TectonicPlate {
public TectonicPlate(int worldHeight, DataInputStream din) throws IOException, ClassNotFoundException { public TectonicPlate(int worldHeight, DataInputStream din) throws IOException, ClassNotFoundException {
this(worldHeight); this(worldHeight);
for(int i = 0; i < chunks.length(); i++) for (int i = 0; i < chunks.length(); i++) {
{ if (din.readBoolean()) {
if(din.readBoolean())
{
chunks.set(i, new MantleChunk(sectionHeight, din)); chunks.set(i, new MantleChunk(sectionHeight, din));
} }
} }
@ -64,63 +63,60 @@ public class TectonicPlate {
/** /**
* Check if a chunk exists in this plate or not (same as get(x, z) != null) * Check if a chunk exists in this plate or not (same as get(x, z) != null)
*
* @param x the chunk relative x (0-31) * @param x the chunk relative x (0-31)
* @param z the chunk relative z (0-31) * @param z the chunk relative z (0-31)
* @return true if the chunk exists * @return true if the chunk exists
*/ */
@ChunkCoordinates @ChunkCoordinates
public boolean exists(int x, int z) public boolean exists(int x, int z) {
{
return get(x, z) != null; return get(x, z) != null;
} }
/** /**
* Get a chunk at the given coordinates or null if it doesnt exist * Get a chunk at the given coordinates or null if it doesnt exist
*
* @param x the chunk relative x (0-31) * @param x the chunk relative x (0-31)
* @param z the chunk relative z (0-31) * @param z the chunk relative z (0-31)
* @return the chunk or null if it doesnt exist * @return the chunk or null if it doesnt exist
*/ */
@ChunkCoordinates @ChunkCoordinates
public MantleChunk get(int x, int z) public MantleChunk get(int x, int z) {
{
return chunks.get(index(x, z)); return chunks.get(index(x, z));
} }
/** /**
* Clear all chunks from this tectonic plate * Clear all chunks from this tectonic plate
*/ */
public void clear() public void clear() {
{ for (int i = 0; i < chunks.length(); i++) {
for(int i = 0; i < chunks.length(); i++)
{
chunks.set(i, null); chunks.set(i, null);
} }
} }
/** /**
* Delete a chunk from this tectonic plate * Delete a chunk from this tectonic plate
*
* @param x the chunk relative x (0-31) * @param x the chunk relative x (0-31)
* @param z the chunk relative z (0-31) * @param z the chunk relative z (0-31)
*/ */
@ChunkCoordinates @ChunkCoordinates
public void delete(int x, int z) public void delete(int x, int z) {
{
chunks.set(index(x, z), null); chunks.set(index(x, z), null);
} }
/** /**
* Get a tectonic plate, or create one and insert it & return it if it diddnt exist * Get a tectonic plate, or create one and insert it & return it if it diddnt exist
*
* @param x the chunk relative x (0-31) * @param x the chunk relative x (0-31)
* @param z the chunk relative z (0-31) * @param z the chunk relative z (0-31)
* @return the chunk (read or created & inserted) * @return the chunk (read or created & inserted)
*/ */
@ChunkCoordinates @ChunkCoordinates
public MantleChunk getOrCreate(int x, int z) public MantleChunk getOrCreate(int x, int z) {
{
MantleChunk chunk = get(x, z); MantleChunk chunk = get(x, z);
if(chunk == null) if (chunk == null) {
{
chunk = new MantleChunk(sectionHeight); chunk = new MantleChunk(sectionHeight);
chunks.set(index(x, z), chunk); chunks.set(index(x, z), chunk);
} }
@ -135,6 +131,7 @@ public class TectonicPlate {
/** /**
* Write this tectonic plate to file * Write this tectonic plate to file
*
* @param file the file to write it to * @param file the file to write it to
* @throws IOException shit happens * @throws IOException shit happens
*/ */
@ -148,17 +145,16 @@ public class TectonicPlate {
/** /**
* Write this tectonic plate to a data stream * Write this tectonic plate to a data stream
*
* @param dos the data output * @param dos the data output
* @throws IOException shit happens * @throws IOException shit happens
*/ */
public void write(DataOutputStream dos) throws IOException { public void write(DataOutputStream dos) throws IOException {
for(int i = 0; i < chunks.length(); i++) for (int i = 0; i < chunks.length(); i++) {
{
MantleChunk chunk = chunks.get(i); MantleChunk chunk = chunks.get(i);
dos.writeBoolean(chunk != null); dos.writeBoolean(chunk != null);
if(chunk != null) if (chunk != null) {
{
chunk.write(dos); chunk.write(dos);
} }
} }

View File

@ -29,7 +29,6 @@ import org.bukkit.World;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import javax.xml.crypto.Data;
import java.io.*; import java.io.*;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -355,13 +354,11 @@ public interface Matter {
return matter; return matter;
} }
default int getTotalCount() default int getTotalCount() {
{
int m = 0; int m = 0;
for(MatterSlice<?> i : getSliceMap().values()) for (MatterSlice<?> i : getSliceMap().values()) {
{ m += i.getEntryCount();
m+= i.getEntryCount();
} }
return m; return m;

View File

@ -21,7 +21,6 @@ package com.volmit.iris.util.matter;
import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.data.Varint; import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.hunk.storage.MappedHunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
@ -116,17 +115,13 @@ public interface MatterSlice<T> extends Hunk<T> {
palette.writePalette(dos); palette.writePalette(dos);
dos.writeBoolean(isMapped()); dos.writeBoolean(isMapped());
if(isMapped()) if (isMapped()) {
{
Varint.writeUnsignedVarInt(getEntryCount(), dos); Varint.writeUnsignedVarInt(getEntryCount(), dos);
iterateSyncIO((x, y, z, b) -> { iterateSyncIO((x, y, z, b) -> {
Varint.writeUnsignedVarInt(Cache.to1D(x, y, z, w, h), dos); Varint.writeUnsignedVarInt(Cache.to1D(x, y, z, w, h), dos);
palette.writeNode(b, dos); palette.writeNode(b, dos);
}); });
} } else {
else
{
iterateSyncIO((x, y, z, b) -> palette.writeNode(b, dos)); iterateSyncIO((x, y, z, b) -> palette.writeNode(b, dos));
} }
} }
@ -135,8 +130,7 @@ public interface MatterSlice<T> extends Hunk<T> {
int w = getWidth(); int w = getWidth();
int h = getHeight(); int h = getHeight();
MatterPalette<T> palette = new MatterPalette<T>(this, din); MatterPalette<T> palette = new MatterPalette<T>(this, din);
if(din.readBoolean()) if (din.readBoolean()) {
{
int nodes = Varint.readUnsignedVarInt(din); int nodes = Varint.readUnsignedVarInt(din);
int[] pos; int[] pos;
@ -144,10 +138,7 @@ public interface MatterSlice<T> extends Hunk<T> {
pos = Cache.to3D(Varint.readUnsignedVarInt(din), w, h); pos = Cache.to3D(Varint.readUnsignedVarInt(din), w, h);
setRaw(pos[0], pos[1], pos[2], palette.readNode(din)); setRaw(pos[0], pos[1], pos[2], palette.readNode(din));
} }
} } else {
else
{
iterateSyncIO((x, y, z, b) -> setRaw(x, y, z, palette.readNode(din))); iterateSyncIO((x, y, z, b) -> setRaw(x, y, z, palette.readNode(din)));
} }
} }
@ -156,18 +147,15 @@ public interface MatterSlice<T> extends Hunk<T> {
rotate(x, y, z, (_x, _y, _z) -> n.slice(getType())); rotate(x, y, z, (_x, _y, _z) -> n.slice(getType()));
} }
default boolean containsKey(BlockVector v) default boolean containsKey(BlockVector v) {
{
return get(v.getBlockX(), v.getBlockY(), v.getBlockZ()) != null; return get(v.getBlockX(), v.getBlockY(), v.getBlockZ()) != null;
} }
default void put(BlockVector v, T d) default void put(BlockVector v, T d) {
{
set(v.getBlockX(), v.getBlockY(), v.getBlockZ(), d); set(v.getBlockX(), v.getBlockY(), v.getBlockZ(), d);
} }
default T get(BlockVector v) default T get(BlockVector v) {
{
return get(v.getBlockX(), v.getBlockY(), v.getBlockZ()); return get(v.getBlockX(), v.getBlockY(), v.getBlockZ());
} }
} }

View File

@ -18,8 +18,6 @@
package com.volmit.iris.util.matter.slices; package com.volmit.iris.util.matter.slices;
import com.volmit.iris.engine.parallax.ParallaxAccess;
import com.volmit.iris.engine.parallax.ParallaxWorld;
import com.volmit.iris.util.data.B; import com.volmit.iris.util.data.B;
import com.volmit.iris.util.matter.Sliced; import com.volmit.iris.util.matter.Sliced;
import org.bukkit.World; import org.bukkit.World;

View File

@ -67,19 +67,12 @@ public class HyperLock {
Throwable ee = null; Throwable ee = null;
try { try {
r.run(); r.run();
} } catch (Throwable e) {
catch(Throwable e)
{
ee = e; ee = e;
} } finally {
finally
{
unlock(x, z); unlock(x, z);
if(ee != null) if (ee != null) {
{
throw ee; throw ee;
} }
} }
@ -90,19 +83,12 @@ public class HyperLock {
IOException ee = null; IOException ee = null;
try { try {
r.run(); r.run();
} } catch (IOException e) {
catch(IOException e)
{
ee = e; ee = e;
} } finally {
finally
{
unlock(x, z); unlock(x, z);
if(ee != null) if (ee != null) {
{
throw ee; throw ee;
} }
} }