Skip to content

Commit

Permalink
#change "Fixed issue where weight breaks the game" #change "Added equ…
Browse files Browse the repository at this point in the history
…ation functionality through java API" #change "made panorama screenshot text have an underline, like normal screenshot text" #change "Bump version" #release beta
  • Loading branch information
LudoCrypt committed Dec 11, 2020
1 parent 5ad5af2 commit acebb74
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 156 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {

mod "fabric-loader", "net.fabricmc:fabric-loader:$project.loader_version"
mod "modmenu", "io.github.prospector:modmenu:$project.modmenu_version"
includeMod "fabric-api", fabricApi.module("fabric-resource-loader-v0", project.fabric_version)
includeMod "fabric-api", "net.fabricmc.fabric-api:fabric-api:$project.fabric_version"
includeMod "cloth-config-2", "me.shedaniel.cloth:config-2:$project.clothconfig_version"
includeMod "autoconfig", "me.sargunvohra.mcmods:autoconfig1u:$project.autoconfig_version"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx1G

mod_version=1.1.1
mod_version=1.2.0
maven_group=com.terraformersmc
archive_name=vistas

Expand Down
26 changes: 15 additions & 11 deletions src/main/java/com/terraformersmc/vistas/Vistas.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import org.apache.logging.log4j.Logger;

import com.terraformersmc.vistas.api.VistasApi;
import com.terraformersmc.vistas.config.PanoramaConfig;
import com.terraformersmc.vistas.api.panorama.Panorama;
import com.terraformersmc.vistas.api.panorama.Panoramas;
import com.terraformersmc.vistas.config.PanoramaConfig;
import com.terraformersmc.vistas.screenshot.PanoramicScreenshots;

import net.fabricmc.api.ClientModInitializer;
Expand All @@ -20,35 +21,38 @@
@Environment(EnvType.CLIENT)
public class Vistas implements ClientModInitializer {

public static final String MOD_NAME = "Vistas";
public static final String MOD_ID = "vistas";

public static Map<String, Panorama> builtinPanoramas = new HashMap<>();
public static Map<String, Panorama> resourcePanoramas = new HashMap<>();
public static Map<String, Panorama> panoramas = new HashMap<>();
public static Map<String, Panorama> builtinPanoramas = new HashMap<String, Panorama>();
public static Map<String, Panorama> resourcePanoramas = new HashMap<String, Panorama>();
public static Map<String, Panorama> panoramas = new HashMap<String, Panorama>();

public static Logger LOGGER = LogManager.getLogger(MOD_ID);
public static Logger LOGGER = LogManager.getLogger(MOD_NAME);

@Override
public void onInitializeClient() {
PanoramaConfig.init();
PanoramicScreenshots.registerKeyBinding();
FabricLoader.getInstance().getEntrypointContainers("vistas", VistasApi.class).forEach(container -> {
FabricLoader.getInstance().getEntrypointContainers(MOD_ID, VistasApi.class).forEach(container -> {
VistasApi impl = container.getEntrypoint();
HashSet<Panorama> panoramas = new HashSet<>();
impl.appendPanoramas(panoramas);
panoramas.forEach(Vistas::addBuiltInPanorama);
HashSet<Panorama> builtInPanoramas = new HashSet<Panorama>();
impl.appendPanoramas(builtInPanoramas);
builtInPanoramas.forEach(Vistas::addBuiltInPanorama);
});
}

public static void addBuiltInPanorama(Panorama pan) {
for (int i = 0; i < pan.getWeight(); i++) {
builtinPanoramas.put(pan.getWeight() > 1 ? pan.getName() + "_" + i : pan.getName(), pan);
builtinPanoramas.put(pan.getName() + '_' + i, pan);
}
Panoramas.reload();
}

public static void addResourcePanorama(Panorama pan) {
for (int i = 0; i < pan.getWeight(); i++) {
resourcePanoramas.put(pan.getWeight() > 1 ? pan.getName() + "_" + i : pan.getName(), pan);
resourcePanoramas.put(pan.getName() + '_' + i, pan);
}
Panoramas.reload();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

public interface MinecraftClientAccess {
void setClientPanorama(Panorama pan);
Panorama getClientPanorama();
}
2 changes: 1 addition & 1 deletion src/main/java/com/terraformersmc/vistas/api/VistasApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import com.terraformersmc.vistas.api.panorama.Panorama;

public interface VistasApi {
void appendPanoramas(Set<Panorama> panoramas);
void appendPanoramas(Set<Panorama> panoramas);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.terraformersmc.vistas.api.panorama;

import com.google.common.base.Function;

public class MovementSettings {

public static final MovementSettings DEFAULT = new MovementSettings(false, 0.0F, 0.0F, 1.0F, false);
Expand All @@ -10,12 +12,37 @@ public class MovementSettings {
private float speedMultiplier;
private boolean woozy;

private boolean useXEquation;
private Function<Float, Float> XEquation;
private boolean useYEquation;
private Function<Float, Float> YEquation;

public MovementSettings(boolean frozen, float addedX, float addedY, float speedMultiplier, boolean woozy, boolean useXEquation, boolean useYEquation, Function<Float, Float> XEquation, Function<Float, Float> YEquation) {
this.frozen = frozen;
this.addedX = addedX;
this.addedY = addedY;
this.speedMultiplier = speedMultiplier;
this.woozy = woozy;
this.useXEquation = useXEquation;
this.useYEquation = useYEquation;
this.XEquation = XEquation;
this.YEquation = YEquation;
}

public MovementSettings(boolean frozen, float addedX, float addedY, float speedMultiplier, boolean woozy) {
this.frozen = frozen;
this.addedX = addedX;
this.addedY = addedY;
this.speedMultiplier = speedMultiplier;
this.woozy = woozy;
this.useXEquation = false;
this.useYEquation = false;
this.XEquation = (time) -> {
return 0.0F;
};
this.YEquation = (time) -> {
return 0.0F;
};
}

public boolean isFrozen() {
Expand All @@ -38,4 +65,20 @@ public boolean isWoozy() {
return woozy;
}

public boolean isUsingXEquation() {
return useXEquation;
}

public Function<Float, Float> getXEquation() {
return XEquation;
}

public boolean isUsingYEquation() {
return useYEquation;
}

public Function<Float, Float> getYEquation() {
return YEquation;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.terraformersmc.vistas.api.panorama;

import com.google.common.base.Function;

import net.minecraft.sound.MusicSound;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
Expand Down Expand Up @@ -54,6 +56,15 @@ public static class Builder {
private float speedMultiplier = 1.0F;
private boolean woozy = false;

private boolean useXEquation = false;
private Function<Float, Float> XEquation = (time) -> {
return 0.0F;
};
private boolean useYEquation = false;
private Function<Float, Float> YEquation = (time) -> {
return 0.0F;
};

public Builder(String name) {
this.name = name;
}
Expand Down Expand Up @@ -98,8 +109,30 @@ public Builder setWoozy(boolean woozy) {
return this;
}

public Builder setUseXEquation(boolean useXEquation) {
this.useXEquation = useXEquation;
return this;
}

public Builder setUseYEquation(boolean useYEquation) {
this.useYEquation = useYEquation;
return this;
}

public Builder setXEquation(Function<Float, Float> xEquation) {
XEquation = xEquation;
useXEquation = true;
return this;
}

public Builder setYEquation(Function<Float, Float> yEquation) {
YEquation = yEquation;
useYEquation = true;
return this;
}

public Panorama build() {
return new Panorama(name, backgroundId, music, new MovementSettings(frozen, addedX, addedY, speedMultiplier, woozy), weight);
return new Panorama(name, backgroundId, music, new MovementSettings(frozen, addedX, addedY, speedMultiplier, woozy, useXEquation, useYEquation, XEquation, YEquation), weight);
}

public static MusicSound createMenuSound(SoundEvent event) {
Expand Down
88 changes: 44 additions & 44 deletions src/main/java/com/terraformersmc/vistas/api/panorama/Panoramas.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
package com.terraformersmc.vistas.api.panorama;

import java.util.Random;

import com.terraformersmc.vistas.Vistas;
import com.terraformersmc.vistas.access.MinecraftClientAccess;
import com.terraformersmc.vistas.config.PanoramaConfig;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import net.minecraft.client.MinecraftClient;

import java.util.Random;
import net.minecraft.client.MinecraftClient;

public class Panoramas {
public static Panorama getCurrent() {

Panorama pickedPanorama = null;

if (AutoConfig.getConfigHolder(PanoramaConfig.class) != null) {
pickedPanorama = Vistas.panoramas.get(PanoramaConfig.getInstance().panorama);
} else {
Vistas.LOGGER.warn("Config not registered while trying for panorama");
}

if (pickedPanorama == null) {
Vistas.LOGGER.warn("Config panorama null");
}

return pickedPanorama;
}

public static Panorama getRandom() {
return Vistas.panoramas.values().toArray(new Panorama[0])[new Random().nextInt(Vistas.panoramas.size())];
}

public static void setRandom() {
if (!PanoramaConfig.getInstance().forcePanorama) {
if (Vistas.panoramas.size() >= 1) {
Panorama pan = getRandom();
PanoramaConfig.getInstance().panorama = pan.getName();
((MinecraftClientAccess) MinecraftClient.getInstance()).setClientPanorama(pan);
}
}
}

public static void reload() {
Vistas.panoramas.clear();
Vistas.panoramas.putAll(Vistas.builtinPanoramas);
Vistas.panoramas.putAll(Vistas.resourcePanoramas);
setRandom();
}

public static void add(Panorama panorama) {
Vistas.addBuiltInPanorama(panorama);
}

public static Panorama getCurrent() {

Panorama pickedPanorama = Vistas.panoramas.get(PanoramaConfig.getInstance().panorama + "_0");

if (pickedPanorama == null) {
Vistas.LOGGER.warn("Config panorama null, trying client");
pickedPanorama = ((MinecraftClientAccess) MinecraftClient.getInstance()).getClientPanorama();
}

if (pickedPanorama == null) {
Vistas.LOGGER.warn("Client panorama null");
}

return pickedPanorama;
}

public static Panorama getRandom() {
return Vistas.panoramas.values().toArray(new Panorama[0])[new Random().nextInt(Vistas.panoramas.size())];
}

public static void setRandom() {
if (!PanoramaConfig.getInstance().forcePanorama) {
if (Vistas.panoramas.size() >= 1) {
Panorama pan = getRandom();
PanoramaConfig.getInstance().panorama = pan.getName();
((MinecraftClientAccess) MinecraftClient.getInstance()).setClientPanorama(pan);
}
}
}

public static void reload() {
Vistas.panoramas.clear();
Vistas.panoramas.putAll(Vistas.builtinPanoramas);
Vistas.panoramas.putAll(Vistas.resourcePanoramas);
setRandom();
}

public static void add(Panorama panorama) {
Vistas.addBuiltInPanorama(panorama);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public abstract class GameRendererMixin {
renderingPanorama = oldFov90;
client.chunkCullingEnabled = oldCulling;
if (client.player != null) {
client.player.sendMessage(new TranslatableText("vistas.panoramic_screenshot.saved", new LiteralText(root.toAbsolutePath().toString()).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, root.toAbsolutePath().toString())))), false);
client.player.sendMessage(new TranslatableText("vistas.panoramic_screenshot.saved", new LiteralText(root.toAbsolutePath().toString()).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, root.toAbsolutePath().toString())).withUnderline(true))), false);
}
}
}
Expand Down
Loading

0 comments on commit acebb74

Please sign in to comment.