@ThreadSafe public class ChunkHandler extends Object
Constructor and Description |
---|
ChunkHandler(TridentWorld world)
Creates a new chunk handler to manage the chunks of the provided world
|
Modifier and Type | Method and Description |
---|---|
boolean |
apply(ChunkLocation location,
java.util.function.Consumer<CRefCounter> consumer)
Obtains the chunk reference counter and applies a transformation function
|
CRefCounter |
get(ChunkLocation location)
Obtains the chunk reference counter at the specified location
|
TridentChunk |
get(ChunkLocation location,
boolean gen)
Obtains the chunk at the given location in the world, generating if given to do so
|
Set<ChunkLocation> |
keys()
Obtains the set of chunk locations that have already been loaded
|
void |
put(TridentChunk chunk)
Places a chunk into the collection of in-memory chunks
|
void |
releaseReferences(ChunkLocationSet chunkSet)
Releases the reference counters associated with the chunks that are specified in the set given
|
void |
remove(ChunkLocation location)
Manually removes the chunk from the collection without running any cleanup code
|
int |
size()
Obtains the amount of loaded chunks
|
boolean |
tryRemove(ChunkLocation location)
Attempts to remove the chunk from memory and save it
|
Collection<TridentChunk> |
values()
Obtains the chunks that have been loaded into memory
|
public ChunkHandler(TridentWorld world)
world
- the world to manage chunks forpublic void put(TridentChunk chunk)
chunk
- the chunk to addpublic TridentChunk get(ChunkLocation location, boolean gen)
location
- the location to obtain the chunkgen
- true
to generate a new chunk if no chunk existsnull
if it doesn't exist and gen
is falsepublic CRefCounter get(ChunkLocation location)
location
- the location to obtain the counternull
if it doesn't existpublic boolean apply(ChunkLocation location, java.util.function.Consumer<CRefCounter> consumer)
location
- the location or obtain the chunk reference counterconsumer
- the transformation functiontrue
to indicate that the chunk was successfully retrieved and transformedpublic boolean tryRemove(ChunkLocation location)
This method returns false
if:
location
- the location to remove the chunktrue
to signify that the collection was modified as a result of this operationpublic void releaseReferences(ChunkLocationSet chunkSet)
chunkSet
- the set of chunks to release references to, given that they exist in this cachepublic void remove(ChunkLocation location)
location
- the location to remove the chunk frompublic Set<ChunkLocation> keys()
public Collection<TridentChunk> values()
public int size()
Copyright © 2016. All rights reserved.