Search in sources :

Example 1 with BlockEntityType

use of net.minecraft.block.entity.BlockEntityType in project meteor-client by MeteorDevelopment.

the class StorageBlockListSetting method parseImpl.

@Override
protected List<BlockEntityType<?>> parseImpl(String str) {
    String[] values = str.split(",");
    List<BlockEntityType<?>> blocks = new ArrayList<>(values.length);
    try {
        for (String value : values) {
            BlockEntityType<?> block = parseId(Registry.BLOCK_ENTITY_TYPE, value);
            if (block != null)
                blocks.add(block);
        }
    } catch (Exception ignored) {
    }
    return blocks;
}
Also used : BlockEntityType(net.minecraft.block.entity.BlockEntityType) NbtString(net.minecraft.nbt.NbtString)

Example 2 with BlockEntityType

use of net.minecraft.block.entity.BlockEntityType in project Client by MatHax.

the class StorageBlockListSetting method parseImpl.

@Override
protected List<BlockEntityType<?>> parseImpl(String str) {
    String[] values = str.split(",");
    List<BlockEntityType<?>> blocks = new ArrayList<>(values.length);
    try {
        for (String value : values) {
            BlockEntityType<?> block = parseId(Registry.BLOCK_ENTITY_TYPE, value);
            if (block != null)
                blocks.add(block);
        }
    } catch (Exception ignored) {
    }
    return blocks;
}
Also used : BlockEntityType(net.minecraft.block.entity.BlockEntityType) NbtString(net.minecraft.nbt.NbtString)

Example 3 with BlockEntityType

use of net.minecraft.block.entity.BlockEntityType in project cem by dorianpb.

the class EntityModelLoaderMixin method loadResourceFromId.

private void loadResourceFromId(ResourceManager manager, Identifier id, String namespace) {
    if (!id.getNamespace().equals(namespace)) {
        return;
    }
    CemFairy.getLogger().info(id.toString());
    try (InputStream stream = manager.getResource(id).getInputStream()) {
        // initialize the file
        @SuppressWarnings("unchecked") LinkedTreeMap<String, Object> json = CemFairy.getGson().fromJson(new InputStreamReader(stream, StandardCharsets.UTF_8), LinkedTreeMap.class);
        if (json == null) {
            throw new Exception("Invalid File");
        }
        JemFile file = new JemFile(json, id, manager);
        String entityName = CemFairy.getEntityNameFromId(id);
        Optional<EntityType<?>> entityTypeOptional = EntityType.get(entityName);
        Optional<BlockEntityType<?>> blockEntityTypeOptional = Registry.BLOCK_ENTITY_TYPE.getOrEmpty(Identifier.tryParse(entityName));
        if (entityTypeOptional.isPresent()) {
            EntityType<? extends Entity> entityType = entityTypeOptional.get();
            if (CemFairy.isUnsupported(entityType)) {
                throw new Exception("Entity \"" + EntityType.getId(entityType) + "\" is unsupported!");
            }
            CemRegistryManager.addRegistry(entityType, file);
        } else if (blockEntityTypeOptional.isPresent()) {
            BlockEntityType<? extends BlockEntity> entityType = blockEntityTypeOptional.get();
            if (CemFairy.isUnsupported(entityType)) {
                throw new Exception("Block Entity \"" + BlockEntityType.getId(entityType) + "\" is unsupported!");
            }
            CemRegistryManager.addRegistry(entityType, file);
        } else {
            if (CemFairy.isUnsupported(entityName)) {
                throw new Exception("Unknown object \"" + entityName + "\"!");
            } else {
                CemRegistryManager.addRegistry(entityName, file);
            }
        }
    } catch (Exception exception) {
        CemFairy.getLogger().error("Error parsing " + id + ":");
        String message = exception.getMessage();
        CemFairy.getLogger().error(exception);
        if (message == null || message.trim().equals("")) {
            CemFairy.getLogger().error(exception.getStackTrace()[0]);
            CemFairy.getLogger().error(exception.getStackTrace()[1]);
            CemFairy.getLogger().error(exception.getStackTrace()[2]);
        }
    }
}
Also used : BlockEntityType(net.minecraft.block.entity.BlockEntityType) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JemFile(net.dorianpb.cem.internal.file.JemFile) EntityType(net.minecraft.entity.EntityType) BlockEntityType(net.minecraft.block.entity.BlockEntityType) BlockEntity(net.minecraft.block.entity.BlockEntity)

Aggregations

BlockEntityType (net.minecraft.block.entity.BlockEntityType)3 NbtString (net.minecraft.nbt.NbtString)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 JemFile (net.dorianpb.cem.internal.file.JemFile)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 EntityType (net.minecraft.entity.EntityType)1