Search in sources :

Example 1 with ModelState

use of net.minecraft.client.resources.model.ModelState in project MinecraftForge by MinecraftForge.

the class DynamicBucketModel method bake.

@Override
public BakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ItemOverrides overrides, ResourceLocation modelLocation) {
    Material particleLocation = owner.isTexturePresent("particle") ? owner.resolveTexture("particle") : null;
    Material baseLocation = owner.isTexturePresent("base") ? owner.resolveTexture("base") : null;
    Material fluidMaskLocation = owner.isTexturePresent("fluid") ? owner.resolveTexture("fluid") : null;
    Material coverLocation = owner.isTexturePresent("cover") ? owner.resolveTexture("cover") : null;
    ModelState transformsFromModel = owner.getCombinedTransform();
    TextureAtlasSprite fluidSprite = fluid != Fluids.EMPTY ? spriteGetter.apply(ForgeHooksClient.getBlockMaterial(fluid.getAttributes().getStillTexture())) : null;
    TextureAtlasSprite coverSprite = (coverLocation != null && (!coverIsMask || baseLocation != null)) ? spriteGetter.apply(coverLocation) : null;
    ImmutableMap<TransformType, Transformation> transformMap = PerspectiveMapWrapper.getTransforms(new CompositeModelState(transformsFromModel, modelTransform));
    TextureAtlasSprite particleSprite = particleLocation != null ? spriteGetter.apply(particleLocation) : null;
    if (particleSprite == null)
        particleSprite = fluidSprite;
    if (particleSprite == null && !coverIsMask)
        particleSprite = coverSprite;
    // if the fluid is lighter than air, will manipulate the initial state to be rotated 180deg to turn it upside down
    if (flipGas && fluid != Fluids.EMPTY && fluid.getAttributes().isLighterThanAir()) {
        modelTransform = new SimpleModelState(modelTransform.getRotation().blockCornerToCenter().compose(new Transformation(null, new Quaternion(0, 0, 1, 0), null, null)).blockCenterToCorner());
    }
    Transformation transform = modelTransform.getRotation();
    ItemMultiLayerBakedModel.Builder builder = ItemMultiLayerBakedModel.builder(owner, particleSprite, new ContainedFluidOverrideHandler(overrides, bakery, owner, this), transformMap);
    if (baseLocation != null) {
        // build base (insidest)
        builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemLayerModel.getQuadsForSprites(ImmutableList.of(baseLocation), transform, spriteGetter));
    }
    if (fluidMaskLocation != null && fluidSprite != null) {
        TextureAtlasSprite templateSprite = spriteGetter.apply(fluidMaskLocation);
        if (templateSprite != null) {
            // build liquid layer (inside)
            int luminosity = applyFluidLuminosity ? fluid.getAttributes().getLuminosity() : 0;
            int color = tint ? fluid.getAttributes().getColor() : 0xFFFFFFFF;
            builder.addQuads(ItemLayerModel.getLayerRenderType(luminosity > 0), ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, NORTH_Z_FLUID, Direction.NORTH, color, 1, luminosity));
            builder.addQuads(ItemLayerModel.getLayerRenderType(luminosity > 0), ItemTextureQuadConverter.convertTexture(transform, templateSprite, fluidSprite, SOUTH_Z_FLUID, Direction.SOUTH, color, 1, luminosity));
        }
    }
    if (coverIsMask) {
        if (coverSprite != null && baseLocation != null) {
            TextureAtlasSprite baseSprite = spriteGetter.apply(baseLocation);
            builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemTextureQuadConverter.convertTexture(transform, coverSprite, baseSprite, NORTH_Z_COVER, Direction.NORTH, 0xFFFFFFFF, 2));
            builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemTextureQuadConverter.convertTexture(transform, coverSprite, baseSprite, SOUTH_Z_COVER, Direction.SOUTH, 0xFFFFFFFF, 2));
        }
    } else {
        if (coverSprite != null) {
            builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemTextureQuadConverter.genQuad(transform, 0, 0, 16, 16, NORTH_Z_COVER, coverSprite, Direction.NORTH, 0xFFFFFFFF, 2));
            builder.addQuads(ItemLayerModel.getLayerRenderType(false), ItemTextureQuadConverter.genQuad(transform, 0, 0, 16, 16, SOUTH_Z_COVER, coverSprite, Direction.SOUTH, 0xFFFFFFFF, 2));
        }
    }
    builder.setParticle(particleSprite);
    return builder.build();
}
Also used : Transformation(com.mojang.math.Transformation) Quaternion(com.mojang.math.Quaternion) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ModelState(net.minecraft.client.resources.model.ModelState) Material(net.minecraft.client.resources.model.Material) TransformType(net.minecraft.client.renderer.block.model.ItemTransforms.TransformType)

Example 2 with ModelState

use of net.minecraft.client.resources.model.ModelState in project MinecraftForge by MinecraftForge.

the class ModelLoaderRegistry method bakeHelper.

public static BakedModel bakeHelper(BlockModel blockModel, ModelBakery modelBakery, BlockModel otherModel, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation, boolean guiLight3d) {
    BakedModel model;
    IModelGeometry<?> customModel = blockModel.customData.getCustomGeometry();
    ModelState customModelState = blockModel.customData.getCustomModelState();
    if (customModelState != null)
        modelTransform = new CompositeModelState(modelTransform, customModelState, modelTransform.isUvLocked());
    if (customModel != null)
        model = customModel.bake(blockModel.customData, modelBakery, spriteGetter, modelTransform, blockModel.getOverrides(modelBakery, otherModel, spriteGetter), modelLocation);
    else {
        // handle vanilla item models here, since vanilla has a shortcut for them
        if (blockModel.getRootModel() == ModelBakery.GENERATION_MARKER) {
            model = ITEM_MODEL_GENERATOR.generateBlockModel(spriteGetter, blockModel).bake(modelBakery, blockModel, spriteGetter, modelTransform, modelLocation, guiLight3d);
        } else {
            model = blockModel.bakeVanilla(modelBakery, otherModel, spriteGetter, modelTransform, modelLocation, guiLight3d);
        }
    }
    if (customModelState != null && !model.doesHandlePerspectives())
        model = new PerspectiveMapWrapper(model, customModelState);
    return model;
}
Also used : BakedModel(net.minecraft.client.resources.model.BakedModel) ModelState(net.minecraft.client.resources.model.ModelState)

Example 3 with ModelState

use of net.minecraft.client.resources.model.ModelState in project MinecraftForge by MinecraftForge.

the class ModelLoaderRegistry method deserializeTransform.

public static Optional<ModelState> deserializeTransform(JsonDeserializationContext context, JsonElement transformData) {
    if (!transformData.isJsonObject()) {
        try {
            Transformation base = context.deserialize(transformData, Transformation.class);
            return Optional.of(new SimpleModelState(ImmutableMap.of(), base.blockCenterToCorner()));
        } catch (JsonParseException e) {
            throw new JsonParseException("transform: expected a string, object or valid base transformation, got: " + transformData);
        }
    } else {
        JsonObject transform = transformData.getAsJsonObject();
        EnumMap<ItemTransforms.TransformType, Transformation> transforms = Maps.newEnumMap(ItemTransforms.TransformType.class);
        deserializeTRSR(context, transforms, transform, "thirdperson", ItemTransforms.TransformType.THIRD_PERSON_RIGHT_HAND);
        deserializeTRSR(context, transforms, transform, "thirdperson_righthand", ItemTransforms.TransformType.THIRD_PERSON_RIGHT_HAND);
        deserializeTRSR(context, transforms, transform, "thirdperson_lefthand", ItemTransforms.TransformType.THIRD_PERSON_LEFT_HAND);
        deserializeTRSR(context, transforms, transform, "firstperson", ItemTransforms.TransformType.FIRST_PERSON_RIGHT_HAND);
        deserializeTRSR(context, transforms, transform, "firstperson_righthand", ItemTransforms.TransformType.FIRST_PERSON_RIGHT_HAND);
        deserializeTRSR(context, transforms, transform, "firstperson_lefthand", ItemTransforms.TransformType.FIRST_PERSON_LEFT_HAND);
        deserializeTRSR(context, transforms, transform, "head", ItemTransforms.TransformType.HEAD);
        deserializeTRSR(context, transforms, transform, "gui", ItemTransforms.TransformType.GUI);
        deserializeTRSR(context, transforms, transform, "ground", ItemTransforms.TransformType.GROUND);
        deserializeTRSR(context, transforms, transform, "fixed", ItemTransforms.TransformType.FIXED);
        int k = transform.entrySet().size();
        if (transform.has("matrix"))
            k--;
        if (transform.has("translation"))
            k--;
        if (transform.has("rotation"))
            k--;
        if (transform.has("scale"))
            k--;
        if (transform.has("post-rotation"))
            k--;
        if (transform.has("origin"))
            k--;
        if (k > 0) {
            throw new JsonParseException("transform: allowed keys: 'thirdperson', 'firstperson', 'gui', 'head', 'matrix', 'translation', 'rotation', 'scale', 'post-rotation', 'origin'");
        }
        Transformation base = Transformation.identity();
        if (!transform.entrySet().isEmpty()) {
            base = context.deserialize(transform, Transformation.class);
        }
        ModelState state = new SimpleModelState(Maps.immutableEnumMap(transforms), base);
        return Optional.of(state);
    }
}
Also used : Transformation(com.mojang.math.Transformation) ModelState(net.minecraft.client.resources.model.ModelState) ItemTransforms(net.minecraft.client.renderer.block.model.ItemTransforms)

Aggregations

ModelState (net.minecraft.client.resources.model.ModelState)3 Transformation (com.mojang.math.Transformation)2 Quaternion (com.mojang.math.Quaternion)1 ItemTransforms (net.minecraft.client.renderer.block.model.ItemTransforms)1 TransformType (net.minecraft.client.renderer.block.model.ItemTransforms.TransformType)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 BakedModel (net.minecraft.client.resources.model.BakedModel)1 Material (net.minecraft.client.resources.model.Material)1