Search in sources :

Example 1 with DataRegistrationNotFoundException

use of org.spongepowered.api.data.DataRegistrationNotFoundException 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;
}
Also used : BlockState(org.spongepowered.api.block.BlockState) Optional(java.util.Optional) HashMap(java.util.HashMap) Builder(org.spongepowered.api.block.BlockState.Builder) ItemStack(org.spongepowered.api.item.inventory.ItemStack) DataRegistrationNotFoundException(org.spongepowered.api.data.DataRegistrationNotFoundException)

Aggregations

HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 BlockState (org.spongepowered.api.block.BlockState)1 Builder (org.spongepowered.api.block.BlockState.Builder)1 DataRegistrationNotFoundException (org.spongepowered.api.data.DataRegistrationNotFoundException)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1