Skip to content

Commit

Permalink
0.2.0 - Update to 19w38b
Browse files Browse the repository at this point in the history
Signed-off-by: liach <liach@users.noreply.github.com>
  • Loading branch information
liach committed Sep 22, 2019
1 parent f2790e4 commit e5249ad
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 40 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx2G

# Project Properties
modVersion=0.1.0
modVersion=0.2.0
mavenGroup=com.github.liachmodded
archivesBaseName=runorama
description=runemoro's panorama
Expand All @@ -15,10 +15,10 @@ dataEntry=com.github.liachmodded.runorama.data.DataDumper

# Fabric Properties
# check these on https://fabricmc.net/use
minecraftVersion=19w36a
yarnMappings=19w36a+build.1
minecraftVersion=19w38b
yarnMappings=19w38b+build.6
loaderVersion=0.6.1+build.164

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric
apiVersion=0.3.2+build.219-1.15
apiVersion=0.3.2+build.232-1.15
30 changes: 24 additions & 6 deletions src/code/java/com/github/liachmodded/runorama/RunoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,44 @@
*/
package com.github.liachmodded.runorama;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import java.util.function.Function;

/**
* The configuration format for Runorama, backed by Java's builtin {@link Properties}.
*/
public final class RunoConfig {

final Properties properties;

/**
* Load the configuration from a property file.
*
* <p>The file should be encoded in UTF-8.
*
* @param file the configuration file
* @return the loaded configuration
*/
public static RunoConfig load(Path file) {
Properties props = new Properties();
try (InputStreamReader stream = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8)) {
props.load(stream);
try (BufferedReader reader = Files.newBufferedReader(file)) {
props.load(reader);
} catch (IOException ex) {
Runorama.LOGGER.error("Failed to load config file from {}!", file, ex);
}
return new RunoConfig(props);
}

/**
* Create a configuration from a {@link Properties}.
*
* @param properties the backing properties
*/
public RunoConfig(Properties properties) {
this.properties = properties;
}
Expand Down Expand Up @@ -79,14 +93,18 @@ public <T> Property<T> property(String key, T value, Function<String, T> reader,
public void save(Path file) {
try {
Files.createDirectories(file.getParent());
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(file), StandardCharsets.UTF_8)) {
try (Writer writer = Files.newBufferedWriter(file)) {
properties.store(writer, "runorama config");
}
} catch (IOException ex) {
Runorama.LOGGER.error("Failed to save runorama config to {}!", file, ex);
}
}

/**
* A property in the configuration.
* @param <T> the value's type
*/
public final class Property<T> {

private final String key;
Expand Down
21 changes: 21 additions & 0 deletions src/code/java/com/github/liachmodded/runorama/RunoSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,34 @@
import java.nio.file.Files;
import java.nio.file.Path;

/**
* The settings for Runorama, loaded from the configuration.
*/
public final class RunoSettings {

private final Runorama mod;
private final RunoConfig config;
private final Path path;
/**
* The integer ID of the next panorama that will be taken.
*/
public final RunoConfig.Property<Integer> next;
/**
* The max ID possible for panoramas. When the next ID exceeds this size, old panoramas will be removed.
*/
public final RunoConfig.Property<Integer> poolSize;
/**
* The rotation speed of the panorama in the {@link net.minecraft.client.gui.screen.TitleScreen title screen}.
*
* <p>Negative values will make the rotation counterclockwise.
*
* <p>A speed that's too high may make viewers dizzy!
*/
public final RunoConfig.Property<Double> rotationSpeed;
/**
* Whether to include vanilla panorama for the panoramas Runorama mod would display.
*/
public final RunoConfig.Property<Boolean> includeVanillaPanorama;

public RunoSettings(Runorama mod, RunoConfig backend, Path path) {
this.mod = mod;
Expand All @@ -25,6 +45,7 @@ public RunoSettings(Runorama mod, RunoConfig backend, Path path) {
this.next = config.integerProperty("next", 0);
this.poolSize = config.integerProperty("pool-size", 1000);
this.rotationSpeed = config.doubleProperty("clockwise-rotation-speed", 1.0D);
this.includeVanillaPanorama = config.booleanProperty("include-vanilla-panorama", false);
}

public Path getCurrentRunoramaFolder() {
Expand Down
111 changes: 89 additions & 22 deletions src/code/java/com/github/liachmodded/runorama/Runorama.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.github.liachmodded.runorama.client.BoundImage;
import com.github.liachmodded.runorama.client.CloseableBinder;
import com.github.liachmodded.runorama.client.VanillaPanorama;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
Expand All @@ -21,6 +22,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -29,9 +31,18 @@
import java.util.Properties;
import java.util.function.Supplier;

/**
* Runorama mod class.
*/
public final class Runorama implements ClientModInitializer {

/**
* The mod id, or the namespace of Runorama.
*/
public static final String ID = "runorama";
/**
* The logger.
*/
public static final Logger LOGGER = LogManager.getLogger(ID);
private static Runorama instance;
private Path cacheDir;
Expand All @@ -40,12 +51,24 @@ public final class Runorama implements ClientModInitializer {
private boolean takingScreenshot;
private float desiredPitch;
private float desiredYaw;
/**
* Whether to take a screenshot the next time a frame is rendered.
*/
public boolean needsScreenshot = false;

/**
* Easy way to create an {@link Identifier} with Runorama's namespace.
*
* @param name the name
* @return a new identifier
*/
public static Identifier name(String name) {
return new Identifier(ID, name);
}

/**
* Returns Runorama's instance.
*/
public static Runorama getInstance() {
return instance;
}
Expand All @@ -59,7 +82,7 @@ public void onInitializeClient() {
readSettings();

FabricKeyBinding screenshotKey =
FabricKeyBinding.Builder.create(name("runorama"), InputUtil.Type.KEYSYM, 72/*h*/, "key.categories.misc").build();
FabricKeyBinding.Builder.create(name("runorama"), InputUtil.Type.KEYSYM, 'H'/*h*/, "key.categories.misc").build();
KeyBindingRegistry.INSTANCE.register(screenshotKey);
ClientTickCallback.EVENT.register(c -> {
if (screenshotKey.isPressed()) {
Expand All @@ -86,39 +109,62 @@ Path getCacheImagePath(int id) {
return cacheDir.resolve("panorama-" + id);
}

/**
* Make a list of candidates for panoramas.
*
* <p>Each candidate may fail to evaluate when called.
*
* @return the list of candidates
*/
public List<Supplier</* Nullable */CloseableBinder>> makeScreenshotBinders() {
List<Supplier</* Nullable */CloseableBinder>> ret = new ArrayList<>();
outerLoop:
for (int i = 0; i < settings.poolSize.get(); i++) {
Path eachRunoFolder = getCacheImagePath(i);
if (!Files.isDirectory(eachRunoFolder)) {
continue;

try (DirectoryStream<Path> paths = Files.newDirectoryStream(cacheDir, eachFolder -> {
if (!Files.isDirectory(eachFolder)) {
return false;
}
for (int j = 0; j < 6; j++) {
Path part = eachRunoFolder.resolve("paranoma_" + j + ".png");
for (int i = 0; i < 6; i++) {
Path part = eachFolder.resolve("panorama_" + i + ".png");
if (!Files.isRegularFile(part)) {
continue outerLoop;
return false;
}
}
ret.add(() -> {
NativeImage[] images = new NativeImage[6];
for (int j = 0; j < 6; j++) {
Path part = eachRunoFolder.resolve("paranoma_" + j + ".png");
try (InputStream stream = Files.newInputStream(part)) {
images[j] = NativeImage.read(stream);
} catch (IOException ex) {
Runorama.LOGGER.error("Failed to bind custom screenshot part at {}!", part, ex);
return null;
return true;
})) {
for (final Path eachFolder : paths) {
ret.add(() -> {
NativeImage[] images = new NativeImage[6];
for (int j = 0; j < 6; j++) {
Path part = eachFolder.resolve("panorama_" + j + ".png");
try (InputStream stream = Files.newInputStream(part)) {
images[j] = NativeImage.read(stream);
} catch (IOException ex) {
Runorama.LOGGER.error("Failed to bind custom screenshot part at {}!", part, ex);
return null;
}
}
}
return new BoundImage(images);
});
return new BoundImage(images);
});
}
} catch (IOException ex) {
return Collections.emptyList();
}

if (settings.includeVanillaPanorama.get()) {
ret.add(VanillaPanorama::new);
}

Collections.shuffle(ret);
return ret;
}

/**
* Save a partial screenshot for a panorama.
*
* @param screenshot the image
* @param folder the panorama folder
* @param i the face index
*/
public void saveScreenshot(NativeImage screenshot, Path folder, int i) {
ResourceImpl.RESOURCE_IO_EXECUTOR.execute(() -> {
try {
Expand All @@ -135,7 +181,7 @@ public void saveScreenshot(NativeImage screenshot, Path folder, int i) {
}
NativeImage saved = new NativeImage(width, height, false);
screenshot.resizeSubRectTo(int_3, int_4, width, height, saved);
saved.writeFile(folder.resolve("paranoma_" + i + ".png"));
saved.writeFile(folder.resolve("panorama_" + i + ".png"));
} catch (IOException var27) {
Runorama.LOGGER.warn("Couldn't save screenshot", var27);
} finally {
Expand All @@ -144,28 +190,49 @@ public void saveScreenshot(NativeImage screenshot, Path folder, int i) {
});
}

/**
* Gets the settings of the mod, loaded from the configuration file.
*/
public RunoSettings getSettings() {
return this.settings;
}

/**
* Sets the rotation for the camera for the panorama and start taking a screenshot.
*
* @param pitch the pitch
* @param yaw the yaw
*/
public void setPanoramicRotation(float pitch, float yaw) {
this.takingScreenshot = true;
this.desiredPitch = pitch;
this.desiredYaw = yaw;
}

/**
* Returns true if a screenshot is in progress.
*/
public boolean isTakingScreenshot() {
return takingScreenshot;
}

/**
* Returns the desired pitch for the camera.
*/
public float getDesiredPitch() {
return desiredPitch;
}

/**
* Returns the desired yaw for the camera.
*/
public float getDesiredYaw() {
return desiredYaw;
}

/**
* End the series of screenshot.
*/
public void endPanorama() {
this.takingScreenshot = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@

public interface CloseableBinder extends AutoCloseable {

/**
* Bind an image for a face. Face varies from 0 to 6.
*
* @param face the face index
*/
void bind(int face);

/**
* Disposes this binder.
*/
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void draw(MinecraftClient client, float xAngle, float yAngle, float zAngl
RenderSystem.pushMatrix();
RenderSystem.loadIdentity();
RenderSystem.multMatrix(Matrix4f.method_4929(85.0D,
(float) client.window.getFramebufferWidth() / (float) client.window.getFramebufferHeight(), 0.05F, 10.0F));
(float) client.method_22683().getFramebufferWidth() / (float) client.method_22683().getFramebufferHeight(), 0.05F, 10.0F));
RenderSystem.matrixMode(5888);
RenderSystem.pushMatrix();
RenderSystem.loadIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public void render(float float_1, float float_2) {
0f,
float_2
);
this.client.window.method_4493(MinecraftClient.IS_SYSTEM_MAC);
this.client.method_22683().method_4493(MinecraftClient.IS_SYSTEM_MAC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
public interface GameRendererAccessor {

@Accessor("field_4001")
void setField_4001(boolean value);
void setFov90(boolean value);

@Accessor("field_4001")
boolean getField_4001();
boolean isFov90();
}

0 comments on commit e5249ad

Please sign in to comment.