use of org.spongepowered.api.block.BlockState.Builder in project core by CubeEngine.
the class MaterialMatcher method buildBlockStateItems.
private Map<String, BlockState> buildBlockStateItems() {
Map<String, BlockState> blockStateItems = new HashMap<>();
Collection<BlockState> blocks = Sponge.getRegistry().getAllOf(BlockState.class);
// System.out.println("Loading Names for " + blocks.size() + " Blockstates");
for (BlockState blockState : blocks) {
try {
if (!blockState.getType().getItem().isPresent()) {
continue;
}
ItemStack item = ItemStack.builder().fromBlockState(blockState).build();
Builder state = BlockState.builder().blockType(item.getType().getBlock().get());
blockState.getKeys().stream().map(Key.class::cast).forEach(k -> {
Optional value = item.get(k);
if (value.isPresent()) {
state.add(k, value.get());
}
});
BlockState finalState = state.build();
/*
ItemStack.Builder builder = ItemStack.builder().itemType(finalState.getType().getItem().get());
blockState.getKeys().stream().map(Key.class::cast).forEach(
k -> {
Optional value = finalState.get(k);
if (value.isPresent())
{
builder.add(k, value.get());
}
});
*/
blockStateItems.put(finalState.getName(), finalState);
} catch (IllegalArgumentException | DataRegistrationNotFoundException ignored) {
}
}
return blockStateItems;
}
Aggregations