Search in sources :

Example 1 with ChunkTicketManager

use of net.minecraftforge.common.ticket.ChunkTicketManager in project MinecraftForge by MinecraftForge.

the class FarmlandWaterManager method addCustomTicket.

/**
 * Adds a custom ticket.
 * Use {@link #addAABBTicket(Level, AABB)} if you just need a ticket that can water a certain area.
 * <br>
 * If you don't want to water the region anymore, call {@link SimpleTicket#invalidate()}. Also call this
 * when the region this is unloaded (e.g. your TE is unloaded or the block is removed), and validate once it is loaded
 * @param world The world where the region should be marked. Only server-side worlds are allowed
 * @param ticket Your ticket you want to have registered
 * @param masterChunk The chunk pos that is controls when the ticket may be unloaded. The ticket should originate from here.
 * @param additionalChunks The chunks in that this ticket wants to operate as well.
 * @return The ticket for your requested region.
 */
@SuppressWarnings("unchecked")
public static <T extends SimpleTicket<Vec3>> T addCustomTicket(Level world, T ticket, ChunkPos masterChunk, ChunkPos... additionalChunks) {
    Preconditions.checkArgument(!world.isClientSide, "Water region is only determined server-side");
    Map<ChunkPos, ChunkTicketManager<Vec3>> ticketMap = customWaterHandler.computeIfAbsent(world, id -> new MapMaker().weakValues().makeMap());
    ChunkTicketManager<Vec3>[] additionalTickets = new ChunkTicketManager[additionalChunks.length];
    for (int i = 0; i < additionalChunks.length; i++) additionalTickets[i] = ticketMap.computeIfAbsent(additionalChunks[i], ChunkTicketManager::new);
    ticket.setManager(ticketMap.computeIfAbsent(masterChunk, ChunkTicketManager::new), additionalTickets);
    ticket.validate();
    return ticket;
}
Also used : MapMaker(com.google.common.collect.MapMaker) ChunkTicketManager(net.minecraftforge.common.ticket.ChunkTicketManager) ChunkPos(net.minecraft.world.level.ChunkPos)

Aggregations

MapMaker (com.google.common.collect.MapMaker)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 ChunkTicketManager (net.minecraftforge.common.ticket.ChunkTicketManager)1