Search in sources :

Example 31 with TextureMap

use of net.minecraft.client.renderer.texture.TextureMap in project Charset by CharsetMC.

the class CharsetTweakUnifyColors method recolorTextures.

private void recolorTextures(TextureMap map, String prefix) {
    ResourceLocation source = new ResourceLocation(prefix + "white");
    for (int i = 0; i < 16; i++) {
        String s = ColorUtils.getUnderscoredSuffix(EnumDyeColor.byMetadata(i));
        ResourceLocation target = new ResourceLocation(prefix + s);
        if (prefix.contains("hardened_clay")) {
            BufferedImage image = RenderUtils.getTextureImage(new ResourceLocation("minecraft:blocks/hardened_clay"));
            BufferedImage imageGrayscale = toGrayscale(image);
            int[] imageData = computeMinMaxData(image);
            int[] imageGrayData = computeMinMaxData(imageGrayscale);
            int delta = imageGrayData[3] - imageGrayData[7];
            final float divisor = delta > 5 ? (float) delta / 5.0f : 1.0f;
            final int value2 = colorMultiplier(prefix, EnumDyeColor.byMetadata(i));
            map.setTextureEntry(new PixelOperationSprite(target.toString(), source, (getter, x, y, value) -> {
                int out = 0xFF000000;
                for (int coff = 0; coff < 24; coff += 8) {
                    int v1 = (((imageGrayscale.getRGB(x, y) >> coff) & 0xFF) * 255 / imageGrayData[coff >> 3]) - 0xFF;
                    v1 /= divisor;
                    int v2 = ((value2 >> coff) & 0xFF) + v1;
                    if (v2 < 0)
                        v2 = 0;
                    if (v2 > 255)
                        v2 = 255;
                    int nonTintedOut = (v2 & 0xFF);
                    int tintedOut = nonTintedOut * imageData[8 + (coff >> 3)] / imageData[0 + 3];
                    out |= Math.round((nonTintedOut + tintedOut + (tintedOut / 2)) / 2.5f) << coff;
                }
                return out;
            }));
        } else if (i > 0) {
            // skip white for non-clay
            map.setTextureEntry(new PixelOperationSprite(target.toString(), source, PixelOperationSprite.multiply(colorMultiplier(prefix, EnumDyeColor.byMetadata(i)))));
        }
    }
}
Also used : Arrays(java.util.Arrays) BufferedImage(java.awt.image.BufferedImage) TextureMap(net.minecraft.client.renderer.texture.TextureMap) ModuleProfile(pl.asie.charset.lib.loader.ModuleProfile) ColorUtils(pl.asie.charset.lib.utils.ColorUtils) RenderUtils(pl.asie.charset.lib.utils.RenderUtils) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) EnumDyeColor(net.minecraft.item.EnumDyeColor) Side(net.minecraftforge.fml.relauncher.Side) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) ColorPaletteParser(pl.asie.charset.lib.resources.ColorPaletteParser) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) CharsetModule(pl.asie.charset.lib.loader.CharsetModule) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedImage(java.awt.image.BufferedImage)

Example 32 with TextureMap

use of net.minecraft.client.renderer.texture.TextureMap in project ForestryMC by ForestryMC.

the class ModelDecorativeLeaves method bakeBlock.

@Override
protected void bakeBlock(BlockDecorativeLeaves block, TreeDefinition treeDefinition, IModelBaker baker, boolean inventory) {
    TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
    ITreeGenome genome = treeDefinition.getGenome();
    IAlleleTreeSpecies species = genome.getPrimary();
    ILeafSpriteProvider leafSpriteProvider = species.getLeafSpriteProvider();
    ResourceLocation leafSpriteLocation = leafSpriteProvider.getSprite(false, Proxies.render.fancyGraphicsEnabled());
    TextureAtlasSprite leafSprite = map.getAtlasSprite(leafSpriteLocation.toString());
    // Render the plain leaf block.
    baker.addBlockModel(null, leafSprite, BlockAbstractLeaves.FOLIAGE_COLOR_INDEX);
    // Render overlay for fruit leaves.
    ResourceLocation fruitSpriteLocation = genome.getFruitProvider().getDecorativeSprite();
    if (fruitSpriteLocation != null) {
        TextureAtlasSprite fruitSprite = map.getAtlasSprite(fruitSpriteLocation.toString());
        baker.addBlockModel(null, fruitSprite, BlockAbstractLeaves.FRUIT_COLOR_INDEX);
    }
    // Set the particle sprite
    baker.setParticleSprite(leafSprite);
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) TextureMap(net.minecraft.client.renderer.texture.TextureMap) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) ILeafSpriteProvider(forestry.api.arboriculture.ILeafSpriteProvider) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 33 with TextureMap

use of net.minecraft.client.renderer.texture.TextureMap in project ForestryMC by ForestryMC.

the class ModelLeaves method getWorldKey.

@Override
protected Key getWorldKey(IBlockState state) {
    IExtendedBlockState stateExtended = (IExtendedBlockState) state;
    IBlockAccess world = stateExtended.getValue(UnlistedBlockAccess.BLOCKACCESS);
    BlockPos pos = stateExtended.getValue(UnlistedBlockPos.POS);
    boolean fancy = Proxies.render.fancyGraphicsEnabled();
    TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
    if (world == null || pos == null) {
        return createEmptyKey(map, fancy);
    }
    TileLeaves tile = TileUtil.getTile(world, pos, TileLeaves.class);
    if (tile == null) {
        return createEmptyKey(map, fancy);
    }
    ResourceLocation leafLocation = tile.getLeaveSprite(fancy);
    ResourceLocation fruitLocation = tile.getFruitSprite();
    return new Key(map.getAtlasSprite(leafLocation.toString()), fruitLocation != null ? map.getAtlasSprite(fruitLocation.toString()) : null, fancy);
}
Also used : TextureMap(net.minecraft.client.renderer.texture.TextureMap) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) TileLeaves(forestry.arboriculture.tiles.TileLeaves) ResourceLocation(net.minecraft.util.ResourceLocation) IBlockAccess(net.minecraft.world.IBlockAccess) BlockPos(net.minecraft.util.math.BlockPos) UnlistedBlockPos(forestry.core.blocks.properties.UnlistedBlockPos)

Example 34 with TextureMap

use of net.minecraft.client.renderer.texture.TextureMap in project ForestryMC by ForestryMC.

the class ModelLeaves method getInventoryKey.

@Override
protected Key getInventoryKey(ItemStack itemStack) {
    TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
    TileLeaves leaves = new TileLeaves();
    if (itemStack.getTagCompound() != null) {
        leaves.readFromNBT(itemStack.getTagCompound());
    } else {
        leaves.setTree(TreeRoot.treeTemplates.get(0));
    }
    boolean fancy = Proxies.render.fancyGraphicsEnabled();
    ResourceLocation leafLocation = leaves.getLeaveSprite(fancy);
    ResourceLocation fruitLocation = leaves.getFruitSprite();
    return new Key(map.getAtlasSprite(leafLocation.toString()), fruitLocation != null ? map.getAtlasSprite(fruitLocation.toString()) : null, fancy);
}
Also used : TextureMap(net.minecraft.client.renderer.texture.TextureMap) TileLeaves(forestry.arboriculture.tiles.TileLeaves) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 35 with TextureMap

use of net.minecraft.client.renderer.texture.TextureMap in project ForestryMC by ForestryMC.

the class BlockBase method registerSprites.

@SideOnly(Side.CLIENT)
@Override
public void registerSprites(ITextureManager manager) {
    IMachineProperties<?> machineProperties = blockType.getMachineProperties();
    if (machineProperties instanceof IMachinePropertiesTesr) {
        TextureMap textureMapBlocks = Minecraft.getMinecraft().getTextureMapBlocks();
        String particleTextureLocation = ((IMachinePropertiesTesr) machineProperties).getParticleTextureLocation();
        textureMapBlocks.registerSprite(new ResourceLocation(particleTextureLocation));
    }
}
Also used : TextureMap(net.minecraft.client.renderer.texture.TextureMap) ResourceLocation(net.minecraft.util.ResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

TextureMap (net.minecraft.client.renderer.texture.TextureMap)107 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)54 ResourceLocation (net.minecraft.util.ResourceLocation)49 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)20 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)19 BlockPos (net.minecraft.util.math.BlockPos)13 Fluid (net.minecraftforge.fluids.Fluid)10 FluidStack (net.minecraftforge.fluids.FluidStack)9 Tessellator (net.minecraft.client.renderer.Tessellator)8 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)6 ILeafSpriteProvider (forestry.api.arboriculture.ILeafSpriteProvider)6 ITreeGenome (forestry.api.arboriculture.ITreeGenome)6 EnumFacing (net.minecraft.util.EnumFacing)6 File (java.io.File)5 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)5 TextureManager (net.minecraft.client.renderer.texture.TextureManager)5 World (net.minecraft.world.World)5 SideOnly (cpw.mods.fml.relauncher.SideOnly)4 IBlockState (net.minecraft.block.state.IBlockState)4 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)4