Java Code Examples for net.minecraftforge.event.world.ChunkEvent#Unload

The following examples show how to use net.minecraftforge.event.world.ChunkEvent#Unload . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LookingGlassForgeEventHandler.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload event) {
	if (!event.world.isRemote) return;
	Chunk chunk = event.getChunk();
	// When we unload a chunk client side, we want to make sure that any view entities clean up. Not strictly necessary, but a good practice.
	// I don't trust vanilla to unload entity references quickly/correctly/completely.
	for (int i = 0; i < chunk.entityLists.length; ++i) {
		List<Entity> list = chunk.entityLists[i];
		for (Entity entity : list) {
			if (entity instanceof EntityPortal) ((EntityPortal) entity).releaseActiveView();
		}
	}
}
 
Example 2
Source File: MovementScheduler.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload event) {

    if (event.world.isRemote)
        return;

    for (Object o : event.getChunk().chunkTileEntityMap.values()) {
        TileEntity te = (TileEntity) o;
        if (te instanceof TileMotor) {
            ((TileMotor) te).onUnload();
        }
    }
}
 
Example 3
Source File: WorldExtensionManager.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onChunkUnLoad(ChunkEvent.Unload event)
{
    if(event.getChunk() instanceof EmptyChunk)
        return;
    
    for(WorldExtension extension : worldMap.get(event.world))
        extension.unloadChunk(event.getChunk());
    
    if(event.world.isRemote)
        removeChunk(event.world, event.getChunk());
}
 
Example 4
Source File: TickableWorldPipeNetEventHandler.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public static void onChunkUnload(ChunkEvent.Unload event) {
    getPipeNetsForWorld(event.getWorld()).forEach(it -> it.onChunkUnloaded(event.getChunk()));
}
 
Example 5
Source File: EventHandler.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload event){
    if(!event.getWorld().isRemote) {
        RailNetworkManager.getInstance(event.getWorld().isRemote).onChunkUnload(event.getChunk());
    }
}
 
Example 6
Source File: ChunkLoadHandler.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload event)
{
	if(!event.getWorld().isRemote && event.getWorld().provider.getDimension() == 0)
	{
		BlockPos chunkWorldPos = new BlockPos(event.getChunk().xPosition * 16, 0, event.getChunk().zPosition * 16);
		IslandMap map = Core.getMapForWorld(event.getWorld(), chunkWorldPos);

		Point islandPos = new Point(chunkWorldPos.getX(), chunkWorldPos.getZ()).toIslandCoord();
		AxisAlignedBB chunkAABB = new AxisAlignedBB(islandPos.getX(), 0, islandPos.getZ(), islandPos.getX()+16, 1, islandPos.getZ()+16);
		Center temp = map.getClosestCenter(islandPos);

		ArrayList<Center> genList = new ArrayList<Center>();
		genList.add(temp);
		genList.addAll(temp.neighbors);

		if(loadedCentersMap.containsKey(map.getParams().getCantorizedID()))
		{
			ArrayList<Center> loaded = loadedCentersMap.get(map.getParams().getCantorizedID());
			for(Center c : genList)
			{	
				AxisAlignedBB aabb = c.getAABB();
				boolean intersect =aabb.intersectsWith(chunkAABB);
				if(intersect && loaded.contains(c) )
				{
					loaded.remove(c);
					ArrayList<Herd> herdsToUnload = map.getIslandData().wildlifeManager.getHerdsInCenter(c);
					for(Herd h : herdsToUnload)
					{
						h.setUnloaded();
						for(VirtualAnimal animal : h.getVirtualAnimals())
						{
							if(animal.getEntity() == null)
							{
								animal.setUnloaded();
								continue;
							}
							Predicate<Entity> predicate = Predicates.<Entity>and(EntitySelectors.NOT_SPECTATING, EntitySelectors.notRiding(animal.getEntity()));
							Entity closestEntity = animal.getEntity().world.getClosestPlayer(animal.getEntity().posX, animal.getEntity().posY, animal.getEntity().posZ, 100D, predicate);
							if(closestEntity == null)
							{
								animal.getEntity().setDead();
								animal.setUnloaded();
							}
						}
					}
				}
			}
		}


	}
}
 
Example 7
Source File: SemiBlockManager.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onChunkUnLoad(ChunkEvent.Unload event){
    if(!event.world.isRemote) {
        chunksMarkedForRemoval.add(event.getChunk());
    }
}
 
Example 8
Source File: EventHandler.java    From mapwriter with MIT License 4 votes vote down vote up
@SubscribeEvent
public void eventChunkUnload(ChunkEvent.Unload event){
	if(event.world.isRemote){
		this.mw.onChunkUnload(event.getChunk());
	}
}