Fix AE2 spatial corrupting gt5 machines (#1292)

Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
Pxx500andMartin Robertz authored and GitHub committed 2026-05-20 08:14:44 +00:00
1 parent 930f22abd9
commit 5ed1dec685
5 files changed
+97 -1

No files matched your search

+9
View File
@@ -47,6 +47,15 @@ dependencies {
//runtimeOnlyNonPublishable('curse.maven:thermal-foundation-222880:2388753')
//runtimeOnlyNonPublishable('curse.maven:thermal-expansion-69163:2388759')
//Uncomment to test with GT5 machines
//runtimeOnlyNonPublishable('com.github.GTNewHorizons:GT5-Unofficial:5.09.52.411:dev') {transitive = false}
//runtimeOnlyNonPublishable('com.github.GTNewHorizons:StructureLib:1.4.34:dev') {transitive = false}
//runtimeOnlyNonPublishable('com.github.GTNewHorizons:ModularUI:1.3.2:dev') {transitive = false}
//runtimeOnlyNonPublishable('com.github.GTNewHorizons:ModularUI2:2.3.51-1.7.10:dev') {transitive = false}
//runtimeOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughIds:2.1.10:dev') {transitive = false}
//runtimeOnlyNonPublishable("com.github.GTNewHorizons:TinkersConstruct:1.14.58-GTNH:dev")
//runtimeOnlyNonPublishable('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev') {transitive = false}
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Postea:1.2.5:dev")
runtimeOnlyNonPublishable('com.github.GTNewHorizons:waila:1.19.22:dev') {transitive = false}
@@ -28,6 +28,13 @@ public interface IMovableHandler {
*/
boolean canHandle(Class<? extends TileEntity> myClass, TileEntity tile);
/**
* Called immediately before the tile is invalidated for movement.
*
* @param tile to be moved tile
*/
default void prepareToMove(TileEntity tile) {}
/**
* request that the handler move the the tile from its current location to the new one. the tile has already been
* invalidated, and the blocks have already been fully moved.
@@ -65,6 +65,7 @@ public class MovableTileRegistry implements IMovableRegistry {
((IMovableTile) te).prepareToMove();
}
canMove.prepareToMove(te);
te.invalidate();
return true;
}
@@ -10,6 +10,7 @@ import appeng.integration.IntegrationHelper;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IGT;
import appeng.spatial.NBTSpatialHandler;
import cpw.mods.fml.common.Loader;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
@@ -35,7 +36,9 @@ public class GT implements IIntegrationModule, IGT {
}
@Override
public void postInit() {}
public void postInit() {
AEApi.instance().registries().movable().addHandler(new NBTSpatialHandler(IGregTechTileEntity.class));
}
@Override
public boolean isGTMachine(TileEntity te) {
@@ -0,0 +1,76 @@
package appeng.spatial;
import java.util.IdentityHashMap;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import appeng.api.movable.IMovableHandler;
import appeng.core.AELog;
public class NBTSpatialHandler implements IMovableHandler {
private final Class<?> tileClass;
private final DefaultSpatialHandler fallback = new DefaultSpatialHandler();
private final IdentityHashMap<TileEntity, NBTTagCompound> snapshots = new IdentityHashMap<>();
public NBTSpatialHandler(final Class<?> tileClass) {
this.tileClass = tileClass;
}
@Override
public boolean canHandle(final Class<? extends TileEntity> myClass, final TileEntity tile) {
return this.tileClass.isAssignableFrom(myClass);
}
@Override
public void prepareToMove(final TileEntity tile) {
final NBTTagCompound tag = new NBTTagCompound();
tile.writeToNBT(tag);
this.snapshots.put(tile, tag);
}
@Override
public void moveTile(final TileEntity tile, final World world, final int x, final int y, final int z) {
try {
final TileEntity moved = TileEntity.createAndLoadEntity(this.createMovedTag(tile, x, y, z));
if (moved == null) {
throw new IllegalStateException("Unable to restore moved tile entity from NBT: " + tile.getClass());
}
moved.setWorldObj(world);
moved.xCoord = x;
moved.yCoord = y;
moved.zCoord = z;
final Chunk chunk = world.getChunkFromBlockCoords(x, z);
chunk.func_150812_a(x & 0xF, y, z & 0xF, moved);
if (chunk.isChunkLoaded) {
world.addTileEntity(moved);
world.markBlockForUpdate(x, y, z);
}
} catch (final Throwable e) {
AELog.debug(e);
this.fallback.moveTile(tile, world, x, y, z);
} finally {
this.snapshots.remove(tile);
}
}
NBTTagCompound createMovedTag(final TileEntity tile, final int x, final int y, final int z) {
NBTTagCompound snapshot = this.snapshots.get(tile);
if (snapshot == null) {
snapshot = new NBTTagCompound();
tile.writeToNBT(snapshot);
}
final NBTTagCompound tag = (NBTTagCompound) snapshot.copy();
tag.setInteger("x", x);
tag.setInteger("y", y);
tag.setInteger("z", z);
return tag;
}
}