Make placementRules in BlockManager an array & add comments for methods

This commit is contained in:
Nesaak 2020-09-08 09:45:36 -04:00
parent e39e692cde
commit 1f078ed011

View File

@ -1,6 +1,5 @@
package net.minestom.server.instance.block;
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
import net.minestom.server.instance.block.rule.BlockPlacementRule;
import java.util.HashMap;
@ -14,17 +13,18 @@ public class BlockManager {
private Map<String, CustomBlock> customBlocksId = new HashMap<>();
// block id -> block placement rule
private Short2ObjectOpenHashMap<BlockPlacementRule> placementRules = new Short2ObjectOpenHashMap<>();
private BlockPlacementRule[] placementRules = new BlockPlacementRule[Short.MAX_VALUE];
/**
* Register a custom block
*
* @param customBlock the custom block to register
* @throws IllegalArgumentException if {@param customBlock} block id is negative
*/
public void registerCustomBlock(CustomBlock customBlock) {
if (customBlock.getCustomBlockId() < 0) throw new IllegalArgumentException("Custom block ID must be > 0, got: " + customBlock.getCustomBlockId());
final String identifier = customBlock.getIdentifier();
final short id = customBlock.getCustomBlockId();
if (id < 0) throw new IllegalArgumentException("Custom block ID must be > 0, got: " + id);
final String identifier = customBlock.getIdentifier();
this.customBlocksInternalId[id] = customBlock;
this.customBlocksId.put(identifier, customBlock);
}
@ -33,9 +33,12 @@ public class BlockManager {
* Register a block placement rule
*
* @param blockPlacementRule the block placement rule to register
* @throws IllegalArgumentException if {@param blockPlacementRule} block id is negative
*/
public void registerBlockPlacementRule(BlockPlacementRule blockPlacementRule) {
this.placementRules.put(blockPlacementRule.getBlockId(), blockPlacementRule);
final short id = blockPlacementRule.getBlockId();
if (id < 0) throw new IllegalArgumentException("Block ID must be > 0, got: " + id);
this.placementRules[id] = blockPlacementRule;
}
/**
@ -47,7 +50,7 @@ public class BlockManager {
public BlockPlacementRule getBlockPlacementRule(short blockStateId) {
final Block block = Block.fromStateId(blockStateId); // Convert block alternative
final short blockId = block.getBlockId();
return this.placementRules.get(blockId);
return this.placementRules[blockId];
}
/**