mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Add perf. improvments for Forge
This commit is contained in:
committed by
Matthew Miller
parent
8c17aab9c5
commit
27c7d488a2
@ -21,8 +21,12 @@ package com.sk89q.worldedit.internal.block;
|
||||
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public class BlockStateIdAccess {
|
||||
|
||||
private BlockStateIdAccess() {
|
||||
@ -40,7 +44,28 @@ public class BlockStateIdAccess {
|
||||
}
|
||||
|
||||
public static OptionalInt getBlockStateId(BlockState holder) {
|
||||
return blockStateStateId.getBlockStateId((BlockState) holder);
|
||||
return blockStateStateId.getBlockStateId(holder);
|
||||
}
|
||||
|
||||
public static @Nullable BlockState getBlockStateById(int id) {
|
||||
return id < blockStates.length ? blockStates[id] : null;
|
||||
}
|
||||
|
||||
private static BlockState[] blockStates = new BlockState[2 << 14];
|
||||
|
||||
public static void register(BlockState blockState) {
|
||||
OptionalInt id = getBlockStateId(blockState);
|
||||
if (id.isPresent()) {
|
||||
int i = id.getAsInt();
|
||||
while (i >= blockStates.length) {
|
||||
blockStates = Arrays.copyOf(blockStates, blockStates.length + blockStates.length >> 1);
|
||||
}
|
||||
BlockState existing = blockStates[i];
|
||||
checkState(existing == null || existing == blockState,
|
||||
"BlockState %s is using the same block ID (%s) as BlockState %s",
|
||||
blockState, i, existing);
|
||||
blockStates[i] = blockState;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
|
||||
BlockState initializeId(BlockRegistry registry) {
|
||||
this.internalId = registry.getInternalBlockStateId(this);
|
||||
BlockStateIdAccess.register(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -67,12 +67,4 @@ public interface BlockRegistry {
|
||||
*/
|
||||
OptionalInt getInternalBlockStateId(BlockState state);
|
||||
|
||||
/**
|
||||
* Retrieve a block state by its internal ID, if possible.
|
||||
*
|
||||
* @param id The internal ID
|
||||
* @return the block state, if available
|
||||
*/
|
||||
@Nullable
|
||||
BlockState getBlockStateByInternalId(int id);
|
||||
}
|
||||
|
@ -59,9 +59,4 @@ public class BundledBlockRegistry implements BlockRegistry {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockStateByInternalId(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user