Search in sources :

Example 1 with MultiVariant

use of net.minecraft.client.renderer.block.model.MultiVariant in project BCLib by paulevsGitch.

the class TripleTerrainBlock method getModelVariant.

@Override
@Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
    boolean isMiddle = isMiddle(blockState);
    String middle = isMiddle ? "_middle" : "";
    ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + middle);
    registerBlockModel(stateId, modelId, blockState, modelCache);
    if (isMiddle) {
        List<Variant> variants = Lists.newArrayList();
        for (BlockModelRotation rotation : BlockModelRotation.values()) {
            variants.add(new Variant(modelId, rotation.getRotation(), false, 1));
        }
        return new MultiVariant(variants);
    } else if (blockState.getValue(SHAPE) == TripleShape.TOP) {
        return new MultiVariant(Lists.newArrayList(new Variant(modelId, BlockModelRotation.X180_Y0.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y90.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y180.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y270.getRotation(), false, 1)));
    }
    return ModelsHelper.createRandomTopModel(modelId);
}
Also used : Variant(net.minecraft.client.renderer.block.model.Variant) MultiVariant(net.minecraft.client.renderer.block.model.MultiVariant) ResourceLocation(net.minecraft.resources.ResourceLocation) BlockModelRotation(net.minecraft.client.resources.model.BlockModelRotation) MultiVariant(net.minecraft.client.renderer.block.model.MultiVariant) Environment(net.fabricmc.api.Environment)

Example 2 with MultiVariant

use of net.minecraft.client.renderer.block.model.MultiVariant in project excavated_variants by lukebemish.

the class BlockStateAssembler method getInfoFromBlockstate.

private static Pair<BlockModelDefinition, List<ResourceLocation>> getInfoFromBlockstate(ResourceLocation oreRl, BlockModelDefinition.Context ctx) throws IOException {
    ResourceLocation oreBS = new ResourceLocation(oreRl.getNamespace(), "blockstates/" + oreRl.getPath() + ".json");
    InputStream oreBSIS;
    try {
        oreBSIS = ClientPrePackRepository.getResource(oreBS);
    } catch (IOException e) {
        oreBSIS = BackupFetcher.provideBlockstateFile(oreRl);
    }
    BlockModelDefinition oreBMD = BlockModelDefinition.fromStream(ctx, new BufferedReader(new InputStreamReader(oreBSIS, StandardCharsets.UTF_8)));
    if (!oreBMD.isMultiPart()) {
        Set<ResourceLocation> oreModels = new HashSet<>();
        for (Map.Entry<String, MultiVariant> e : oreBMD.getVariants().entrySet()) {
            oreModels.addAll(e.getValue().getDependencies());
        }
        List<ResourceLocation> oreTextures = new ArrayList<>();
        for (ResourceLocation mRl : oreModels) {
            ResourceLocation actual = new ResourceLocation(mRl.getNamespace(), "models/" + mRl.getPath() + ".json");
            InputStream is;
            try {
                is = ClientPrePackRepository.getResource(actual);
            } catch (IOException e) {
                is = BackupFetcher.provideBlockModelFile(mRl);
            }
            BlockModelParser map = GSON.fromJson(new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)), BlockModelParser.class);
            if (map.textures != null) {
                for (String i : map.textures.values()) {
                    ResourceLocation o = ResourceLocation.of(i, ':');
                    oreTextures.add(new ResourceLocation(o.getNamespace(), "textures/" + o.getPath() + ".png"));
                }
            }
        }
        return new Pair<>(oreBMD, oreTextures);
    }
    return null;
}
Also used : BlockModelDefinition(net.minecraft.client.renderer.block.model.BlockModelDefinition) MultiVariant(net.minecraft.client.renderer.block.model.MultiVariant) ResourceLocation(net.minecraft.resources.ResourceLocation) Pair(io.github.lukebemish.excavated_variants.util.Pair)

Aggregations

MultiVariant (net.minecraft.client.renderer.block.model.MultiVariant)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 Pair (io.github.lukebemish.excavated_variants.util.Pair)1 Environment (net.fabricmc.api.Environment)1 BlockModelDefinition (net.minecraft.client.renderer.block.model.BlockModelDefinition)1 Variant (net.minecraft.client.renderer.block.model.Variant)1 BlockModelRotation (net.minecraft.client.resources.model.BlockModelRotation)1