Java Code Examples for net.minecraftforge.common.ForgeChunkManager#forceChunk()

The following examples show how to use net.minecraftforge.common.ForgeChunkManager#forceChunk() . 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: ChunkLoaderManager.java    From ChickenChunks with MIT License 6 votes vote down vote up
protected void addChunk(DimChunkCoord coord) {
    if (heldChunks.containsKey(coord))
        return;

    Stack<Ticket> freeTickets = ticketsWithSpace.get(coord.dimension);
    if (freeTickets == null)
        ticketsWithSpace.put(coord.dimension, freeTickets = new Stack<Ticket>());

    Ticket ticket;
    if (freeTickets.isEmpty())
        freeTickets.push(ticket = createTicket(coord.dimension));
    else
        ticket = freeTickets.peek();

    ForgeChunkManager.forceChunk(ticket, coord.getChunkCoord());
    heldChunks.put(coord, ticket);
    if (ticket.getChunkList().size() == ticket.getChunkListDepth() && !freeTickets.isEmpty())
        freeTickets.pop();
}
 
Example 2
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void ticketsLoaded(List<Ticket> tickets, World world)
{
    for (Ticket ticket : tickets)
    {
        //System.out.println("void ticketsLoaded(): looping tickets");
        if (ticket != null)
        {
            for (ChunkPos chunk : ticket.getChunkList())
            {
                //System.out.println("void ticketsLoaded(): forcing chunk: " + chunk + " in dimension: " + ticket.world.provider.getDimensionId());
                ForgeChunkManager.forceChunk(ticket, chunk);
            }
        }
    }
}
 
Example 3
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean loadChunkForcedWithTicket(Ticket ticket, int dimension, int chunkX, int chunkZ, int unloadDelay)
{
    if (ticket == null)
    {
        EnderUtilities.logger.warn("loadChunkForcedWithTicket(): ticket == null");
        return false;
    }

    ForgeChunkManager.forceChunk(ticket, new ChunkPos(chunkX, chunkZ));
    if (unloadDelay > 0)
    {
        //System.out.println("loadChunkForcedWithTicket() adding timeout: " + unloadDelay);
        this.addChunkTimeout(ticket, dimension, chunkX, chunkZ, unloadDelay);
    }

    return this.loadChunkWithoutForce(dimension, chunkX, chunkZ);
}
 
Example 4
Source File: TileRailgun.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void onLoad() {
	if(ticket == null) {
		ticket = ForgeChunkManager.requestTicket(AdvancedRocketry.instance, this.world, Type.NORMAL);
		if(ticket != null)
			ForgeChunkManager.forceChunk(ticket, new ChunkPos(getPos().getX() / 16 - (getPos().getX() < 0 ? 1 : 0), getPos().getZ() / 16 - (getPos().getZ() < 0 ? 1 : 0)));
	}
}
 
Example 5
Source File: TileSpaceLaser.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
/**
 * Checks to see if the situation for firing the laser exists... and changes the state accordingly
 */
public void checkCanRun() {
	//Laser requires lense, redstone power, not be jammed, and be in orbit and energy to function
	if(world.isBlockIndirectlyGettingPowered(getPos()) == 0 || !isAllowedToRun()) {
		if(laserSat.isAlive()) {
			laserSat.deactivateLaser();
		}

		setRunning(false);
	} else if(!laserSat.isAlive() && !finished && !laserSat.getJammed() && world.isBlockIndirectlyGettingPowered(getPos()) > 0 && canMachineSeeEarth()) {

		//Laser will be on at this point
		int orbitDimId = ((WorldProviderSpace)this.world.provider).getDimensionProperties(getPos()).getParentPlanet();
		if(orbitDimId == SpaceObjectManager.WARPDIMID)
			return;
		WorldServer orbitWorld = DimensionManager.getWorld(orbitDimId);

		if(orbitWorld == null) {
			DimensionManager.initDimension(orbitDimId);
			orbitWorld = DimensionManager.getWorld(orbitDimId);
			if(orbitWorld == null)
				return;
		}


		if(ticket == null) {
			ticket = ForgeChunkManager.requestTicket(AdvancedRocketry.instance, this.world, Type.NORMAL);
			if(ticket != null)
				ForgeChunkManager.forceChunk(ticket, new ChunkPos(getPos().getX() / 16 - (getPos().getX() < 0 ? 1 : 0), getPos().getZ() / 16 - (getPos().getZ() < 0 ? 1 : 0)));
		}

		setRunning(laserSat.activateLaser(orbitWorld, laserX, laserZ));
	}

	if(!this.world.isRemote)
		PacketHandler.sendToNearby(new PacketMachine(this, (byte)12), 128, pos, this.world.provider.getDimension());
}
 
Example 6
Source File: SatelliteLaser.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
/**
 * creates the laser and begins mining.  This can
 * fail if the chunk cannot be force loaded
 * @param world world to spawn the laser into
 * @param x x coord
 * @param z z coord
 * @return whether creating the laser is successful
 */
public boolean activateLaser(World world, int x, int z) {
	ticketLaser = ForgeChunkManager.requestTicket(AdvancedRocketry.instance, world, Type.NORMAL);
	
	if(ticketLaser != null) {
		ForgeChunkManager.forceChunk(ticketLaser, new ChunkPos(x >> 4, z >> 4));
		
		int y = 64;
		
		if(world.getChunkFromChunkCoords(x >> 4, z >> 4).isLoaded()) {
			int current = 0;
			for(int i = 0; i < 9; i++) {
				current = world.getTopSolidOrLiquidBlock(new BlockPos(x + (i % 3) - 1, 0xFF, z + (i / 3) - 1)).getY();
				if(current > y)
					y = current;
			}
			if(y < 1)
				y = 255;
		}
		else
			y = 255;
		
		laser = new EntityLaserNode(world, x, y, z);
		laser.forceSpawn = true;
		world.spawnEntity(laser);
		return true;
	}
	return false;
}
 
Example 7
Source File: TicketMap.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public void chunkLoad(TownBlock block) {
    ForgeChunkManager.Ticket ticket = get(block.getDim());
    NBTTagList list = ticket.getModData().getTagList("chunkCoords", Constants.NBT.TAG_COMPOUND);
    list.appendTag(block.toChunkPos().toNBTTagCompound());

    ForgeChunkManager.forceChunk(ticket, block.toChunkCoords());
}
 
Example 8
Source File: MyTownLoadingCallback.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@Override
public void ticketsLoaded(List<ForgeChunkManager.Ticket> tickets, World world) {
    for (ForgeChunkManager.Ticket ticket : tickets) {
        NBTTagList list = ticket.getModData().getTagList("chunkCoords", Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < list.tagCount(); i++) {
            NBTTagCompound chunkNBT = list.getCompoundTagAt(i);
            ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(chunkNBT.getInteger("x"), chunkNBT.getInteger("z")));
        }
    }
    MyTownLoadingCallback.tickets.addAll(tickets);
}