From 40dbb1f8d60993cc3a22bcef56bcaf5134f0c8c6 Mon Sep 17 00:00:00 2001 From: topchetoeu <36534413+TopchetoEU@users.noreply.github.com> Date: Sun, 15 Jan 2023 21:33:39 +0200 Subject: [PATCH] chore: clean up codebase, note sodium incompatibility --- README.md | 4 +- build.gradle | 5 + gradle.properties | 9 +- .../animatedchunks/AnimatedChunks.java | 85 ++--- .../animatedchunks/ConfigManager.java | 26 +- .../me/topchetoeu/animatedchunks/Manager.java | 18 +- .../{ProgressManager.java => Animator.java} | 330 ++++++++++-------- .../gui/AnimatedChunksScreen.java | 24 +- .../animatedchunks/gui/ChunkPreview.java | 38 +- .../animatedchunks/mixin/BuiltChunkMixin.java | 4 +- .../mixin/WorldRendererMixin.java | 48 ++- src/main/resources/fabric.mod.json | 3 +- 12 files changed, 294 insertions(+), 300 deletions(-) rename src/main/java/me/topchetoeu/animatedchunks/animation/{ProgressManager.java => Animator.java} (73%) diff --git a/README.md b/README.md index 46a6879..863dd0d 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ An enhanecd fork of [cadenkriese's mod](https://github.com/cadenkriese/smooth-ch +**NOTE: This mod WILL NOT support Sodium, since Sodium doesn't render separate chunks, but whole regions, hence separate chunk animations are rendered impossible. Anyone interested in making sodium compatibility, be my guest** + ## What is this? Animated Chunks is a Fabric mod that adds animations of currently loading chunks. This makes chunk loading generally seem much more pleasant than them appearing out of thin air. There are multiple built-in animations and ease types, and if this isnt't enough, there's an API which will allow you to add your own animations and eases
(with ease :trollface:) @@ -47,7 +49,7 @@ Generally, this is what you'd call an "eye-candy" mod. ## Future plans -In the future, I plan to extend the scope of this mod to not only smoothen the chunk loading, but entity spawning/despawning/dying, liquid flowing, crops growing etc. and support Sodium. +In the future, I plan to extend the scope of this mod to not only smoothen the chunk loading, but entity spawning/despawning/dying, liquid flowing, crops growing etc. ## License diff --git a/build.gradle b/build.gradle index 513b60c..eee4c3c 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,10 @@ repositories { maven { url "https://maven.terraformersmc.com/releases" } + // maven { + // url "https://jitpack.io/" + // } + mavenLocal() } dependencies { @@ -50,6 +54,7 @@ dependencies { // include("me.sargunvohra.mcmods:autoconfig1u:${project.autoconfig_version}") modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}") + // modImplementation("com.github.CaffeineMC:sodium-fabric:${project.sodium_version}") } diff --git a/gradle.properties b/gradle.properties index 28be1bc..4788267 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.jvmargs=-Xmx4G # Fabric Properties minecraft_version=1.19.2 -yarn_mappings=1.19.2+build.20 -loader_version=0.14.9 +yarn_mappings=1.19.2+build.28 +loader_version=0.14.12 # Mod Properties mod_version=0.3.0 @@ -13,5 +13,6 @@ maven_group=me.topchetoeu archives_base_name=animated-chunks # Dependencies -fabric_version=[0.0.0,) -modmenu_version=[4.0.0,) +fabric_version=0.72.0+1.19.2 +modmenu_version=4.1.2 +# sodium_version=mc1.19.2-0.4.3 diff --git a/src/main/java/me/topchetoeu/animatedchunks/AnimatedChunks.java b/src/main/java/me/topchetoeu/animatedchunks/AnimatedChunks.java index 57b5545..264d4b4 100644 --- a/src/main/java/me/topchetoeu/animatedchunks/AnimatedChunks.java +++ b/src/main/java/me/topchetoeu/animatedchunks/AnimatedChunks.java @@ -5,11 +5,10 @@ import java.io.File; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; -import me.topchetoeu.animatedchunks.Manager.RegisterEvent; import me.topchetoeu.animatedchunks.animation.Animation; import me.topchetoeu.animatedchunks.animation.FallAnimation; import me.topchetoeu.animatedchunks.animation.FlyInAnimation; -import me.topchetoeu.animatedchunks.animation.ProgressManager; +import me.topchetoeu.animatedchunks.animation.Animator; import me.topchetoeu.animatedchunks.animation.RiseAnimation; import me.topchetoeu.animatedchunks.animation.ScaleAnimation; import me.topchetoeu.animatedchunks.easing.Ease; @@ -20,54 +19,27 @@ import me.topchetoeu.animatedchunks.easing.SineEase; import me.topchetoeu.animatedchunks.gui.AnimatedChunksScreen; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents; -import net.fabricmc.fabric.api.event.Event; import net.minecraft.client.gui.screen.Screen; import net.minecraft.util.math.BlockPos; public final class AnimatedChunks implements ClientModInitializer, ModMenuApi { private static AnimatedChunks instance; + /** + * Gets the currently running instance of this mod + */ public static AnimatedChunks getInstance() { return instance; } /** - * An event, fired once, when eases are being registered + * The animator used by the mod. Used to manage animation progress and animate chunks */ - public final Event> EASES_REGISTERING = Manager.createEvent(); + public final Animator animator; /** - * An event, fired once, when animations are being registered + * The config manager used by the mod. Used to save/load config from disk */ - public final Event> ANIMATIONS_REGISTERING = Manager.createEvent(); + public final ConfigManager config; - private ProgressManager progress; - private ConfigManager config; - private Manager ease; - private Manager animation; - - /** - * Gets the config manager - */ - public ConfigManager getConfigManager() { - return config; - } - /** - * Gets the chunk progress manager - */ - public ProgressManager getProgressManager() { - return progress; - } - /** - * Gets the animation manager - */ - public Manager getAnimationManager() { - return animation; - } - /** - * Gets the ease manager - */ - public Manager getEaseManager() { - return ease; - } private static void registerEases(Manager manager) { manager.register(new Descriptor<>(new LinearEase(), "linear") @@ -121,34 +93,35 @@ public final class AnimatedChunks implements ClientModInitializer, ModMenuApi { @Override public void onInitializeClient() { instance = this; - progress = new ProgressManager(); - ease = new Manager<>(x -> 1); - ease.get() - .description("Ends the animation as soon as it has started.") - .displayName("No animation"); - animation = new Manager<>((a, b, c, d, e, f, g, h) -> {}); - animation.get() - .description("Does nothing.") - .displayName("No animation"); - - registerEases(ease); - registerAnimations(animation); - - config = new ConfigManager(new File("config/animated-chunks.dat"), animation, ease, progress); - - EASES_REGISTERING.invoker().register(ease); - ANIMATIONS_REGISTERING.invoker().register(animation); - ClientChunkEvents.CHUNK_UNLOAD.register((world, chunk) -> { BlockPos pos = chunk.getPos().getStartPos(); - progress.unload(pos.getX(), pos.getY(), pos.getZ()); + animator.unload(pos.getX(), pos.getY(), pos.getZ()); }); } @Override public ConfigScreenFactory getModConfigScreenFactory() { return (Screen parent) -> { var _this = getInstance(); - return new AnimatedChunksScreen(parent, _this.animation, _this.ease, _this.config, _this.progress); + return new AnimatedChunksScreen(parent, _this.config, _this.animator); }; } + + public AnimatedChunks() { + var eases = new Manager<>(new Descriptor(x -> 1, "default") + .author("TopchetoEU") + .description("Ends the animation as soon as it has started.") + .displayName("No animation") + ); + var animations = new Manager<>(new Descriptor((a, b, c, d, e, f, g, h) -> {}, "default") + .author("TopchetoEU") + .description("Does nothing.") + .displayName("No animation") + ); + + registerEases(eases); + registerAnimations(animations); + + animator = new Animator(animations, eases); + config = new ConfigManager(new File("config/animated-chunks.dat"), animator); + } } diff --git a/src/main/java/me/topchetoeu/animatedchunks/ConfigManager.java b/src/main/java/me/topchetoeu/animatedchunks/ConfigManager.java index d64ca11..d60daa6 100644 --- a/src/main/java/me/topchetoeu/animatedchunks/ConfigManager.java +++ b/src/main/java/me/topchetoeu/animatedchunks/ConfigManager.java @@ -9,15 +9,11 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; -import me.topchetoeu.animatedchunks.animation.Animation; -import me.topchetoeu.animatedchunks.animation.ProgressManager; -import me.topchetoeu.animatedchunks.easing.Ease; +import me.topchetoeu.animatedchunks.animation.Animator; public class ConfigManager { public final File configFile; - private final Manager animation; - private final Manager ease; - private final ProgressManager progress; + private final Animator animator; private String readString(InputStream reader) throws IOException { String res = ""; @@ -56,9 +52,9 @@ public class ConfigManager { reader.close(); - this.animation.set(animation); - this.ease.set(ease); - this.progress.setDuration(duration); + this.animator.ANIMATIONS.set(animation); + this.animator.EASES.set(ease); + this.animator.setDuration(duration); } catch (IOException e) { save(); @@ -67,9 +63,9 @@ public class ConfigManager { public void save() { try { var writer = new FileOutputStream(configFile); - writeString(writer, animation.get().getName()); - writeString(writer, ease.get().getName()); - writer.write(ByteBuffer.allocate(4).putFloat(progress.getDuration()).array()); + writeString(writer, this.animator.ANIMATIONS.get().getName()); + writeString(writer, this.animator.EASES.get().getName()); + writer.write(ByteBuffer.allocate(4).putFloat(animator.getDuration()).array()); writer.close(); } catch (IOException e) { @@ -77,11 +73,9 @@ public class ConfigManager { } } - public ConfigManager(File configFile, Manager animation, Manager ease, ProgressManager progress) { + public ConfigManager(File configFile, Animator animator) { this.configFile = configFile; - this.animation = animation; - this.ease = ease; - this.progress = progress; + this.animator = animator; reload(); } diff --git a/src/main/java/me/topchetoeu/animatedchunks/Manager.java b/src/main/java/me/topchetoeu/animatedchunks/Manager.java index ac172ac..f46fe6b 100644 --- a/src/main/java/me/topchetoeu/animatedchunks/Manager.java +++ b/src/main/java/me/topchetoeu/animatedchunks/Manager.java @@ -7,21 +7,7 @@ import java.util.Map; import org.apache.commons.lang3.Validate; -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; - public final class Manager { - public static interface RegisterEvent { - public void register(Manager manager); - } - public static final Event> createEvent() { - return EventFactory.createArrayBacked(RegisterEvent.class, (listeners) -> (manager) -> { - for (RegisterEvent listener: listeners) { - listener.register(manager); - } - }); - } - private String currName = null; private Map> objects = new Hashtable<>(); @@ -75,8 +61,8 @@ public final class Manager { return Collections.unmodifiableCollection(objects.values()); } - public Manager(T _default) { - register(new Descriptor<>(_default, "default").displayName("Default").author("TopchetoEU")); + public Manager(Descriptor _default) { + register(_default); set("default"); } } diff --git a/src/main/java/me/topchetoeu/animatedchunks/animation/ProgressManager.java b/src/main/java/me/topchetoeu/animatedchunks/animation/Animator.java similarity index 73% rename from src/main/java/me/topchetoeu/animatedchunks/animation/ProgressManager.java rename to src/main/java/me/topchetoeu/animatedchunks/animation/Animator.java index bb39db9..f86ea03 100644 --- a/src/main/java/me/topchetoeu/animatedchunks/animation/ProgressManager.java +++ b/src/main/java/me/topchetoeu/animatedchunks/animation/Animator.java @@ -1,146 +1,184 @@ -package me.topchetoeu.animatedchunks.animation; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Hashtable; - -public final class ProgressManager { - public static class ChunkLoc { - public final int x; - public final int y; - public final int z; - - @Override - public boolean equals(Object obj) { - return obj instanceof ChunkLoc && ((ChunkLoc)obj).x == x && ((ChunkLoc)obj).y == y && ((ChunkLoc)obj).z == z; - } - - @Override - public int hashCode() { - return 137 * x + 149 * y + 163 * z; - } - - public ChunkLoc(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - } - - private Hashtable chunkToStage = new Hashtable<>(); - private HashSet chunks = new HashSet<>(); - private float duration = 1; - - public ProgressManager() { - - } - - public float getDuration() { - return duration; - } - public void setDuration(float duration) { - this.duration = duration; - } - - /** - * Removes all loaded chunks (called when a world is unloaded and loaded) - */ - public void reset() { - chunkToStage.clear(); - chunks.clear(); - } - /** - * Advances the animation for all tracked chunks, according to the duration and the specified delta - * @param delta The second delta to advance the animation by - */ - public void tick(float delta) { - for (ChunkLoc loc : new ArrayList<>(chunkToStage.keySet())) { - float val = chunkToStage.get(loc); - val += delta / duration; - if (val > 1f) chunkToStage.remove(loc); - chunkToStage.put(loc, val); - } - } - - /** - * Loads a specified chunk (starts tracking its animation) - * @param x The x of the chunk - * @param y The y of the chunk - * @param y The z of the chunk - */ - public void load(int x, int y, int z) { - if (isChunkLoaded(x, y, z)) return; - ChunkLoc loc = new ChunkLoc(x, y, z); - chunks.add(loc); - chunkToStage.put(loc, 0f); - } - /** - * Unloads a specified chunk (stops tracking its animation) - * @param x The x of the chunk - * @param y The y of the chunk - * @param y The z of the chunk - */ - public void unload(int x, int y, int z) { - ChunkLoc loc = new ChunkLoc(x, y, z); - chunkToStage.remove(loc); - chunks.remove(loc); - } - /** - * Unloads all loaded chunks - */ - public void unloadAll() { - chunkToStage.clear(); - chunks.clear(); - } - /** - * Unloads all the chunks that are outside the render distance specified - * @param viewDistance The view distance (in chunks, radius) - * @param playerChunkX The x coordinate of the chunk in which the player stands - * @param playerChunkY The y coordinate of the chunk in which the player stands - * @param playerChunkZ The z coordinate of the chunk in which the player stands - */ - public void unloadAllFar(int viewDistance, int playerChunkX, int playerChunkY, int playerChunkZ) { - float circleVD = viewDistance + 1.38f; - int squareVD = viewDistance; - - for (ChunkLoc loc : new ArrayList<>(chunks)) { - int chunkX = loc.x / 16; - int chunkZ = loc.z / 16; - - int diffSquareX = playerChunkX - chunkX ; - int diffSquareZ = playerChunkZ - chunkZ; - - int diffCircleX = playerChunkX - chunkX; - int diffCircleZ = playerChunkZ - chunkZ; - - int dist = diffCircleX * diffCircleX + diffCircleZ * diffCircleZ; - - if (dist > circleVD * circleVD) unload(loc.x, loc.y, loc.z); - if (Math.abs(diffSquareX) > squareVD || Math.abs(diffSquareZ) > squareVD) unload(loc.x, loc.y, loc.z); - } - } - - /** - * Checks whether or not a chunk is loaded - * @param x The x of the chunk - * @param y The y of the chunk - * @param y The z of the chunk - * @return A value indicating whether or not the specified chunk is tracked - */ - public boolean isChunkLoaded(int x, int y, int z) { - return chunks.contains(new ChunkLoc(x, y, z)); - } - - /** - * Gets the animation progress of the specified chunk - * @param x The x of the chunk - * @param y The y of the chunk - * @param y The z of the chunk - * @return A float value from 0 to 1 (0 if the chunk is not tracked), indicating the animation progress of the specified chunk - */ - public float getChunkProgress(int x, int y, int z) { - if (!isChunkLoaded(x, y, z)) return 0f; - if (!chunkToStage.containsKey(new ChunkLoc(x, y, z))) return 1f; - return chunkToStage.get(new ChunkLoc(x, y, z)); - } -} +package me.topchetoeu.animatedchunks.animation; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Hashtable; + +import me.topchetoeu.animatedchunks.Manager; +import me.topchetoeu.animatedchunks.easing.Ease; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.util.math.Vector3d; +import net.minecraft.util.math.BlockPos; + +public final class Animator { + public static class ChunkLoc { + public final int x; + public final int y; + public final int z; + + @Override + public boolean equals(Object obj) { + return obj instanceof ChunkLoc && ((ChunkLoc)obj).x == x && ((ChunkLoc)obj).y == y && ((ChunkLoc)obj).z == z; + } + @Override + public int hashCode() { + return 137 * x + 149 * y + 163 * z; + } + + public ChunkLoc(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + } + + public final Manager ANIMATIONS; + public final Manager EASES; + + private Hashtable chunkToStage = new Hashtable<>(); + private HashSet chunks = new HashSet<>(); + private float duration = 1; + + public Animator(Manager animations, Manager eases) { + ANIMATIONS = animations; + EASES = eases; + } + + public float getDuration() { + return duration; + } + public void setDuration(float duration) { + this.duration = duration; + } + + /** + * Removes all loaded chunks (called when a world is unloaded and loaded) + */ + public void reset() { + chunkToStage.clear(); + chunks.clear(); + } + /** + * Advances the animation for all tracked chunks, according to the duration and the specified delta + * @param delta The second delta to advance the animation by + */ + public void tick(float delta) { + for (ChunkLoc loc : new ArrayList<>(chunkToStage.keySet())) { + float val = chunkToStage.get(loc); + val += delta / duration; + if (val > 1f) chunkToStage.remove(loc); + chunkToStage.put(loc, val); + } + } + + /** + * Loads a specified chunk (starts tracking its animation) + * @param x The x of the chunk + * @param y The y of the chunk + * @param y The z of the chunk + */ + public void load(int x, int y, int z) { + if (isChunkLoaded(x, y, z)) return; + ChunkLoc loc = new ChunkLoc(x, y, z); + chunks.add(loc); + chunkToStage.put(loc, 0f); + } + /** + * Unloads a specified chunk (stops tracking its animation) + * @param x The x of the chunk + * @param y The y of the chunk + * @param y The z of the chunk + */ + public void unload(int x, int y, int z) { + ChunkLoc loc = new ChunkLoc(x, y, z); + chunkToStage.remove(loc); + chunks.remove(loc); + } + /** + * Unloads all loaded chunks + */ + public void unloadAll() { + chunkToStage.clear(); + chunks.clear(); + } + /** + * Unloads all the chunks that are outside the render distance specified + * @param viewDistance The view distance (in chunks, radius) + * @param playerChunkX The x coordinate of the chunk in which the player stands + * @param playerChunkY The y coordinate of the chunk in which the player stands + * @param playerChunkZ The z coordinate of the chunk in which the player stands + */ + public void unloadAllFar(int viewDistance, int playerChunkX, int playerChunkY, int playerChunkZ) { + float circleVD = viewDistance + 1.38f; + int squareVD = viewDistance; + + for (ChunkLoc loc : new ArrayList<>(chunks)) { + int chunkX = loc.x / 16; + int chunkZ = loc.z / 16; + + int diffSquareX = playerChunkX - chunkX ; + int diffSquareZ = playerChunkZ - chunkZ; + + int diffCircleX = playerChunkX - chunkX; + int diffCircleZ = playerChunkZ - chunkZ; + + int dist = diffCircleX * diffCircleX + diffCircleZ * diffCircleZ; + + if (dist > circleVD * circleVD) unload(loc.x, loc.y, loc.z); + if (Math.abs(diffSquareX) > squareVD || Math.abs(diffSquareZ) > squareVD) unload(loc.x, loc.y, loc.z); + } + } + + /** + * Checks whether or not a chunk is loaded + * @param x The x of the chunk + * @param y The y of the chunk + * @param y The z of the chunk + * @return A value indicating whether or not the specified chunk is tracked + */ + public boolean isChunkLoaded(int x, int y, int z) { + return chunks.contains(new ChunkLoc(x, y, z)); + } + + /** + * Gets the animation progress of the specified chunk + * @param x The x of the chunk + * @param y The y of the chunk + * @param y The z of the chunk + * @return A float value from 0 to 1 (0 if the chunk is not tracked), indicating the animation progress of the specified chunk + */ + public float getChunkProgress(int x, int y, int z) { + if (!isChunkLoaded(x, y, z)) return 0f; + if (!chunkToStage.containsKey(new ChunkLoc(x, y, z))) return 1f; + return chunkToStage.get(new ChunkLoc(x, y, z)); + } + + public void animate(MatrixStack matrices, float progress, BlockPos chunkPos, Vector3d playerPos) { + if (progress < 0) progress = 0; + if (progress > 1) progress = 1; + if (progress < 0.999) { + float _progress = EASES.getValue().ease(progress); + ANIMATIONS.getValue().animate( + _progress, matrices, + chunkPos.getX() * 16, 0, chunkPos.getZ() * 16, + (float)playerPos.x, (float)playerPos.y, (float)playerPos.z + ); + // matrices.translate(0, 0, 16); + } + } + public void animate(MatrixStack matrices, BlockPos chunkPos, Vector3d playerPos) { + if (!isChunkLoaded(chunkPos.getX(), chunkPos.getY(), chunkPos.getZ())) { + matrices.scale(0, 0, 0); + } + else { + animate(matrices, getChunkProgress(chunkPos.getX(), chunkPos.getY(), chunkPos.getZ()), chunkPos, playerPos); + } + } + + public void animate(MatrixStack matrices, BlockPos chunkPos) { + animate(matrices, chunkPos, new Vector3d(0, 0, 0)); + } + public void animate(MatrixStack matrices, float progress, BlockPos chunkPos) { + animate(matrices, progress, chunkPos, new Vector3d(0, 0, 0)); + } +} diff --git a/src/main/java/me/topchetoeu/animatedchunks/gui/AnimatedChunksScreen.java b/src/main/java/me/topchetoeu/animatedchunks/gui/AnimatedChunksScreen.java index ffec4a8..5841ae0 100644 --- a/src/main/java/me/topchetoeu/animatedchunks/gui/AnimatedChunksScreen.java +++ b/src/main/java/me/topchetoeu/animatedchunks/gui/AnimatedChunksScreen.java @@ -9,19 +9,15 @@ import net.minecraft.util.Formatting; import net.minecraft.util.math.ColorHelper.Argb; import me.topchetoeu.animatedchunks.ConfigManager; import me.topchetoeu.animatedchunks.Manager; -import me.topchetoeu.animatedchunks.animation.Animation; -import me.topchetoeu.animatedchunks.animation.ProgressManager; -import me.topchetoeu.animatedchunks.easing.Ease; +import me.topchetoeu.animatedchunks.animation.Animator; import me.topchetoeu.animatedchunks.gui.Section.OrderType; import net.minecraft.client.MinecraftClient; public class AnimatedChunksScreen extends Screen { public final Screen parent; private final HorizontalSection mainSection = new HorizontalSection(); - private final Manager animation; - private final Manager ease; private final ConfigManager config; - private final ProgressManager progress; + private final Animator animator; public static void playClick() { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0f)); @@ -65,7 +61,7 @@ public class AnimatedChunksScreen extends Screen { res.x = res.y = 5; res.title = Text.of("Preview:"); - res.children.addSelectableChild(new ChunkPreview(0, 0, 150, 150)); + res.children.addSelectableChild(new ChunkPreview(0, 0, 150, 150, animator)); return res; } @@ -100,10 +96,10 @@ public class AnimatedChunksScreen extends Screen { private Section durationSection() { var res = new HorizontalSection(); res.setTargetWidth(width / 2); - var input = new NumberInput(res, 5, 5, progress.getDuration(), (sender, val) -> { + var input = new NumberInput(res, 5, 5, animator.getDuration(), (sender, val) -> { if (val <= 0) sender.invalid = true; else { - progress.setDuration(val); + animator.setDuration(val); sender.invalid = false; } }); @@ -117,18 +113,16 @@ public class AnimatedChunksScreen extends Screen { var res = new HorizontalSection(); res.x = res.y = 5; res.title = Text.of("Animation config:"); - res.children.addSelectableChild(selectionSection(animation, "Animation")); - res.children.addSelectableChild(selectionSection(ease, "Ease")); + res.children.addSelectableChild(selectionSection(animator.ANIMATIONS, "Animation")); + res.children.addSelectableChild(selectionSection(animator.EASES, "Ease")); res.children.addSelectableChild(durationSection()); return res; } - public AnimatedChunksScreen(Screen parent, Manager animation, Manager ease, ConfigManager config, ProgressManager progress) { + public AnimatedChunksScreen(Screen parent, ConfigManager config, Animator animator) { super(Text.of("Animated Chunks Config")); config.reload(); - this.progress = progress; - this.animation = animation; - this.ease = ease; + this.animator = animator; this.config = config; mainSection.x = mainSection.y = 5; diff --git a/src/main/java/me/topchetoeu/animatedchunks/gui/ChunkPreview.java b/src/main/java/me/topchetoeu/animatedchunks/gui/ChunkPreview.java index c774718..300cf59 100644 --- a/src/main/java/me/topchetoeu/animatedchunks/gui/ChunkPreview.java +++ b/src/main/java/me/topchetoeu/animatedchunks/gui/ChunkPreview.java @@ -5,7 +5,7 @@ import org.lwjgl.opengl.GL11; import com.mojang.blaze3d.systems.RenderSystem; -import me.topchetoeu.animatedchunks.AnimatedChunks; +import me.topchetoeu.animatedchunks.animation.Animator; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.DrawableHelper; @@ -20,6 +20,7 @@ import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Quaternion; import net.minecraft.util.math.Vec3f; @@ -31,8 +32,10 @@ public class ChunkPreview extends DrawableHelper implements Drawable, Element, S void onClick(); } - public ClickAction clickAction; public final MinecraftClient client; + public final Animator animator; + + public ClickAction clickAction; private boolean clicked = false; private boolean rotating = false; private boolean focused = false; @@ -158,6 +161,7 @@ public class ChunkPreview extends DrawableHelper implements Drawable, Element, S RenderSystem.enableBlend(); } private void renderChunk(MatrixStack matrices, int x, int y, int n, float delta) { + duration = animator.getDuration(); matrices.push(); matrices.translate(x * 16 - 8, 0, y * 16 - 8); @@ -165,16 +169,19 @@ public class ChunkPreview extends DrawableHelper implements Drawable, Element, S // y += n; float progress = globalProgress / duration - (float)Math.sqrt(x * x + y * y) / (float)n / 2; - if (progress < 0) progress = 0; - if (progress > 1) progress = 1; - if (progress < 0.999) { - float _progress = AnimatedChunks.getInstance().getEaseManager().getValue().ease(progress); - AnimatedChunks.getInstance().getAnimationManager().getValue().animate( - _progress, matrices, - x * 16, 0, y * 16, 0, 0, 0 - ); - // matrices.translate(0, 0, 16); - } + + animator.animate(matrices, progress, new BlockPos(x * 16, 0, y * 16)); + + // if (progress < 0) progress = 0; + // if (progress > 1) progress = 1; + // if (progress < 0.999) { + // float _progress = animator.EASES.getValue().ease(progress); + // AnimatedChunks.getInstance().getAnimationManager().getValue().animate( + // _progress, matrices, + // x * 16, 0, y * 16, 0, 0, 0 + // ); + // // matrices.translate(0, 0, 16); + // } matrices.translate(0, 0, 16); matrices.multiply(rotation); myFill(matrices, 2, 1, 14, 2, progress, 1, 1, 1); @@ -185,7 +192,6 @@ public class ChunkPreview extends DrawableHelper implements Drawable, Element, S matrices.pop(); } private void renderChunks(MatrixStack matrices, float delta, int n) { - duration = AnimatedChunks.getInstance().getProgressManager().getDuration(); // globalProgress += (lastTime - (lastTime = System.nanoTime())) / -1000000000f; globalProgress += delta * 0.05f; matrices.push(); @@ -316,16 +322,18 @@ public class ChunkPreview extends DrawableHelper implements Drawable, Element, S return false; } - public ChunkPreview(int x, int y) { + public ChunkPreview(int x, int y, Animator animator) { this.client = MinecraftClient.getInstance(); this.x = x; this.y = y; + this.animator = animator; } - public ChunkPreview(int x, int y, int w, int h) { + public ChunkPreview(int x, int y, int w, int h, Animator animator) { this.client = MinecraftClient.getInstance(); this.x = x; this.y = y; this.width = w; this.height = h; + this.animator = animator; } } diff --git a/src/main/java/me/topchetoeu/animatedchunks/mixin/BuiltChunkMixin.java b/src/main/java/me/topchetoeu/animatedchunks/mixin/BuiltChunkMixin.java index 8961917..c5d1c09 100644 --- a/src/main/java/me/topchetoeu/animatedchunks/mixin/BuiltChunkMixin.java +++ b/src/main/java/me/topchetoeu/animatedchunks/mixin/BuiltChunkMixin.java @@ -11,12 +11,12 @@ import net.minecraft.util.math.BlockPos; // From flogic's mod @Mixin(ChunkBuilder.BuiltChunk.class) -abstract class BuiltChunkMixin { +public abstract class BuiltChunkMixin { @Inject(method = "clear", at = @At(value = "TAIL"), cancellable = true) public void clear(CallbackInfo ci) { // ci.cancel(); // return; BlockPos origin = ((ChunkBuilder.BuiltChunk)(Object)this).getOrigin(); - AnimatedChunks.getInstance().getProgressManager().unload(origin.getX(), 0, origin.getZ()); + AnimatedChunks.getInstance().animator.unload(origin.getX(), 0, origin.getZ()); } } \ No newline at end of file diff --git a/src/main/java/me/topchetoeu/animatedchunks/mixin/WorldRendererMixin.java b/src/main/java/me/topchetoeu/animatedchunks/mixin/WorldRendererMixin.java index b411062..32be951 100644 --- a/src/main/java/me/topchetoeu/animatedchunks/mixin/WorldRendererMixin.java +++ b/src/main/java/me/topchetoeu/animatedchunks/mixin/WorldRendererMixin.java @@ -11,6 +11,7 @@ import net.minecraft.client.render.WorldRenderer; import net.minecraft.client.render.WorldRenderer.ChunkInfo; import net.minecraft.client.render.chunk.ChunkBuilder.BuiltChunk; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.util.math.Vector3d; import net.minecraft.util.math.Matrix4f; import org.spongepowered.asm.mixin.Mixin; @@ -22,22 +23,17 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import it.unimi.dsi.fastutil.objects.ObjectListIterator; import me.topchetoeu.animatedchunks.AnimatedChunks; -import me.topchetoeu.animatedchunks.animation.ProgressManager; @Mixin(WorldRenderer.class) -abstract class WorldRendererMixin { +public abstract class WorldRendererMixin { private long lastTime = System.nanoTime(); @Accessor abstract BuiltChunkStorage getChunks(); - private ProgressManager getProgressManager() { - return AnimatedChunks.getInstance().getProgressManager(); - } - @Inject(method = "render", at = @At(value = "HEAD")) private void renderStart(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci) { long currTime = System.nanoTime(); - getProgressManager().tick((currTime - lastTime) / 1000000000f); + AnimatedChunks.getInstance().animator.tick((currTime - lastTime) / 1000000000f); lastTime = currTime; } @@ -51,7 +47,7 @@ abstract class WorldRendererMixin { if (playerY < 0) chunkY--; if (playerZ < 0) chunkZ--; - getProgressManager().unloadAllFar((int)((WorldRenderer)(Object)this).getViewDistance(), chunkX, chunkY, chunkZ); + AnimatedChunks.getInstance().animator.unloadAllFar((int)((WorldRenderer)(Object)this).getViewDistance(), chunkX, chunkY, chunkZ); } @Inject(method = "renderLayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gl/VertexBuffer;drawElements()V"), locals=LocalCapture.CAPTURE_FAILHARD) private void renderChunkBefore(RenderLayer renderLayer, MatrixStack matrices, double playerX, double playerY, double playerZ, Matrix4f positionMatrix, CallbackInfo ci, @@ -59,28 +55,26 @@ abstract class WorldRendererMixin { matrices.push(); - int x = chunk.getOrigin().getX(); - int y = chunk.getOrigin().getY(); - int z = chunk.getOrigin().getZ(); + AnimatedChunks.getInstance().animator.animate(matrices, chunk.getOrigin(), new Vector3d(playerX, playerY, playerZ)); - if (getProgressManager().isChunkLoaded(x, 0, z)) { - float progress = getProgressManager().getChunkProgress(x, 0, z); + // if (getProgressManager().isChunkLoaded(x, 0, z)) { + // float progress = getProgressManager().getChunkProgress(x, 0, z); - if (progress < 0.999) { - progress = AnimatedChunks.getInstance().getEaseManager().getValue().ease(progress); + // if (progress < 0.999) { + // progress = AnimatedChunks.getInstance().getEaseManager().getValue().ease(progress); - float centerX = (float)playerX - x; - float centerY = (float)playerY - y; - float centerZ = (float)playerZ - z; + // float centerX = (float)playerX - x; + // float centerY = (float)playerY - y; + // float centerZ = (float)playerZ - z; - matrices.translate(-centerX, -centerY, -centerZ); - AnimatedChunks.getInstance().getAnimationManager().getValue().animate(progress, matrices, x, y, z, (float)playerX, (float)playerY, (float)playerZ); - matrices.translate(centerX, centerY, centerZ); - } - } - else { - matrices.scale(0, 0, 0); - } + // matrices.translate(-centerX, -centerY, -centerZ); + // AnimatedChunks.getInstance().getAnimationManager().getValue().animate(progress, matrices, x, y, z, (float)playerX, (float)playerY, (float)playerZ); + // matrices.translate(centerX, centerY, centerZ); + // } + // } + // else { + // matrices.scale(0, 0, 0); + // } shader.modelViewMat.set(matrices.peek().getPositionMatrix()); matrices.pop(); @@ -91,6 +85,6 @@ abstract class WorldRendererMixin { boolean _1, ObjectListIterator _2, Shader shader, GlUniform _4, ChunkInfo _6, BuiltChunk chunk) { int x = chunk.getOrigin().getX(); int z = chunk.getOrigin().getZ(); - getProgressManager().load(x, 0, z); + AnimatedChunks.getInstance().animator.load(x, 0, z); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ff4c701..be134ab 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,6 @@ "modmenu": ">=4.0.0" }, "breaks": { - "sodium": "*", - "iris": "*" + "sodium": "*" } }