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;
}
Aggregations