Search in sources :

Example 6 with Ticket

use of net.minecraftforge.common.ForgeChunkManager.Ticket in project ArsMagica2 by Mithion.

the class AMChunkLoader method requestStaticChunkLoad.

/**
	 * Requests a static chunk load.  This is a non-moving chunk load, and will be assumed that the specified class will exist as a tile entity
	 *
	 * @param clazz the class to look for
	 * @param x     the x coordinate of the tile entity
	 * @param y     the y coordinate of the tile entity
	 * @param z     the z coordinate of the tile entity
	 * @param world The world object of the tile entity
	 */
public void requestStaticChunkLoad(Class clazz, int x, int y, int z, World world) {
    Ticket ticket = requestTicket(x, y, z, world);
    if (ticket == null) {
        LogHelper.warn("Unable to get a ticket for chunk loading!  The chunk identified by %d, %d is *not* loaded!", x, z);
        return;
    }
    NBTTagCompound compound = ticket.getModData();
    compound.setIntArray("StaticLoadCoords", new int[] { x, y, z });
    compound.setString("ChunkLoadClass", clazz.getName());
    ChunkCoordIntPair pair = new ChunkCoordIntPair(x >> 4, z >> 4);
    ForgeChunkManager.forceChunk(ticket, pair);
}
Also used : Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 7 with Ticket

use of net.minecraftforge.common.ForgeChunkManager.Ticket in project Railcraft by Railcraft.

the class TileWorldspike method setTicket.

public void setTicket(@Nullable Ticket t) {
    boolean changed = false;
    Ticket ticket = getTicket();
    if (ticket != t) {
        if (ticket != null) {
            if (ticket.world == worldObj) {
                for (ChunkPos chunk : ticket.getChunkList()) {
                    if (ForgeChunkManager.getPersistentChunksFor(worldObj).keys().contains(chunk))
                        ForgeChunkManager.unforceChunk(ticket, chunk);
                }
                ForgeChunkManager.releaseTicket(ticket);
            }
            tickets.remove(getUUID());
        }
        changed = true;
    }
    hasTicket = t != null;
    if (hasTicket)
        tickets.put(getUUID(), t);
    if (changed)
        sendUpdateToClient();
}
Also used : Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 8 with Ticket

use of net.minecraftforge.common.ForgeChunkManager.Ticket in project Railcraft by Railcraft.

the class ChunkManager method ticketsLoaded.

@Override
public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world, int maxTicketCount) {
    //        System.out.println("Callback 1");
    Set<Ticket> adminTickets = new HashSet<Ticket>();
    Set<Ticket> worldTickets = new HashSet<Ticket>();
    Set<Ticket> cartTickets = new HashSet<Ticket>();
    for (Ticket ticket : tickets) {
        Entity entity = ticket.getEntity();
        if (entity == null) {
            int y = ticket.getModData().getInteger("yCoord");
            String type = ticket.getModData().getString("type");
            if (y >= 0) {
                if (type.equals(WorldspikeVariant.ADMIN.getTag()))
                    adminTickets.add(ticket);
                else if (type.equals(WorldspikeVariant.STANDARD.getTag()))
                    worldTickets.add(ticket);
                else if (type.isEmpty())
                    worldTickets.add(ticket);
            }
        } else {
            if (entity instanceof EntityCartWorldspike) {
                //                    System.out.println("Claim Cart Ticket");
                cartTickets.add(ticket);
            }
        }
    }
    List<Ticket> claimedTickets = new LinkedList<Ticket>();
    claimedTickets.addAll(cartTickets);
    claimedTickets.addAll(adminTickets);
    claimedTickets.addAll(worldTickets);
    return claimedTickets;
}
Also used : Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityCartWorldspike(mods.railcraft.common.carts.EntityCartWorldspike) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 9 with Ticket

use of net.minecraftforge.common.ForgeChunkManager.Ticket in project Railcraft by Railcraft.

the class EntityCartWorldspike method requestTicket.

private boolean requestTicket() {
    if (meetsTicketRequirements()) {
        Ticket chunkTicket = getTicketFromForge();
        //noinspection ConstantConditions
        if (chunkTicket != null) {
            //                System.out.println("Request Ticket: " + worldObj.getClass().getSimpleName());
            chunkTicket.getModData();
            chunkTicket.setChunkListDepth(MAX_CHUNKS);
            chunkTicket.bindEntity(this);
            setChunkTicket(chunkTicket);
            forceChunkLoading(chunkCoordX, chunkCoordZ);
            return true;
        }
    }
    return false;
}
Also used : Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket)

Aggregations

Ticket (net.minecraftforge.common.ForgeChunkManager.Ticket)9 TileEntity (net.minecraft.tileentity.TileEntity)3 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)3 EntityCartWorldspike (mods.railcraft.common.carts.EntityCartWorldspike)2 Entity (net.minecraft.entity.Entity)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 GenericRailTransport (ebf.tim.entities.GenericRailTransport)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 TileWorldspike (mods.railcraft.common.blocks.machine.worldspike.TileWorldspike)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1