Search in sources :

Example 1 with PixelOperationSprite

use of pl.asie.charset.lib.render.sprite.PixelOperationSprite 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 2 with PixelOperationSprite

use of pl.asie.charset.lib.render.sprite.PixelOperationSprite in project Charset by CharsetMC.

the class ProxyClient method addCustomModels.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void addCustomModels(TextureStitchEvent.Pre event) {
    prismModel = RenderUtils.getModelWithTextures(new ResourceLocation("charset:block/laser_prism"), event.getMap());
    ResourceLocation torchOnLoc = new ResourceLocation("minecraft:blocks/torch_on");
    ResourceLocation torchCenterLoc = new ResourceLocation("charset:items/beam_torch_center");
    event.getMap().setTextureEntry(new PixelOperationSprite("charset:blocks/torch_base_generated", torchOnLoc, (getter, x, y, value) -> {
        TextureAtlasSprite torchOnSprite = getter.apply(torchOnLoc);
        TextureAtlasSprite torchCenterSprite = getter.apply(torchCenterLoc);
        int tcx = x * torchCenterSprite.getIconWidth() / torchOnSprite.getIconWidth();
        int tcy = y * torchCenterSprite.getIconHeight() / torchOnSprite.getIconHeight();
        int alpha = (torchCenterSprite.getFrameTextureData(0)[0][tcy * torchCenterSprite.getIconWidth() + tcx] >> 24) & 0xFF;
        return alpha > 0 ? 0 : value;
    }, torchOnLoc, torchCenterLoc));
}
Also used : SimpleMultiLayerBakedModel(pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) Properties(pl.asie.charset.lib.Properties) LaserRenderer(pl.asie.charset.module.optics.laser.system.LaserRenderer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MinecraftForgeClient(net.minecraftforge.client.MinecraftForgeClient) LaserTintHandler(pl.asie.charset.module.optics.laser.blocks.LaserTintHandler) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) Side(net.minecraftforge.fml.relauncher.Side) CommandCharset(pl.asie.charset.lib.command.CommandCharset) RegistryUtils(pl.asie.charset.lib.utils.RegistryUtils) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) ColorHandlerEvent(net.minecraftforge.client.event.ColorHandlerEvent) ModelLoader(net.minecraftforge.client.model.ModelLoader) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ModelTransformer(pl.asie.charset.lib.render.model.ModelTransformer) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) LaserColor(pl.asie.charset.api.laser.LaserColor) EnumFacing(net.minecraft.util.EnumFacing) SubCommandDebugLasersClient(pl.asie.charset.module.optics.laser.system.SubCommandDebugLasersClient) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IModel(net.minecraftforge.client.model.IModel) RenderUtils(pl.asie.charset.lib.utils.RenderUtils) IBlockState(net.minecraft.block.state.IBlockState) MinecraftForge(net.minecraftforge.common.MinecraftForge) Orientation(pl.asie.charset.lib.utils.Orientation) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ForgeHooksClient(net.minecraftforge.client.ForgeHooksClient) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with PixelOperationSprite

use of pl.asie.charset.lib.render.sprite.PixelOperationSprite in project Charset by CharsetMC.

the class ProxyClient method onTextureStitch.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onTextureStitch(TextureStitchEvent.Pre event) {
    GateRenderDefinitions.INSTANCE.load("simplelogic:gatedefs/base.json", SimpleLogicGates.logicDefinitions);
    for (ResourceLocation rs : SimpleLogicGates.logicClasses.keySet()) {
        Set<ResourceLocation> textures = new HashSet<>();
        Map<String, TIntObjectMap<String>> colorMasks = new HashMap<>();
        // step 1: gather colormasks
        int i = 0;
        for (GateRenderDefinitions.Layer layer : GateRenderDefinitions.INSTANCE.getGateDefinition(rs).layers) {
            if (layer.color_mask != null) {
                layer.texture = rs.getResourceDomain() + ":blocks/" + rs.getResourcePath() + "/layer_" + i;
                colorMasks.computeIfAbsent(layer.textureBase, (k) -> new TIntObjectHashMap<>()).put(Integer.parseInt(layer.color_mask, 16), layer.texture);
            }
            i++;
        }
        // step 2: gather textures
        GateRenderDefinitions.Definition def = GateRenderDefinitions.INSTANCE.getGateDefinition(rs);
        for (IModel model : def.getAllModels()) {
            textures.addAll(model.getTextures());
        }
        for (GateRenderDefinitions.Layer layer : GateRenderDefinitions.INSTANCE.getGateDefinition(rs).layers) {
            if (layer.texture != null) {
                textures.add(new ResourceLocation(layer.texture));
            }
        }
        // step 3: add colormasked textures
        for (String baseTexture : colorMasks.keySet()) {
            TIntObjectMap<String> resultingTextures = colorMasks.get(baseTexture);
            resultingTextures.forEachEntry((color, resultingTexture) -> {
                event.getMap().setTextureEntry(new PixelOperationSprite(resultingTexture, new ResourceLocation(baseTexture), ((getter, x, y, value) -> (value & 0xFFFFFF) == color ? -1 : 0)));
                textures.remove(new ResourceLocation(resultingTexture));
                return true;
            });
            event.getMap().setTextureEntry(new PixelOperationSprite(baseTexture, new ResourceLocation(baseTexture), (((getter, x, y, value) -> {
                if (resultingTextures.containsKey(value & 0xFFFFFF)) {
                    return 0;
                } else {
                    return value;
                }
            }))));
            textures.remove(new ResourceLocation(baseTexture));
        }
        // step 4: add non-colormasked textures
        for (ResourceLocation location : textures) {
            event.getMap().registerSprite(location);
        }
    }
}
Also used : ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectMap(gnu.trove.map.TIntObjectMap) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) Set(java.util.Set) GateRenderDefinitions(pl.asie.simplelogic.gates.render.GateRenderDefinitions) HashMap(java.util.HashMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IModel(net.minecraftforge.client.model.IModel) HashSet(java.util.HashSet) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) Side(net.minecraftforge.fml.relauncher.Side) RendererGate(pl.asie.simplelogic.gates.render.RendererGate) RegistryUtils(pl.asie.charset.lib.utils.RegistryUtils) Map(java.util.Map) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IModel(net.minecraftforge.client.model.IModel) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) GateRenderDefinitions(pl.asie.simplelogic.gates.render.GateRenderDefinitions) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectMap(gnu.trove.map.TIntObjectMap) HashSet(java.util.HashSet) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ResourceLocation (net.minecraft.util.ResourceLocation)3 TextureStitchEvent (net.minecraftforge.client.event.TextureStitchEvent)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 Side (net.minecraftforge.fml.relauncher.Side)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 PixelOperationSprite (pl.asie.charset.lib.render.sprite.PixelOperationSprite)3 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 ModelBakeEvent (net.minecraftforge.client.event.ModelBakeEvent)2 ModelRegistryEvent (net.minecraftforge.client.event.ModelRegistryEvent)2 IModel (net.minecraftforge.client.model.IModel)2 RegistryUtils (pl.asie.charset.lib.utils.RegistryUtils)2 RenderUtils (pl.asie.charset.lib.utils.RenderUtils)2 TIntObjectMap (gnu.trove.map.TIntObjectMap)1 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 BufferedImage (java.awt.image.BufferedImage)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1