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)))));
}
}
}
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));
}
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);
}
}
}
Aggregations