Search in sources :

Example 26 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project Almura by AlmuraDev.

the class OBJBakedModel method createParticleSpriteFor.

private TextureAtlasSprite createParticleSpriteFor(final Face face, final TextureAtlasSprite diffuseSprite) {
    /*
         * 0: (0, 0)       3: (0, 1)
         *
         *
         * 1: (1, 0)       2: (1, 1)
         */
    final TextureAtlasSprite particleSprite = new TextureAtlasSprite(diffuseSprite.getIconName());
    particleSprite.copyFrom(diffuseSprite);
    final VertexTextureCoordinate vt1 = face.getVertices().get(0).getTextureCoordinate().orElse(null);
    final VertexTextureCoordinate vt3 = face.getVertices().get(2).getTextureCoordinate().orElse(null);
    final float u1;
    final float u2;
    final float v1;
    final float v2;
    if (vt1 != null) {
        u1 = particleSprite.getInterpolatedU(vt1.getU() * 16f);
        v1 = particleSprite.getInterpolatedV((1 - vt1.getV()) * 16f);
    } else {
        u1 = 0f;
        v1 = 0f;
    }
    if (vt3 != null) {
        u2 = particleSprite.getInterpolatedU(vt3.getU() * 16f);
        v2 = particleSprite.getInterpolatedV((1 - vt3.getV()) * 16f);
    } else {
        u2 = 1f;
        v2 = 1f;
    }
    final IMixinTextureAtlasSprite mixinSprite = (IMixinTextureAtlasSprite) particleSprite;
    mixinSprite.setMinU(u1);
    mixinSprite.setMaxU(u2);
    mixinSprite.setMinV(v1);
    mixinSprite.setMaxV(v2);
    return particleSprite;
}
Also used : IMixinTextureAtlasSprite(com.almuradev.content.mixin.iface.IMixinTextureAtlasSprite) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) VertexTextureCoordinate(com.almuradev.content.model.obj.geometry.VertexTextureCoordinate) IMixinTextureAtlasSprite(com.almuradev.content.mixin.iface.IMixinTextureAtlasSprite)

Example 27 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project MinecraftForge by MinecraftForge.

the class OBJModel method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap.Builder<String, TextureAtlasSprite> builder = ImmutableMap.builder();
    builder.put(ModelLoader.White.LOCATION.toString(), ModelLoader.White.INSTANCE);
    TextureAtlasSprite missing = bakedTextureGetter.apply(new ResourceLocation("missingno"));
    for (Map.Entry<String, Material> e : matLib.materials.entrySet()) {
        if (e.getValue().getTexture().getTextureLocation().getResourcePath().startsWith("#")) {
            FMLLog.severe("OBJLoader: Unresolved texture '%s' for obj model '%s'", e.getValue().getTexture().getTextureLocation().getResourcePath(), modelLocation);
            builder.put(e.getKey(), missing);
        } else {
            builder.put(e.getKey(), bakedTextureGetter.apply(e.getValue().getTexture().getTextureLocation()));
        }
    }
    builder.put("missingno", missing);
    return new OBJBakedModel(this, state, format, builder.build());
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 28 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project MinecraftForge by MinecraftForge.

the class ItemLayerModel method bake.

public IBakedModel bake(IModelState state, final VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    Optional<TRSRTransformation> transform = state.apply(Optional.<IModelPart>absent());
    for (int i = 0; i < textures.size(); i++) {
        TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
        builder.addAll(getQuadsForSprite(i, sprite, format, transform));
    }
    TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? new ResourceLocation("missingno") : textures.get(0));
    ImmutableMap<TransformType, TRSRTransformation> map = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
    return new BakedItemModel(builder.build(), particle, map, overrides, null);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) ImmutableList(com.google.common.collect.ImmutableList) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)

Example 29 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project MinecraftForge by MinecraftForge.

the class ModelDynBucket method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<TransformType, TRSRTransformation> transformMap = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
    // if the fluid is a gas wi manipulate the initial state to be rotated 180° to turn it upside down
    if (flipGas && fluid != null && fluid.isGaseous()) {
        state = new ModelStateComposition(state, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(null, new Quat4f(0, 0, 1, 0), null, null)));
    }
    TRSRTransformation transform = state.apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity());
    TextureAtlasSprite fluidSprite = null;
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    if (fluid != null) {
        fluidSprite = bakedTextureGetter.apply(fluid.getStill());
    }
    if (baseLocation != null) {
        // build base (insidest)
        IBakedModel model = (new ItemLayerModel(ImmutableList.of(baseLocation))).bake(state, format, bakedTextureGetter);
        builder.addAll(model.getQuads(null, null, 0));
    }
    if (liquidLocation != null && fluidSprite != null) {
        TextureAtlasSprite liquid = bakedTextureGetter.apply(liquidLocation);
        // build liquid layer (inside)
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, NORTH_Z_FLUID, EnumFacing.NORTH, fluid.getColor()));
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, SOUTH_Z_FLUID, EnumFacing.SOUTH, fluid.getColor()));
    }
    if (coverLocation != null) {
        // cover (the actual item around the other two)
        TextureAtlasSprite base = bakedTextureGetter.apply(coverLocation);
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, NORTH_Z_BASE, base, EnumFacing.NORTH, 0xffffffff));
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, SOUTH_Z_BASE, base, EnumFacing.SOUTH, 0xffffffff));
    }
    return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ImmutableList(com.google.common.collect.ImmutableList) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType) IModelPart(net.minecraftforge.common.model.IModelPart) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Quat4f(javax.vecmath.Quat4f) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Example 30 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project CodeChickenLib by Chicken-Bones.

the class RenderUtils method renderFluidGauge.

public static void renderFluidGauge(FluidStack stack, Rectangle4i rect, double density, double res) {
    if (!shouldRenderFluid(stack))
        return;
    int alpha = 255;
    if (stack.getFluid().isGaseous())
        alpha = (int) (fluidDensityToAlpha(density) * 255);
    else {
        int height = (int) (rect.h * density);
        rect.y += rect.h - height;
        rect.h = height;
    }
    TextureAtlasSprite tex = prepareFluidRender(stack, alpha);
    CCRenderState.startDrawing();
    renderFluidQuad(new Vector3(rect.x, rect.y + rect.h, 0), new Vector3(rect.w, 0, 0), new Vector3(0, -rect.h, 0), tex, res);
    CCRenderState.draw();
    postFluidRender();
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3(codechicken.lib.vec.Vector3)

Aggregations

TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)51 ResourceLocation (net.minecraft.util.ResourceLocation)9 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)8 EnumFacing (net.minecraft.util.EnumFacing)8 Tessellator (net.minecraft.client.renderer.Tessellator)6 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)5 IBlockState (net.minecraft.block.state.IBlockState)5 TileEntity (net.minecraft.tileentity.TileEntity)5 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)5 Minecraft (net.minecraft.client.Minecraft)4 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 Vector3f (org.lwjgl.util.vector.Vector3f)4 ImmutableList (com.google.common.collect.ImmutableList)3 HashMap (java.util.HashMap)3 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)3 TextureManager (net.minecraft.client.renderer.texture.TextureManager)3 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)3