Fixed Bug: #0695 - Itemframes disappearing with Spatial IO

This commit is contained in:
AlgorithmX2 2014-07-25 21:35:48 -05:00
parent 6766f8f0f8
commit b4d99d3d06

View file

@ -5,20 +5,19 @@ import java.util.List;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityHanging;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.Teleporter; import net.minecraft.world.Teleporter;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.util.WorldCoord; import appeng.api.util.WorldCoord;
import appeng.block.spatial.BlockMatrixFrame; import appeng.block.spatial.BlockMatrixFrame;
import appeng.core.AELog;
import appeng.util.Platform; import appeng.util.Platform;
import cpw.mods.fml.relauncher.ReflectionHelper;
public class StorageHelper public class StorageHelper
{ {
@ -72,17 +71,24 @@ public class StorageHelper
class TelDestination class TelDestination
{ {
TelDestination(World _dim, AxisAlignedBB srcBox, double _x, double _y, double _z) { TelDestination(World _dim, AxisAlignedBB srcBox, double _x, double _y, double _z, int tileX, int tileY, int tileZ) {
dim = _dim; dim = _dim;
x = Math.min( srcBox.maxX - 0.5, Math.max( srcBox.minX + 0.5, _x ) ); x = Math.min( srcBox.maxX - 0.5, Math.max( srcBox.minX + 0.5, _x + tileX ) );
y = Math.min( srcBox.maxY - 0.5, Math.max( srcBox.minY + 0.5, _y ) ); y = Math.min( srcBox.maxY - 0.5, Math.max( srcBox.minY + 0.5, _y + tileY ) );
z = Math.min( srcBox.maxZ - 0.5, Math.max( srcBox.minZ + 0.5, _z ) ); z = Math.min( srcBox.maxZ - 0.5, Math.max( srcBox.minZ + 0.5, _z + tileZ ) );
xOff = tileX;
yOff = tileY;
zOff = tileZ;
} }
final World dim; final World dim;
final double x; final double x;
final double y; final double y;
final double z; final double z;
final int xOff;
final int yOff;
final int zOff;
}; };
class METeleporter extends Teleporter class METeleporter extends Teleporter
@ -167,6 +173,10 @@ public class StorageHelper
// We keep track of both so we can remount them on the other side. // We keep track of both so we can remount them on the other side.
} }
// load the chunk!
Chunk myChunk = WorldServer.class.cast( newWorld ).getChunkProvider()
.loadChunk( MathHelper.floor_double( link.x ) >> 4, MathHelper.floor_double( link.z ) >> 4 );
boolean difDest = newWorld != oldWorld; boolean difDest = newWorld != oldWorld;
if ( difDest ) if ( difDest )
{ {
@ -178,50 +188,42 @@ public class StorageHelper
{ {
int entX = entity.chunkCoordX; int entX = entity.chunkCoordX;
int entZ = entity.chunkCoordZ; int entZ = entity.chunkCoordZ;
if ( (entity.addedToChunk) && (oldWorld.getChunkProvider().chunkExists( entX, entZ )) ) if ( (entity.addedToChunk) && (oldWorld.getChunkProvider().chunkExists( entX, entZ )) )
{ {
oldWorld.getChunkFromChunkCoords( entX, entZ ).removeEntity( entity ); oldWorld.getChunkFromChunkCoords( entX, entZ ).removeEntity( entity );
oldWorld.getChunkFromChunkCoords( entX, entZ ).isModified = true; oldWorld.getChunkFromChunkCoords( entX, entZ ).isModified = true;
} }
if ( onEntityRemoved == null ) Entity newEntity = EntityList.createEntityByName( EntityList.getEntityString( entity ), newWorld );
if ( newEntity != null )
{ {
onEntityRemoved = ReflectionHelper.findMethod( WorldServer.class, oldWorld, new String[] { "onEntityRemoved", "func_72847_b" }, entity.lastTickPosX = entity.prevPosX = entity.posX = link.x;
Entity.class ); entity.lastTickPosY = entity.prevPosY = entity.posY = link.y;
} entity.lastTickPosZ = entity.prevPosZ = entity.posZ = link.z;
if ( onEntityRemoved != null ) if ( entity instanceof EntityHanging )
{
try
{ {
onEntityRemoved.invoke( oldWorld, entity ); EntityHanging h = (EntityHanging) entity;
h.field_146063_b += link.xOff;
h.field_146064_c += link.yOff;
h.field_146062_d += link.zOff;
} }
catch (Throwable t)
{
AELog.error( t );
}
}
if ( player == null ) // Are we NOT working with a player? newEntity.copyDataFrom( entity, true );
{ newEntity.dimension = newWorld.provider.dimensionId;
NBTTagCompound entityNBT = new NBTTagCompound(); newEntity.forceSpawn = true;
entity.posX = link.x;
entity.posY = link.y;
entity.posZ = link.z;
entity.prevPosX = link.x;
entity.prevPosY = link.y;
entity.prevPosZ = link.z;
entity.isDead = false;
entity.writeToNBTOptional( entityNBT );
entity.isDead = true; entity.isDead = true;
entity = EntityList.createEntityFromNBT( entityNBT, newWorld ); entity = newEntity;
} }
else
return null;
if ( entity == null ) // myChunk.addEntity( entity );
return entity; // newWorld.loadedEntityList.add( entity );
// newWorld.onEntityAdded( entity );
newWorld.spawnEntityInWorld( entity ); newWorld.spawnEntityInWorld( entity );
entity.setWorld( newWorld );
} }
} }
@ -235,12 +237,6 @@ public class StorageHelper
entity.mountEntity( cart ); entity.mountEntity( cart );
} }
if ( player != null )
{
WorldServer.class.cast( newWorld ).getChunkProvider()
.loadChunk( MathHelper.floor_double( entity.posX ) >> 4, MathHelper.floor_double( entity.posZ ) >> 4 );
}
return entity; return entity;
} }
@ -292,12 +288,12 @@ public class StorageHelper
for (Entity e : dstE) for (Entity e : dstE)
{ {
teleportEntity( e, new TelDestination( src, srcBox, e.posX - i + x, e.posY - j + y, e.posZ - k + z ) ); teleportEntity( e, new TelDestination( src, srcBox, e.posX, e.posY, e.posZ, -i + x, -j + y, -k + z ) );
} }
for (Entity e : srcE) for (Entity e : srcE)
{ {
teleportEntity( e, new TelDestination( dst, dstBox, e.posX - x + i, e.posY - y + j, e.posZ - z + k ) ); teleportEntity( e, new TelDestination( dst, dstBox, e.posX, e.posY, e.posZ, -x + i, -y + j, -z + k ) );
} }
for (WorldCoord wc : cDst.updates) for (WorldCoord wc : cDst.updates)