mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-11-14 01:14:11 +00:00
Fix Spatial IO transfers into unloaded chunks (#1482)
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
e221aa1036
commit
6efcb44074
3 files changed
+40
-1
No files matched your search
@@ -70,7 +70,10 @@ public abstract class MBCalculator {
|
||||
|
||||
boolean updateGrid = false;
|
||||
IAECluster cluster = this.target.getCluster();
|
||||
if (cluster == null) {
|
||||
if (cluster == null || !this.matchesExistingCluster(cluster, min, max)) {
|
||||
if (cluster != null) {
|
||||
cluster.destroy();
|
||||
}
|
||||
cluster = this.createCluster(world, min, max);
|
||||
this.updateTiles(cluster, world, min, max);
|
||||
updateGrid = true;
|
||||
@@ -120,6 +123,10 @@ public abstract class MBCalculator {
|
||||
*/
|
||||
public abstract IAECluster createCluster(World w, WorldCoord min, WorldCoord max);
|
||||
|
||||
protected boolean matchesExistingCluster(final IAECluster cluster, final WorldCoord min, final WorldCoord max) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract boolean verifyInternalStructure(World worldObj, WorldCoord min, WorldCoord max);
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,12 @@ public class SpatialPylonCalculator extends MBCalculator {
|
||||
new DimensionalCoord(w, max.x, max.y, max.z));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesExistingCluster(final IAECluster cluster, final WorldCoord min, final WorldCoord max) {
|
||||
final SpatialPylonCluster pylonCluster = (SpatialPylonCluster) cluster;
|
||||
return pylonCluster.getMin().isEqual(min) && pylonCluster.getMax().isEqual(max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyInternalStructure(final World w, final WorldCoord min, final WorldCoord max) {
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.util.WorldCoord;
|
||||
@@ -30,6 +33,8 @@ import appeng.util.Platform;
|
||||
|
||||
public class StorageHelper {
|
||||
|
||||
private static final int CHUNK_COORDINATE_SHIFT = 4;
|
||||
|
||||
private static StorageHelper instance;
|
||||
|
||||
public static StorageHelper getInstance() {
|
||||
@@ -173,6 +178,9 @@ public class StorageHelper {
|
||||
, final World dst/** storage cell **/
|
||||
,final int x, final int y, final int z, final int i, final int j, final int k, final int scaleX,
|
||||
final int scaleY, final int scaleZ) {
|
||||
ensureRegionLoaded(src.getChunkProvider(), x - 1, z - 1, x + scaleX + 1, z + scaleZ + 1);
|
||||
ensureRegionLoaded(dst.getChunkProvider(), i - 1, k - 1, i + scaleX + 1, k + scaleZ + 1);
|
||||
|
||||
for (final Block matrixFrameBlock : AEApi.instance().definitions().blocks().matrixFrame().maybeBlock()
|
||||
.asSet()) {
|
||||
this.transverseEdges(
|
||||
@@ -243,6 +251,24 @@ public class StorageHelper {
|
||||
|
||||
}
|
||||
|
||||
static void ensureRegionLoaded(final IChunkProvider chunkProvider, final int minBlockX, final int minBlockZ,
|
||||
final int maxBlockX, final int maxBlockZ) {
|
||||
final int minChunkX = minBlockX >> CHUNK_COORDINATE_SHIFT;
|
||||
final int minChunkZ = minBlockZ >> CHUNK_COORDINATE_SHIFT;
|
||||
final int maxChunkX = maxBlockX >> CHUNK_COORDINATE_SHIFT;
|
||||
final int maxChunkZ = maxBlockZ >> CHUNK_COORDINATE_SHIFT;
|
||||
|
||||
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
|
||||
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
|
||||
final Chunk chunk = chunkProvider.loadChunk(chunkX, chunkZ);
|
||||
if (chunk == null || chunk instanceof EmptyChunk || !chunk.isAtLocation(chunkX, chunkZ)) {
|
||||
throw new IllegalStateException(
|
||||
"Unable to load chunk " + chunkX + ", " + chunkZ + " for spatial transfer");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class TriggerUpdates implements ISpatialVisitor {
|
||||
|
||||
private final World dst;
|
||||
|
||||
Reference in new issue
Block a user