mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Unsafe but somehow safe black magic
This commit is contained in:
parent
e66cb9479f
commit
6dcf3e15da
@ -95,11 +95,7 @@ public class Mantle {
|
|||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
public void flag(int x, int z, MantleFlag flag, boolean flagged) {
|
public void flag(int x, int z, MantleFlag flag, boolean flagged) {
|
||||||
try {
|
get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).flag(flag, flagged);
|
||||||
get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).flag(flag, flagged);
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
@ -110,22 +106,12 @@ public class Mantle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).iterate(type, iterator);
|
||||||
get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).iterate(type, iterator);
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
public boolean hasFlag(int x, int z, MantleFlag flag) {
|
public boolean hasFlag(int x, int z, MantleFlag flag) {
|
||||||
try {
|
return get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).isFlagged(flag);
|
||||||
return get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).isFlagged(flag);
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,25 +134,9 @@ public class Mantle {
|
|||||||
throw new RuntimeException("The Mantle is closed");
|
throw new RuntimeException("The Mantle is closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
Matter matter = null;
|
Matter matter = get((x >> 4) >> 5, (z >> 4) >> 5)
|
||||||
try {
|
.getOrCreate((x >> 4) & 31, (z >> 4) & 31)
|
||||||
matter = get((x >> 4) >> 5, (z >> 4) >> 5).get()
|
.getOrCreate(y >> 4);
|
||||||
.getOrCreate((x >> 4) & 31, (z >> 4) & 31)
|
|
||||||
.getOrCreate(y >> 4);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Iris.error("Failed to get Tectonic Plate " + ((x >> 4) >> 5) + " " + ((z >> 4) >> 5) + " Due to a thread intterruption");
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
Iris.error("Failed to get Tectonic Plate " + ((x >> 4) >> 5) + " " + ((z >> 4) >> 5) + " Due to a thread execution exception");
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matter == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
matter.slice(matter.getClass(t))
|
matter.slice(matter.getClass(t))
|
||||||
.set(x & 15, y & 15, z & 15, t);
|
.set(x & 15, y & 15, z & 15, t);
|
||||||
}
|
}
|
||||||
@ -193,22 +163,10 @@ public class Mantle {
|
|||||||
throw new RuntimeException("The Mantle is closed");
|
throw new RuntimeException("The Mantle is closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return (T) get((x >> 4) >> 5, (z >> 4) >> 5)
|
||||||
return (T) get((x >> 4) >> 5, (z >> 4) >> 5).get()
|
.getOrCreate((x >> 4) & 31, (z >> 4) & 31)
|
||||||
.getOrCreate((x >> 4) & 31, (z >> 4) & 31)
|
.getOrCreate(y >> 4).slice(t)
|
||||||
.getOrCreate(y >> 4).slice(t)
|
.get(x & 15, y & 15, z & 15);
|
||||||
.get(x & 15, y & 15, z & 15);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Iris.error("Failed to get Tectonic Plate " + ((x >> 4) >> 5) + " " + ((z >> 4) >> 5) + " Due to a thread intterruption");
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
Iris.error("Failed to get Tectonic Plate " + ((x >> 4) >> 5) + " " + ((z >> 4) >> 5) + " Due to a thread execution exception");
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -286,7 +244,41 @@ public class Mantle {
|
|||||||
* @return the future of a tectonic plate.
|
* @return the future of a tectonic plate.
|
||||||
*/
|
*/
|
||||||
@RegionCoordinates
|
@RegionCoordinates
|
||||||
private synchronized CompletableFuture<TectonicPlate> get(int x, int z) {
|
private TectonicPlate get(int x, int z) {
|
||||||
|
TectonicPlate p = loadedRegions.get(key(x, z));
|
||||||
|
|
||||||
|
if(p != null)
|
||||||
|
{
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return getSafe(x, z).get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Iris.error("Failed to get Tectonic Plate " + x + " " + z + " Due to a thread intterruption");
|
||||||
|
Iris.reportError(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
Iris.error("Failed to get Tectonic Plate " + x + " " + z + " Due to a thread execution exception");
|
||||||
|
Iris.reportError(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iris.warn("Retrying to get " + x + " " + z + " Mantle Region");
|
||||||
|
return get(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This retreives a future of the Tectonic Plate at the given coordinates.
|
||||||
|
* All methods accessing tectonic plates should go through this method
|
||||||
|
*
|
||||||
|
* @param x the region x
|
||||||
|
* @param z the region z
|
||||||
|
* @return the future of a tectonic plate.
|
||||||
|
*/
|
||||||
|
@RegionCoordinates
|
||||||
|
private CompletableFuture<TectonicPlate> getSafe(int x, int z) {
|
||||||
Long k = key(x, z);
|
Long k = key(x, z);
|
||||||
TectonicPlate p = loadedRegions.get(k);
|
TectonicPlate p = loadedRegions.get(k);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user