From 05096f0492f59ca9100eb7535df90e97cd71bd27 Mon Sep 17 00:00:00 2001 From: flogic Date: Mon, 26 Oct 2020 19:34:25 -0600 Subject: [PATCH] Add translation amount config option --- .../client/config/SmoothChunksConfig.java | 19 ++++++++++++++++++- .../client/handler/ChunkAnimationHandler.java | 8 ++++---- .../assets/smooth-chunks/lang/en_us.json | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/cc/flogi/dev/smoothchunks/client/config/SmoothChunksConfig.java b/src/main/java/cc/flogi/dev/smoothchunks/client/config/SmoothChunksConfig.java index dfe7bc5..d4c6958 100644 --- a/src/main/java/cc/flogi/dev/smoothchunks/client/config/SmoothChunksConfig.java +++ b/src/main/java/cc/flogi/dev/smoothchunks/client/config/SmoothChunksConfig.java @@ -13,14 +13,31 @@ import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Comment; */ @Config(name = "smooth-chunks") @Config.Gui.Background("minecraft:textures/block/stone.png") @Getter public class SmoothChunksConfig implements ConfigData { + //TODO use localization for comment strings. @Comment("Duration of the animation in seconds.") - @ConfigEntry.BoundedDiscrete(min = 0, max = 4) double duration = 1; + @Comment("The amount the chunk moves to get to its final position.") + @ConfigEntry.BoundedDiscrete(min = 1, max = 10) + int translationAmount = 5; + @Comment("Type of animation for loading chunks.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) LoadAnimation loadAnimation = LoadAnimation.UPWARD; @Comment("Disable animating chunks close to you") boolean disableNearby = true; + + /* + * Custom Getters + */ + + /** + * Gets the config value for translation amount, translating config value to usable value. + * + * @return The translation amount as an int 1 to 10 where higher = more translation. + */ + public int getTranslationAmount() { + return translationAmount / 5; + } } \ No newline at end of file diff --git a/src/main/java/cc/flogi/dev/smoothchunks/client/handler/ChunkAnimationHandler.java b/src/main/java/cc/flogi/dev/smoothchunks/client/handler/ChunkAnimationHandler.java index 68b3c02..c35a18d 100644 --- a/src/main/java/cc/flogi/dev/smoothchunks/client/handler/ChunkAnimationHandler.java +++ b/src/main/java/cc/flogi/dev/smoothchunks/client/handler/ChunkAnimationHandler.java @@ -45,7 +45,7 @@ public final class ChunkAnimationHandler { } } - animations.put(chunk, new AnimationController(chunk.getOrigin(), direction, System.currentTimeMillis())); + animations.putIfAbsent(chunk, new AnimationController(chunk.getOrigin(), direction, System.currentTimeMillis())); } public void updateChunk(ChunkBuilder.BuiltChunk chunk, MatrixStack stack) { @@ -69,15 +69,15 @@ public final class ChunkAnimationHandler { switch (config.getLoadAnimation()) { default: case DOWNWARD: - stack.translate(0, finalPos.getY() - (completion * finalPos.getY()), 0); + stack.translate(0, (finalPos.getY() - completion * finalPos.getY()) * config.getTranslationAmount(), 0); break; case UPWARD: - stack.translate(0, -finalPos.getY() + (completion * finalPos.getY()), 0); + stack.translate(0, (-finalPos.getY() + completion * finalPos.getY()) * config.getTranslationAmount(), 0); break; case INWARD: if (controller.getDirection() == null) break; Vec3i dirVec = controller.getDirection().getVector(); - double mod = -(200 - UtilEasing.easeInOutSine(completion) * 200); + double mod = -(200 - UtilEasing.easeInOutSine(completion) * 200) * config.getTranslationAmount(); stack.translate(dirVec.getX() * mod, 0, dirVec.getZ() * mod); break; case SCALE: diff --git a/src/main/resources/assets/smooth-chunks/lang/en_us.json b/src/main/resources/assets/smooth-chunks/lang/en_us.json index b8a95e4..6525e69 100644 --- a/src/main/resources/assets/smooth-chunks/lang/en_us.json +++ b/src/main/resources/assets/smooth-chunks/lang/en_us.json @@ -2,5 +2,6 @@ "text.autoconfig.smooth-chunks.title": "Smooth Chunks Config", "text.autoconfig.smooth-chunks.option.loadAnimation": "Load Animation", "text.autoconfig.smooth-chunks.option.duration": "Duration", + "text.autoconfig.smooth-chunks.option.translationAmount": "Translation Amount", "text.autoconfig.smooth-chunks.option.disableNearby": "Disable for Nearby Chunks" } \ No newline at end of file