mirror of
https://github.com/GeyserMC/PackConverter.git
synced 2025-12-30 12:19:11 +00:00
Rewrite pack converter code and add pack schemas
Java POJO's are now generated from JSON schemas meaning they should always be up-to-date. The legacy converters have been moved into a separate package until they get converted. This new structure and systems/supporting APIs backing it makes the library far more powerful and will allow for much greater potential going forward.
This commit is contained in:
102
legacy/WeatherConverter.java
Normal file
102
legacy/WeatherConverter.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 WeatherConverter extends AbstractConverter {
|
||||
|
||||
@Getter
|
||||
public static final List<Object[]> defaultData = new ArrayList<>();
|
||||
|
||||
static {
|
||||
// Bed
|
||||
defaultData.add(new Object[] {"textures/environment/snow.png", "textures/environment/rain.png", "textures/environment/weather.png"});
|
||||
}
|
||||
|
||||
public WeatherConverter(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 snow = (String) context.data()[0];
|
||||
String rain = (String) context.data()[1];
|
||||
String to = (String) context.data()[2];
|
||||
|
||||
File snowFile = storage.resolve(snow).toFile();
|
||||
File rainFile = storage.resolve(rain).toFile();
|
||||
|
||||
if (!snowFile.exists() || !rainFile.exists()) {
|
||||
return delete;
|
||||
}
|
||||
|
||||
context.log("Convert weather");
|
||||
|
||||
BufferedImage snowImage = ImageIO.read(snowFile);
|
||||
BufferedImage rainImage = ImageIO.read(rainFile);
|
||||
|
||||
int factor = snowImage.getWidth() / 64;
|
||||
|
||||
BufferedImage weatherImage = new BufferedImage((32 * factor), (32 * factor), BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
Graphics g = weatherImage.getGraphics();
|
||||
|
||||
// Snow
|
||||
g.drawImage(ImageUtils.cover(ImageUtils.crop(snowImage, snowImage.getWidth(), (3 * factor)), weatherImage.getWidth(), (3 * factor)), 0, 0, null);
|
||||
|
||||
delete.add(new DeleteConverter(packConverter, storage, new Object[] {snow}));
|
||||
|
||||
// Rain
|
||||
g.drawImage(ImageUtils.cover(ImageUtils.crop(rainImage, rainImage.getWidth(), (5 * factor)), weatherImage.getWidth(), (5 * factor)), 0, (5 * factor), null);
|
||||
|
||||
delete.add(new DeleteConverter(packConverter, storage, new Object[] {rain}));
|
||||
|
||||
ImageUtils.write(weatherImage, "png", storage.resolve(to).toFile());
|
||||
} catch (IOException e) { }
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user