2014-01-20 17:41:37 +01:00
|
|
|
package appeng.debug;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.world.ChunkCoordIntPair;
|
|
|
|
import net.minecraftforge.common.ForgeChunkManager;
|
|
|
|
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
|
|
|
import net.minecraftforge.common.ForgeChunkManager.Type;
|
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.core.AppEng;
|
|
|
|
import appeng.tile.AEBaseTile;
|
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
|
|
|
|
public class TileChunkLoader extends AEBaseTile
|
|
|
|
{
|
|
|
|
|
|
|
|
boolean requestTicket = true;
|
|
|
|
Ticket ct;
|
|
|
|
|
|
|
|
class ChunkLoaderHandler extends AETileEventHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
public ChunkLoaderHandler() {
|
2014-01-26 07:44:50 +01:00
|
|
|
super( TileEventType.TICK );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Tick()
|
|
|
|
{
|
|
|
|
if ( requestTicket )
|
|
|
|
{
|
|
|
|
requestTicket = false;
|
|
|
|
initTicket();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
public TileChunkLoader() {
|
|
|
|
addNewHandler( new ChunkLoaderHandler() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void initTicket()
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ct = ForgeChunkManager.requestTicket( AppEng.instance, worldObj, Type.NORMAL );
|
|
|
|
|
|
|
|
if ( ct == null )
|
|
|
|
{
|
|
|
|
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
|
|
|
|
if ( server != null )
|
|
|
|
{
|
|
|
|
List<EntityPlayerMP> pl = server.getConfigurationManager().playerEntityList;
|
|
|
|
for (EntityPlayerMP p : pl)
|
|
|
|
{
|
|
|
|
p.addChatMessage( "Can't chunk load.." );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AELog.info( "New Ticket " + ct.toString() );
|
|
|
|
ForgeChunkManager.forceChunk( ct, new ChunkCoordIntPair( xCoord >> 4, zCoord >> 4 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void invalidate()
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
AELog.info( "Released Ticket " + ct.toString() );
|
|
|
|
ForgeChunkManager.releaseTicket( ct );
|
|
|
|
}
|
|
|
|
}
|