mirror of
https://github.com/GeyserMC/PackConverter.git
synced 2026-01-06 15:41:51 +00:00
Re-enable liquid transformer and add sheep
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
|
||||
package org.geysermc.pack.converter.converter.texture.transformer.bulk.type.block;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.geysermc.pack.converter.converter.texture.transformer.bulk.BulkTextureTransformer;
|
||||
import org.geysermc.pack.converter.converter.texture.transformer.bulk.BulkTransformContext;
|
||||
@@ -37,8 +38,8 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
// @AutoService(BulkTextureTransformer.class)
|
||||
public class LiquidConverter implements BulkTextureTransformer {
|
||||
@AutoService(BulkTextureTransformer.class)
|
||||
public class LiquidTransformer implements BulkTextureTransformer {
|
||||
private static final List<LiquidData> LIQUID = List.of(
|
||||
new LiquidData("block/lava_flow.png", "blocks/lava_flow.png", 32),
|
||||
new LiquidData("block/lava_still.png", "blocks/lava_still.png", 16),
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/PackConverter
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converter.texture.transformer.bulk.type.entity;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.geysermc.pack.converter.converter.texture.transformer.bulk.BulkTextureTransformer;
|
||||
import org.geysermc.pack.converter.converter.texture.transformer.bulk.BulkTransformContext;
|
||||
import org.geysermc.pack.converter.util.ImageUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import team.unnamed.creative.texture.Texture;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
@AutoService(BulkTextureTransformer.class)
|
||||
public class SheepTransformer implements BulkTextureTransformer {
|
||||
private static final String SHEEP = "entity/sheep/sheep.png";
|
||||
private static final String SHEEP_FUR = "entity/sheep/sheep_fur.png";
|
||||
|
||||
@Override
|
||||
public void transform(@NotNull BulkTransformContext context) throws IOException {
|
||||
Texture sheepTexture = context.poll(Key.key(Key.MINECRAFT_NAMESPACE, SHEEP));
|
||||
Texture sheepFurTexture = context.poll(Key.key(Key.MINECRAFT_NAMESPACE, SHEEP_FUR));
|
||||
|
||||
if (sheepTexture == null || sheepFurTexture == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.info(String.format("Converting sheep texture %s", SHEEP));
|
||||
|
||||
BufferedImage sheepImage = this.readImage(sheepTexture);
|
||||
BufferedImage sheepFurImage = this.readImage(sheepFurTexture);
|
||||
|
||||
int width = Math.max(sheepImage.getWidth(), sheepFurImage.getWidth());
|
||||
sheepImage = ImageUtil.ensureMinWidth(sheepImage, width);
|
||||
sheepFurImage = ImageUtil.ensureMinWidth(sheepFurImage, width);
|
||||
|
||||
BufferedImage newImage = new BufferedImage(sheepImage.getWidth(), sheepImage.getHeight() + sheepFurImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics g = newImage.getGraphics();
|
||||
|
||||
g.drawImage(sheepImage, 0, 0, null);
|
||||
|
||||
g.drawImage(sheepFurImage, 0, sheepImage.getHeight(), null);
|
||||
|
||||
for (int x = 0; x < newImage.getWidth(); x++) {
|
||||
for (int y = 0; y < sheepImage.getHeight(); y++) {
|
||||
Color c = new Color(newImage.getRGB(x, y), true);
|
||||
if (c.getAlpha() == 255) {
|
||||
Color tmpCol = new Color(c.getRed(), c.getGreen(), c.getBlue(), 1);
|
||||
newImage.setRGB(x, y, tmpCol.getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.offer(Key.key(Key.MINECRAFT_NAMESPACE, SHEEP), newImage, "png");
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/PackConverter
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.packconverter.converters;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.packconverter.PackConversionContext;
|
||||
import org.geysermc.packconverter.PackConverter;
|
||||
import org.geysermc.packconverter.utils.ImageUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@AutoService(Converter.class)
|
||||
public class SheepConverter extends AbstractConverter {
|
||||
|
||||
@Getter
|
||||
public static final List<Object[]> defaultData = new ArrayList<>();
|
||||
|
||||
static {
|
||||
defaultData.add(new Object[] {"textures/entity/sheep/sheep.png", "textures/entity/sheep/sheep_fur.png"});
|
||||
}
|
||||
|
||||
public SheepConverter(PackConverter packConverter, Path storage, Object[] data) {
|
||||
super(packConverter, storage, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractConverter> convert(@NotNull PackConversionContext context) {
|
||||
List<AbstractConverter> delete = new ArrayList<>();
|
||||
|
||||
try {
|
||||
String sheep = (String) context.data()[0];
|
||||
String sheepFur = (String) context.data()[1];
|
||||
|
||||
File sheepFile = storage.resolve(sheep).toFile();
|
||||
File sheepFurFile = storage.resolve(sheepFur).toFile();
|
||||
|
||||
if (!sheepFile.exists() || !sheepFurFile.exists()) {
|
||||
return delete;
|
||||
}
|
||||
|
||||
context.log("Convert sheep");
|
||||
|
||||
BufferedImage sheepImage = ImageIO.read(sheepFile);
|
||||
BufferedImage sheepFurImage = ImageIO.read(sheepFurFile);
|
||||
|
||||
int width = Math.max(sheepImage.getWidth(), sheepFurImage.getWidth());
|
||||
sheepImage = ImageUtils.ensureMinWidth(sheepImage, width);
|
||||
sheepFurImage = ImageUtils.ensureMinWidth(sheepFurImage, width);
|
||||
|
||||
BufferedImage newImage = new BufferedImage(sheepImage.getWidth(), sheepImage.getHeight() + sheepFurImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics g = newImage.getGraphics();
|
||||
|
||||
g.drawImage(sheepImage, 0, 0, null);
|
||||
|
||||
g.drawImage(sheepFurImage, 0, sheepImage.getHeight(), null);
|
||||
|
||||
for (int x = 0; x < newImage.getWidth(); x++) {
|
||||
for (int y = 0; y < sheepImage.getHeight(); y++) {
|
||||
Color c = new Color(newImage.getRGB(x, y), true);
|
||||
if (c.getAlpha() == 255) {
|
||||
Color tmpCol = new Color(c.getRed(), c.getGreen(), c.getBlue(), 1);
|
||||
newImage.setRGB(x, y, tmpCol.getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImageUtils.write(newImage, "png", sheepFile);
|
||||
|
||||
delete.add(new DeleteConverter(packConverter, storage, new Object[] {sheepFur}));
|
||||
} catch (IOException e) { }
|
||||
|
||||
return delete;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user