diff --git a/build.gradle b/build.gradle index 0e7c3cd..9767149 100644 --- a/build.gradle +++ b/build.gradle @@ -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" } diff --git a/gradle.properties b/gradle.properties index 9d07a39..07ed1c4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/com/terraformersmc/vistas/Vistas.java b/src/main/java/com/terraformersmc/vistas/Vistas.java index d0b482c..1566092 100644 --- a/src/main/java/com/terraformersmc/vistas/Vistas.java +++ b/src/main/java/com/terraformersmc/vistas/Vistas.java @@ -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; @@ -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 builtinPanoramas = new HashMap<>(); - public static Map resourcePanoramas = new HashMap<>(); - public static Map panoramas = new HashMap<>(); + public static Map builtinPanoramas = new HashMap(); + public static Map resourcePanoramas = new HashMap(); + public static Map panoramas = new HashMap(); - 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 panoramas = new HashSet<>(); - impl.appendPanoramas(panoramas); - panoramas.forEach(Vistas::addBuiltInPanorama); + HashSet builtInPanoramas = new HashSet(); + 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(); } } diff --git a/src/main/java/com/terraformersmc/vistas/access/MinecraftClientAccess.java b/src/main/java/com/terraformersmc/vistas/access/MinecraftClientAccess.java index 819dc50..56bee8f 100644 --- a/src/main/java/com/terraformersmc/vistas/access/MinecraftClientAccess.java +++ b/src/main/java/com/terraformersmc/vistas/access/MinecraftClientAccess.java @@ -4,4 +4,5 @@ public interface MinecraftClientAccess { void setClientPanorama(Panorama pan); + Panorama getClientPanorama(); } diff --git a/src/main/java/com/terraformersmc/vistas/api/VistasApi.java b/src/main/java/com/terraformersmc/vistas/api/VistasApi.java index 54944a8..25a2fca 100644 --- a/src/main/java/com/terraformersmc/vistas/api/VistasApi.java +++ b/src/main/java/com/terraformersmc/vistas/api/VistasApi.java @@ -5,5 +5,5 @@ import com.terraformersmc.vistas.api.panorama.Panorama; public interface VistasApi { - void appendPanoramas(Set panoramas); + void appendPanoramas(Set panoramas); } diff --git a/src/main/java/com/terraformersmc/vistas/api/panorama/MovementSettings.java b/src/main/java/com/terraformersmc/vistas/api/panorama/MovementSettings.java index bfdb22e..b9b3918 100644 --- a/src/main/java/com/terraformersmc/vistas/api/panorama/MovementSettings.java +++ b/src/main/java/com/terraformersmc/vistas/api/panorama/MovementSettings.java @@ -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); @@ -10,12 +12,37 @@ public class MovementSettings { private float speedMultiplier; private boolean woozy; + private boolean useXEquation; + private Function XEquation; + private boolean useYEquation; + private Function YEquation; + + public MovementSettings(boolean frozen, float addedX, float addedY, float speedMultiplier, boolean woozy, boolean useXEquation, boolean useYEquation, Function XEquation, Function 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() { @@ -38,4 +65,20 @@ public boolean isWoozy() { return woozy; } + public boolean isUsingXEquation() { + return useXEquation; + } + + public Function getXEquation() { + return XEquation; + } + + public boolean isUsingYEquation() { + return useYEquation; + } + + public Function getYEquation() { + return YEquation; + } + } diff --git a/src/main/java/com/terraformersmc/vistas/api/panorama/Panorama.java b/src/main/java/com/terraformersmc/vistas/api/panorama/Panorama.java index 3ae7dac..a9f9b45 100644 --- a/src/main/java/com/terraformersmc/vistas/api/panorama/Panorama.java +++ b/src/main/java/com/terraformersmc/vistas/api/panorama/Panorama.java @@ -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; @@ -54,6 +56,15 @@ public static class Builder { private float speedMultiplier = 1.0F; private boolean woozy = false; + private boolean useXEquation = false; + private Function XEquation = (time) -> { + return 0.0F; + }; + private boolean useYEquation = false; + private Function YEquation = (time) -> { + return 0.0F; + }; + public Builder(String name) { this.name = name; } @@ -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 xEquation) { + XEquation = xEquation; + useXEquation = true; + return this; + } + + public Builder setYEquation(Function 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) { diff --git a/src/main/java/com/terraformersmc/vistas/api/panorama/Panoramas.java b/src/main/java/com/terraformersmc/vistas/api/panorama/Panoramas.java index 3a9e294..fd16b79 100644 --- a/src/main/java/com/terraformersmc/vistas/api/panorama/Panoramas.java +++ b/src/main/java/com/terraformersmc/vistas/api/panorama/Panoramas.java @@ -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); + } } diff --git a/src/main/java/com/terraformersmc/vistas/mixin/GameRendererMixin.java b/src/main/java/com/terraformersmc/vistas/mixin/GameRendererMixin.java index 820cfd2..d7c0176 100644 --- a/src/main/java/com/terraformersmc/vistas/mixin/GameRendererMixin.java +++ b/src/main/java/com/terraformersmc/vistas/mixin/GameRendererMixin.java @@ -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); } } } diff --git a/src/main/java/com/terraformersmc/vistas/mixin/MinecraftClientMixin.java b/src/main/java/com/terraformersmc/vistas/mixin/MinecraftClientMixin.java index 0b507b2..150e13a 100644 --- a/src/main/java/com/terraformersmc/vistas/mixin/MinecraftClientMixin.java +++ b/src/main/java/com/terraformersmc/vistas/mixin/MinecraftClientMixin.java @@ -1,59 +1,65 @@ package com.terraformersmc.vistas.mixin; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import com.terraformersmc.vistas.access.MinecraftClientAccess; import com.terraformersmc.vistas.api.panorama.Panorama; -import com.terraformersmc.vistas.api.panorama.Panoramas; import com.terraformersmc.vistas.resource.PanoramaManager; + import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.resource.ReloadableResourceManager; import net.minecraft.sound.MusicSound; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Environment(EnvType.CLIENT) @Mixin(MinecraftClient.class) public class MinecraftClientMixin implements MinecraftClientAccess { - @Shadow - public ClientPlayerEntity player; - - @Shadow - @Final - private ReloadableResourceManager resourceManager; - - @Unique - private PanoramaManager panoramaManager; - - @Unique - private Panorama clientPanorama; - - @Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true) - private void VISTAS_getMusicType(CallbackInfoReturnable ci) { - if (this.player == null) { - if (clientPanorama != null) { - ci.setReturnValue(Panoramas.getCurrent().getMusic()); - } - } - } - - @Inject(method = "", at = @At(value = "NEW", target = "Lnet/minecraft/client/texture/TextureManager;")) - private void VISTAS_PanoramaManagerMixin(CallbackInfo ci) { - this.panoramaManager = new PanoramaManager(); - this.resourceManager.registerListener(panoramaManager); - clientPanorama = null; - } - - @Override - public void setClientPanorama(Panorama pan) { - clientPanorama = pan; - } + @Shadow + public ClientPlayerEntity player; + + @Shadow + @Final + private ReloadableResourceManager resourceManager; + + @Unique + private PanoramaManager panoramaManager; + + @Unique + private Panorama clientPanorama; + + @Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true) + private void VISTAS_getMusicType(CallbackInfoReturnable ci) { + if (this.player == null) { + if (clientPanorama != null) { + ci.setReturnValue(clientPanorama.getMusic()); + } + } + } + + @Inject(method = "", at = @At(value = "NEW", target = "Lnet/minecraft/client/texture/TextureManager;")) + private void VISTAS_PanoramaManagerMixin(CallbackInfo ci) { + this.panoramaManager = new PanoramaManager(); + this.resourceManager.registerListener(panoramaManager); + clientPanorama = null; + } + + @Override + public void setClientPanorama(Panorama pan) { + clientPanorama = pan; + } + + @Override + public Panorama getClientPanorama() { + return clientPanorama; + } } diff --git a/src/main/java/com/terraformersmc/vistas/mixin/RotatingCubeMapRendererMixin.java b/src/main/java/com/terraformersmc/vistas/mixin/RotatingCubeMapRendererMixin.java index 5119858..fb83308 100644 --- a/src/main/java/com/terraformersmc/vistas/mixin/RotatingCubeMapRendererMixin.java +++ b/src/main/java/com/terraformersmc/vistas/mixin/RotatingCubeMapRendererMixin.java @@ -1,34 +1,57 @@ package com.terraformersmc.vistas.mixin; -import com.terraformersmc.vistas.api.panorama.Panoramas; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.RotatingCubeMapRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; +import com.terraformersmc.vistas.api.panorama.MovementSettings; import com.terraformersmc.vistas.api.panorama.Panorama; +import com.terraformersmc.vistas.api.panorama.Panoramas; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.RotatingCubeMapRenderer; @Environment(EnvType.CLIENT) -@Mixin(RotatingCubeMapRenderer.class) +@Mixin(value = RotatingCubeMapRenderer.class, priority = 69) public abstract class RotatingCubeMapRendererMixin { - @Shadow - private float time; - - @ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/CubeMapRenderer;draw(Lnet/minecraft/client/MinecraftClient;FFF)V")) - public void VISTAS_changeSpeed(Args args, float delta, float alpha) { - Panorama pan = Panoramas.getCurrent(); - boolean frozen = pan.getMovementSettings().isFrozen(); - float addedX = pan.getMovementSettings().getAddedX(); - float addedY = pan.getMovementSettings().getAddedY(); - boolean woozy = pan.getMovementSettings().isWoozy(); - float speedMultiplier = pan.getMovementSettings().getSpeedMultiplier(); - args.set(1, frozen ? addedX : (float) (woozy ? this.time * 0.1F * speedMultiplier : args.get(1)) + addedX); - args.set(2, frozen ? addedY : ((float) args.get(2) * speedMultiplier) + addedY); - } + @Shadow + private float time; + + @ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/CubeMapRenderer;draw(Lnet/minecraft/client/MinecraftClient;FFF)V")) + public void VISTAS_changeSpeed(Args args, float delta, float alpha) { + Panorama pan = Panoramas.getCurrent(); + MovementSettings settings = pan.getMovementSettings(); + + float newX = settings.getAddedX(); + float newY = settings.getAddedY(); + + if (!settings.isFrozen()) { + if (!settings.isUsingXEquation()) { + if (settings.isWoozy()) { + newX += this.time * 0.1F; + } else { + newX += (float) args.get(1); + } + } else { + newX = settings.getXEquation().apply(time); + } + + if (!settings.isUsingYEquation()) { + newY += (float) args.get(2); + } else { + newY = settings.getYEquation().apply(time); + } + + newX *= settings.getSpeedMultiplier(); + newY *= settings.getSpeedMultiplier(); + } + + args.set(1, newX); + args.set(2, newY); + } } diff --git a/src/main/java/com/terraformersmc/vistas/screenshot/PanoramicScreenshots.java b/src/main/java/com/terraformersmc/vistas/screenshot/PanoramicScreenshots.java index 828b3df..af1349c 100644 --- a/src/main/java/com/terraformersmc/vistas/screenshot/PanoramicScreenshots.java +++ b/src/main/java/com/terraformersmc/vistas/screenshot/PanoramicScreenshots.java @@ -31,7 +31,7 @@ public final class PanoramicScreenshots { private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss"); - public static final Logger LOGGER = LogManager.getLogger(Vistas.MOD_ID + "|PanoramicScreenshots"); + public static final Logger LOGGER = LogManager.getLogger(Vistas.MOD_NAME + "|PanoramicScreenshots"); /** * The rotations for the 6 sides of the rendered panorama. */ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9f2f767..aab0c96 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,36 +1,36 @@ { - "schemaVersion": 1, - "id": "vistas", - "version": "${version}", - "name": "Vistas", - "description": "A library and tool for creating and customizing main menu panoramas and music for mods and modpacks on the fabric platform.", - "authors": [ - "LudoCrypt", - "Prospector", - "TerraformersMC" - ], - "contact": { - "homepage": "https://www.curseforge.com/minecraft/mc-mods/vistas", - "sources": "https://github.com/TerraformersMC/Vistas", - "issues": "https://github.com/TerraformersMC/Vistas/issues" - }, - "license": "LGPLv3", - "icon": "assets/vistas/icon.png", - "environment": "client", - "entrypoints": { - "client": [ - "com.terraformersmc.vistas.Vistas" - ], - "modmenu": [ - "com.terraformersmc.vistas.config.VistasModMenuCompat" - ] - }, - "mixins": [ - "vistas.mixins.json" - ], - "depends": { - "fabricloader": ">=0.7.4", - "fabric": "*", - "minecraft": ">=1.16.4" - } + "schemaVersion": 1, + "id": "vistas", + "version": "${version}", + "name": "Vistas", + "description": "A library and tool for creating and customizing main menu panoramas and music for mods and modpacks on the fabric platform.", + "authors": [ + "LudoCrypt", + "Prospector", + "TerraformersMC" + ], + "contact": { + "homepage": "https://www.curseforge.com/minecraft/mc-mods/vistas", + "sources": "https://github.com/TerraformersMC/Vistas", + "issues": "https://github.com/TerraformersMC/Vistas/issues" + }, + "license": "LGPLv3", + "icon": "assets/vistas/icon.png", + "environment": "client", + "entrypoints": { + "client": [ + "com.terraformersmc.vistas.Vistas" + ], + "modmenu": [ + "com.terraformersmc.vistas.config.VistasModMenuCompat" + ] + }, + "mixins": [ + "vistas.mixins.json" + ], + "depends": { + "fabricloader": ">=0.7.4", + "fabric": "*", + "minecraft": ">=1.16.4" + } }