mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-07 08:58:20 +01:00
Cleanup
This commit is contained in:
parent
1712ebd151
commit
b118fc717b
@ -74,9 +74,11 @@ public class InstanceContainer extends Instance {
|
|||||||
super(uniqueId, dimensionType);
|
super(uniqueId, dimensionType);
|
||||||
|
|
||||||
this.storageLocation = storageLocation;
|
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));
|
setChunkSupplier((instance, biomes, chunkX, chunkZ) -> new DynamicChunk(instance, biomes, chunkX, chunkZ));
|
||||||
|
|
||||||
// Get instance data from the saved data if a StorageLocation is defined
|
// 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>
|
* <p>
|
||||||
* Uses {@link DynamicChunk} by default.
|
* 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
|
* @throws NullPointerException if {@code chunkSupplier} is null
|
||||||
*/
|
*/
|
||||||
public void setChunkSupplier(ChunkSupplier chunkSupplier) {
|
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>
|
* <p>
|
||||||
* Only used by {@link InstanceManager}
|
* Only used by {@link InstanceManager}, mostly unsafe.
|
||||||
*
|
*
|
||||||
* @param sharedInstance the shared instance to assign to this container
|
* @param sharedInstance the shared instance to assign to this container
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.instance.block;
|
package net.minestom.server.instance.block;
|
||||||
|
|
||||||
import net.minestom.server.instance.block.rule.BlockPlacementRule;
|
import net.minestom.server.instance.block.rule.BlockPlacementRule;
|
||||||
|
import net.minestom.server.utils.validate.Check;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -20,10 +21,13 @@ public class BlockManager {
|
|||||||
*
|
*
|
||||||
* @param customBlock the custom block to register
|
* @param customBlock the custom block to register
|
||||||
* @throws IllegalArgumentException if <code>customBlock</code> block id is not greater than 0
|
* @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) {
|
public void registerCustomBlock(CustomBlock customBlock) {
|
||||||
final short id = customBlock.getCustomBlockId();
|
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();
|
final String identifier = customBlock.getIdentifier();
|
||||||
this.customBlocksInternalId[id] = customBlock;
|
this.customBlocksInternalId[id] = customBlock;
|
||||||
this.customBlocksId.put(identifier, customBlock);
|
this.customBlocksId.put(identifier, customBlock);
|
||||||
@ -37,7 +41,8 @@ public class BlockManager {
|
|||||||
*/
|
*/
|
||||||
public void registerBlockPlacementRule(BlockPlacementRule blockPlacementRule) {
|
public void registerBlockPlacementRule(BlockPlacementRule blockPlacementRule) {
|
||||||
final short id = blockPlacementRule.getBlockId();
|
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;
|
this.placementRules[id] = blockPlacementRule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,19 +5,19 @@ import net.minestom.server.instance.Instance;
|
|||||||
import net.minestom.server.world.biomes.Biome;
|
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
|
@FunctionalInterface
|
||||||
public interface ChunkSupplier {
|
public interface ChunkSupplier {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the {@link Chunk} object
|
* Create a {@link Chunk} object.
|
||||||
*
|
*
|
||||||
* @param instance the {@link Instance} assigned to the chunk
|
* @param instance the {@link Instance} assigned to the chunk
|
||||||
* @param biomes the biomes of the chunk, can be null
|
* @param biomes the biomes of the chunk, can be null
|
||||||
* @param chunkX the chunk X
|
* @param chunkX the chunk X
|
||||||
* @param chunkZ the chunk Z
|
* @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);
|
Chunk getChunk(Instance instance, Biome[] biomes, int chunkX, int chunkZ);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user