net.minecraftforge.common.ForgeChunkManager.Ticket Java Examples

The following examples show how to use net.minecraftforge.common.ForgeChunkManager.Ticket. 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: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addChunkTimeout(Ticket ticket, int dimension, int chunkX, int chunkZ, int timeout)
{
    String s = dimChunkCoordsToString(dimension, chunkX, chunkZ);

    DimChunkCoordTimeout dcct = this.timeOuts.get(s);
    if (dcct != null)
    {
        //System.out.println("addChunkTimeout(): re-setting");
        dcct.setTimeout(timeout);
    }
    else if (ticket != null)
    {
        //System.out.println("addChunkTimeout(): adding");
        this.timeOuts.put(s, new DimChunkCoordTimeout(ticket, dimension, new ChunkPos(chunkX, chunkZ), timeout));
    }
}
 
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: PlayerChunkViewerTracker.java    From ChickenChunks with MIT License 6 votes vote down vote up
public void writeTicketToPacket(PacketCustom packet, Ticket ticket, Collection<ChunkCoordIntPair> chunkSet)
{
    packet.writeInt(manager.ticketIDs.get(ticket));
    packet.writeString(ticket.getModId());
    String player = ticket.getPlayerName();
    packet.writeBoolean(player != null);
    if(player != null)
        packet.writeString(player);
    packet.writeByte(ticket.getType().ordinal());
    Entity entity = ticket.getEntity();
    if(entity != null)
        packet.writeInt(entity.getEntityId());
    packet.writeShort(chunkSet.size());
    for(ChunkCoordIntPair chunk : chunkSet)
    {
        packet.writeInt(chunk.chunkXPos);
        packet.writeInt(chunk.chunkZPos);
    }
    
    knownTickets.add(manager.ticketIDs.get(ticket));
}
 
Example #5
Source File: PlayerChunkViewerTracker.java    From ChickenChunks with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void loadDimension(WorldServer world)
{
    PacketCustom packet = new PacketCustom(channel, 2).compress();
    int dim = CommonUtils.getDimension(world);
    packet.writeInt(dim);
            
    List<Chunk> allchunks = world.theChunkProviderServer.loadedChunks;        
    packet.writeInt(allchunks.size());
    for(Chunk chunk : allchunks)
    {
        packet.writeInt(chunk.xPosition);
        packet.writeInt(chunk.zPosition);
    }
    
    Map<Ticket, Collection<ChunkCoordIntPair>> tickets = ForgeChunkManager.getPersistentChunksFor(world).inverse().asMap();
    packet.writeInt(tickets.size());
    for(Entry<Ticket, Collection<ChunkCoordIntPair>> entry : tickets.entrySet())
        writeTicketToPacket(packet, entry.getKey(), entry.getValue());
    
    packet.sendToPlayer(owner);
}
 
Example #6
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 #7
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean loadChunkForcedWithModTicket(int dimension, int chunkX, int chunkZ, int unloadDelay)
{
    // If the target chunk is already being loaded by something, we don't need another ticket/forced load for it
    // We just refresh the timeout, if the previous one is shorter that the new request
    if (this.hasChunkTimeout(dimension, chunkX, chunkZ))
    {
        if (this.refreshChunkTimeout(dimension, chunkX, chunkZ, unloadDelay, true))
        {
            return true;
        }
    }

    Ticket ticket = this.requestModTicket(dimension, unloadDelay != 0);

    return this.loadChunkForcedWithTicket(ticket, dimension, chunkX, chunkZ, unloadDelay);
}
 
Example #8
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean loadChunkForcedWithPlayerTicket(EntityPlayer player, int dimension, int chunkX, int chunkZ, int unloadDelay)
{
    // If the target chunk is already being loaded by something, we don't need another ticket/forced load for it
    // We just refresh the timeout, if the previous one is shorter that the new request
    if (this.hasChunkTimeout(dimension, chunkX, chunkZ))
    {
        if (this.refreshChunkTimeout(dimension, chunkX, chunkZ, unloadDelay, true))
        {
            return true;
        }
    }

    Ticket ticket = this.requestPlayerTicket(player, dimension, unloadDelay != 0);

    return this.loadChunkForcedWithTicket(ticket, dimension, chunkX, chunkZ, unloadDelay);
}
 
Example #9
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void removeTicket(Ticket ticket)
{
    if (ticket == null || ticket.world == null)
    {
        return;
    }

    if (ticket.isPlayerTicket())
    {
        UUID uuid = this.getPlayerUUIDFromTicket(ticket);
        if (ticket.world.provider != null && uuid != null)
        {
            this.playerTickets.get(uuid.toString() + "-" + ticket.world.provider.getDimension()).remove(ticket);
        }
    }
    else
    {
        this.modTickets.get(ticket.world).remove(ticket);
    }
}
 
Example #10
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ListMultimap<String, Ticket> playerTicketsLoaded(ListMultimap<String, Ticket> tickets, World world)
{
    Multimap<String, Ticket> persistentPlayerTickets = HashMultimap.create();
    LinkedListMultimap<String, Ticket> claimedTickets = LinkedListMultimap.create();

    //int i = 0;
    for (String player : tickets.keys())
    {
        //System.out.println("playerTicketsLoaded(): looping outer start: " + i);
        for (Ticket ticket : tickets.get(player))
        {
            if (ticket != null)
            {
                /*if (ticket.world != null && ticket.world.provider != null) { System.out.println("playerTicketsLoaded(): looping: " + i + " world: " + world + " dim: " + ticket.world.provider.getDimensionId()); }
                else { System.out.println("playerTicketsLoaded(): looping: " + i + " world: " + world); }
                ++i;*/

                NBTTagCompound nbt = ticket.getModData();

                // Only claim tickets that are used for persistent chunk loading
                if (nbt != null && nbt.getBoolean("Persistent"))
                {
                    //System.out.println("playerTicketsLoaded(): found persistent ticket");
                    persistentPlayerTickets.put(player, ticket);
                }
            }
        }
    }

    claimedTickets.putAll(persistentPlayerTickets);

    return claimedTickets;
}
 
Example #11
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world, int maxTicketCount)
{
    Set<Ticket> persistentTickets = new HashSet<Ticket>();
    LinkedList<Ticket> claimedTickets = new LinkedList<Ticket>();

    //int i = 0;
    for (Ticket ticket : tickets)
    {
        if (ticket == null)
        {
            continue;
        }

        /*
        if (ticket.world != null && ticket.world.provider != null)
        {
            System.out.println("List<Ticket> ticketsLoaded(): looping: " + i + " world: " + world + " dim: " + ticket.world.provider.getDimensionId());
        }
        else
        {
            System.out.println("List<Ticket> ticketsLoaded(): looping: " + i + " world: " + world);
        }
        i++;
        */

        NBTTagCompound nbt = ticket.getModData();

        // Only claim tickets that are used for persistent chunk loading
        if (nbt != null && nbt.getBoolean("Persistent"))
        {
            persistentTickets.add(ticket);
        }
    }

    claimedTickets.addAll(persistentTickets);

    return claimedTickets;
}
 
Example #12
Source File: PlayerChunkViewerManager.java    From ChickenChunks with MIT License 5 votes vote down vote up
public TicketChange(Ticket ticket, ChunkCoordIntPair chunk, boolean force)
{
    this.ticket = ticket;
    this.dimension = CommonUtils.getDimension(ticket.world);
    this.chunk = chunk;
    this.force = force;
}
 
Example #13
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void cleanChunks(WorldServer world) {
    int dim = CommonUtils.getDimension(world);
    int viewdist = ServerUtils.mc().getConfigurationManager().getViewDistance();

    HashSet<ChunkCoordIntPair> loadedChunks = new HashSet<ChunkCoordIntPair>();
    for (EntityPlayer player : ServerUtils.getPlayersInDimension(dim)) {
        int playerChunkX = (int) player.posX >> 4;
        int playerChunkZ = (int) player.posZ >> 4;

        for (int cx = playerChunkX - viewdist; cx <= playerChunkX + viewdist; cx++)
            for (int cz = playerChunkZ - viewdist; cz <= playerChunkZ + viewdist; cz++)
                loadedChunks.add(new ChunkCoordIntPair(cx, cz));
    }

    ImmutableSetMultimap<ChunkCoordIntPair, Ticket> persistantChunks = world.getPersistentChunks();
    PlayerManager manager = world.getPlayerManager();

    for (Chunk chunk : (List<Chunk>) world.theChunkProviderServer.loadedChunks) {
        ChunkCoordIntPair coord = chunk.getChunkCoordIntPair();
        if (!loadedChunks.contains(coord) && !persistantChunks.containsKey(coord) && world.theChunkProviderServer.chunkExists(coord.chunkXPos, coord.chunkZPos)) {
            PlayerInstance instance = manager.getOrCreateChunkWatcher(coord.chunkXPos, coord.chunkZPos, false);
            if (instance == null) {
                world.theChunkProviderServer.unloadChunksIfNotNearSpawn(coord.chunkXPos, coord.chunkZPos);
            } else {
                while (instance.playersWatchingChunk.size() > 0)
                    instance.removePlayer((EntityPlayerMP) instance.playersWatchingChunk.get(0));
            }
        }
    }

    if (ServerUtils.getPlayersInDimension(dim).isEmpty() && world.getPersistentChunks().isEmpty() && !DimensionManager.shouldLoadSpawn(dim)) {
        DimensionManager.unloadWorld(dim);
    }
}
 
Example #14
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public UUID getPlayerUUIDFromTicket(Ticket ticket)
{
    if (ticket == null)
    {
        return null;
    }

    OwnerData playerData = OwnerData.getOwnerDataFromNBT(ticket.getModData());
    if (playerData != null)
    {
        return playerData.getOwnerUUID();
    }

    return null;
}
 
Example #15
Source File: BaseVehicleEntity.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
public BaseVehicleEntity(World worldIn) {
	super(worldIn);
	storage = new ShipStorage(getOffset(), worldIn);
	Ticket tic = ForgeChunkManager.requestTicket(CommunityMod.INSTANCE,
			DimensionManager.getWorld(StorageDimReg.storageDimensionType.getId()), Type.NORMAL);
	loadTicket = tic;
}
 
Example #16
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DimChunkCoordTimeout(Ticket ticket, int dimension, ChunkPos cc, int timeout)
{
    this.ticket = ticket;
    this.dimension = dimension;
    this.chunkCoords = cc;
    this.timeout = timeout;
    this.timeoutFresh = timeout;
}
 
Example #17
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 5 votes vote down vote up
protected void remChunk(DimChunkCoord coord) {
    Ticket ticket = heldChunks.remove(coord);
    if (ticket == null)
        return;

    ForgeChunkManager.unforceChunk(ticket, coord.getChunkCoord());

    if (ticket.getChunkList().size() == ticket.getChunkListDepth() - 1) {
        Stack<Ticket> freeTickets = ticketsWithSpace.get(coord.dimension);
        if (freeTickets == null)
            ticketsWithSpace.put(coord.dimension, freeTickets = new Stack<Ticket>());
        freeTickets.push(ticket);
    }
}
 
Example #18
Source File: PlayerChunkViewerTracker.java    From ChickenChunks with MIT License 5 votes vote down vote up
public void addTicket(int dimension, Ticket ticket)
{
    PacketCustom packet = new PacketCustom(channel, 8);
    packet.writeInt(dimension);
    writeTicketToPacket(packet, ticket, ticket.getChunkList());
    
    packet.sendToPlayer(owner);
}
 
Example #19
Source File: ChunkLoadManager.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public ChunkLoadEntry(Ticket ticket){
    this.ticket = ticket;
    if(update()) {
        Log.warning("Chunkloading cart dead on init!");
    } else {
        Log.debug("Loaded chunkloader for cart at " + (ticket.getEntity() == null ? "[No entity]" : ticket.getEntity().getPosition().toString()));
    }
}
 
Example #20
Source File: ChunkLoadManager.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public boolean markAsChunkLoader(String chunkloadingPlayer, EntityMinecart cart){
    Ticket ticket = ForgeChunkManager.requestPlayerTicket(Signals.instance, chunkloadingPlayer, cart.world, Type.ENTITY);
    if(ticket != null) {
        ticket.bindEntity(cart);
        add(ticket);
        return true;
    } else {
        return false;
    }
}
 
Example #21
Source File: ChunkLoadManager.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
private void add(Ticket ticket){
    Validate.notNull(ticket);
    ChunkLoadEntry oldEntry = entries.put(ticket.getEntity(), new ChunkLoadEntry(ticket));
    if(oldEntry != null) {
        oldEntry.dispose();
    }
}
 
Example #22
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 4 votes vote down vote up
@Override
public void ticketsLoaded(List<Ticket> tickets, World world) {
}
 
Example #23
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 4 votes vote down vote up
@Override
public ListMultimap<String, Ticket> playerTicketsLoaded(ListMultimap<String, Ticket> tickets, World world) {
    return LinkedListMultimap.create();
}
 
Example #24
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 4 votes vote down vote up
@Override
public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world, int maxTicketCount) {
    return new LinkedList<Ticket>();
}
 
Example #25
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 4 votes vote down vote up
@Override
protected Ticket createTicket(int dimension) {
    return ForgeChunkManager.requestTicket(mod, DimensionManager.getWorld(dimension), Type.NORMAL);
}
 
Example #26
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 4 votes vote down vote up
@Override
public Ticket createTicket(int dimension) {
    return ForgeChunkManager.requestPlayerTicket(ChickenChunks.instance, username, DimensionManager.getWorld(dimension), Type.NORMAL);
}
 
Example #27
Source File: WorldEvents.java    From AdvancedRocketry with MIT License 2 votes vote down vote up
@Override
public void ticketsLoaded(List<Ticket> tickets, World world) {
	
}
 
Example #28
Source File: BlockyEntities.java    From CommunityMod with GNU Lesser General Public License v2.1 2 votes vote down vote up
@Override
public void ticketsLoaded(List<Ticket> tickets, World world) {
	
}
 
Example #29
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License votes vote down vote up
protected abstract Ticket createTicket(int dimension);