This commit is contained in:
themode 2020-10-10 06:07:28 +02:00
parent 1712ebd151
commit b118fc717b
3 changed files with 18 additions and 11 deletions

View File

@ -74,9 +74,11 @@ public class InstanceContainer extends Instance {
super(uniqueId, dimensionType);
this.storageLocation = storageLocation;
this.chunkLoader = new MinestomBasicChunkLoader(storageLocation);
// Set the default chunk supplier
// Set the default chunk loader which use the instance's StorageLocation to save and load chunks
setChunkLoader(new MinestomBasicChunkLoader(storageLocation));
// Set the default chunk supplier using DynamicChunk
setChunkSupplier((instance, biomes, chunkX, chunkZ) -> new DynamicChunk(instance, biomes, chunkX, chunkZ));
// Get instance data from the saved data if a StorageLocation is defined
@ -561,11 +563,11 @@ public class InstanceContainer extends Instance {
}
/**
* Change which type of {@link Chunk} implementation to use once one needs to be loaded
* Change which type of {@link Chunk} implementation to use once one needs to be loaded.
* <p>
* Uses {@link DynamicChunk} by default.
*
* @param chunkSupplier the new {@link ChunkSupplier} of this instance
* @param chunkSupplier the new {@link ChunkSupplier} of this instance, chunks need to be non-null
* @throws NullPointerException if {@code chunkSupplier} is null
*/
public void setChunkSupplier(ChunkSupplier chunkSupplier) {
@ -583,9 +585,9 @@ public class InstanceContainer extends Instance {
}
/**
* Assign a {@link SharedInstance} to this container
* Assign a {@link SharedInstance} to this container.
* <p>
* Only used by {@link InstanceManager}
* Only used by {@link InstanceManager}, mostly unsafe.
*
* @param sharedInstance the shared instance to assign to this container
*/

View File

@ -1,6 +1,7 @@
package net.minestom.server.instance.block;
import net.minestom.server.instance.block.rule.BlockPlacementRule;
import net.minestom.server.utils.validate.Check;
import java.util.HashMap;
import java.util.Map;
@ -20,10 +21,13 @@ public class BlockManager {
*
* @param customBlock the custom block to register
* @throws IllegalArgumentException if <code>customBlock</code> block id is not greater than 0
* @throws IllegalStateException if the id of <code>customBlock</code> is already registered
*/
public void registerCustomBlock(CustomBlock customBlock) {
final short id = customBlock.getCustomBlockId();
if (id <= 0) throw new IllegalArgumentException("Custom block ID must be greater than 0, got: " + id);
Check.argCondition(id <= 0, "Custom block ID must be greater than 0, got: " + id);
Check.stateCondition(customBlocksInternalId[id] != null, "a CustomBlock with the id " + id + " already exists");
final String identifier = customBlock.getIdentifier();
this.customBlocksInternalId[id] = customBlock;
this.customBlocksId.put(identifier, customBlock);
@ -37,7 +41,8 @@ public class BlockManager {
*/
public void registerBlockPlacementRule(BlockPlacementRule blockPlacementRule) {
final short id = blockPlacementRule.getBlockId();
if (id < 0) throw new IllegalArgumentException("Block ID must be >= 0, got: " + id);
Check.argCondition(id < 0, "Block ID must be >= 0, got: " + id);
this.placementRules[id] = blockPlacementRule;
}

View File

@ -5,19 +5,19 @@ import net.minestom.server.instance.Instance;
import net.minestom.server.world.biomes.Biome;
/**
* Used to customize which type of {@link Chunk} an implementation should use
* Used to customize which type of {@link Chunk} an implementation should use.
*/
@FunctionalInterface
public interface ChunkSupplier {
/**
* Create the {@link Chunk} object
* Create a {@link Chunk} object.
*
* @param instance the {@link Instance} assigned to the chunk
* @param biomes the biomes of the chunk, can be null
* @param chunkX the chunk X
* @param chunkZ the chunk Z
* @return a newly {@link Chunk} object
* @return a newly {@link Chunk} object, cannot be null
*/
Chunk getChunk(Instance instance, Biome[] biomes, int chunkX, int chunkZ);
}