diff --git a/.gitignore b/.gitignore index 361def5..252ab0c 100644 --- a/.gitignore +++ b/.gitignore @@ -118,3 +118,4 @@ run/ !gradle-wrapper.jar src/main/generated/ src/test/ +remappedSrc/ diff --git a/build.gradle b/build.gradle index 85635b6..9c067ed 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import org.apache.tools.ant.filters.ReplaceTokens + plugins { id 'fabric-loom' version '0.5-SNAPSHOT' id 'maven-publish' @@ -19,6 +21,19 @@ dependencies { // Fabric API. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + // Cloth Config / Autoconfig + modApi("me.shedaniel.cloth:config-2:4.8.2") { + exclude(group: "net.fabricmc.fabric-api") + exclude module: "modmenu" + } + modApi("me.sargunvohra.mcmods:autoconfig1u:3.2.2") { + exclude(group: "net.fabricmc.fabric-api") + } + include "me.shedaniel.cloth:config-2:4.8.2" + include "me.sargunvohra.mcmods:autoconfig1u:3.2.2" + + modImplementation "io.github.prospector:modmenu:1.14.6+build.31" + compileOnly 'org.projectlombok:lombok:1.18.12' annotationProcessor 'org.projectlombok:lombok:1.18.12' @@ -35,6 +50,7 @@ processResources { from(sourceSets.main.resources.srcDirs) { include "fabric.mod.json" +// filter(ReplaceTokens, tokens: [version: project.version]) expand "version": project.version } @@ -51,7 +67,7 @@ tasks.withType(JavaCompile) { } task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" + getArchiveClassifier().set("sources") from sourceSets.main.allSource } diff --git a/gradle.properties b/gradle.properties index d9483cb..e1edfe5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html minecraft_version=1.16.3 -yarn_mappings=1.16.3+build.11 -loader_version=0.9.3+build.207 +yarn_mappings=1.16.3+build.17 +loader_version=0.10.0+build.208 # Mod Properties mod_version=0.1.0-SNAPSHOT maven_group=cc.flogi.dev archives_base_name=smooth-chunks # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.21.0+build.407-1.16 +fabric_version=0.22.0+build.408-1.16 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bb8b2fc..12d38de 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..2b958d9 --- /dev/null +++ b/readme.md @@ -0,0 +1,5 @@ +![Smooth Chunks Logo](src/main/resources/assets/smooth-chunks/icon.png) + + + +# Smooth Chunks diff --git a/src/main/java/cc/flogi/dev/smoothchunks/client/ChunkAnimationHandler.java b/src/main/java/cc/flogi/dev/smoothchunks/client/ChunkAnimationHandler.java deleted file mode 100644 index a31b2bd..0000000 --- a/src/main/java/cc/flogi/dev/smoothchunks/client/ChunkAnimationHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -package cc.flogi.dev.smoothchunks.client; - -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.client.render.chunk.ChunkBuilder; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.BlockPos; - -import java.util.HashMap; - -/** - * @author Caden Kriese (flogic) - * - * Created on 09/27/2020 - */ -public class ChunkAnimationHandler { - private static final long DURATION = 1000; - - private static final HashMap animations = new HashMap<>(); - - public static void update(ChunkBuilder.BuiltChunk chunk, MatrixStack stack) { - AnimationController controller = animations.get(chunk); - - if (controller == null) { - controller = new AnimationController(chunk.getOrigin(), System.currentTimeMillis()); - animations.put(chunk, controller); - } - - double completion = (double) (System.currentTimeMillis() - controller.getStartTime()) / DURATION; - completion = Math.min(completion, 1.0); - - stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0); - - if (completion >= 1.0) animations.remove(chunk); - } - - @AllArgsConstructor @Data - private static class AnimationController { - private BlockPos finalPos; - private long startTime; - } -} diff --git a/src/main/java/cc/flogi/dev/smoothchunks/client/SmoothChunksClient.java b/src/main/java/cc/flogi/dev/smoothchunks/client/SmoothChunksClient.java index 2c20604..47cc520 100644 --- a/src/main/java/cc/flogi/dev/smoothchunks/client/SmoothChunksClient.java +++ b/src/main/java/cc/flogi/dev/smoothchunks/client/SmoothChunksClient.java @@ -1,5 +1,10 @@ package cc.flogi.dev.smoothchunks.client; +import cc.flogi.dev.smoothchunks.client.config.SmoothChunksConfig; +import cc.flogi.dev.smoothchunks.client.handler.ChunkAnimationHandler; +import lombok.Getter; +import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; +import me.sargunvohra.mcmods.autoconfig1u.serializer.Toml4jConfigSerializer; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -10,5 +15,18 @@ import net.fabricmc.api.Environment; * Created on 09/21/2020 */ @Environment(EnvType.CLIENT) public class SmoothChunksClient implements ClientModInitializer { - @Override public void onInitializeClient() {} + private static SmoothChunksClient instance; + public static SmoothChunksClient get() {return instance;} + + @Getter private SmoothChunksConfig config; + @Getter private ChunkAnimationHandler chunkAnimationHandler; + + @Override public void onInitializeClient() { + instance = this; + + AutoConfig.register(SmoothChunksConfig.class, Toml4jConfigSerializer::new); + config = AutoConfig.getConfigHolder(SmoothChunksConfig.class).getConfig(); + + chunkAnimationHandler = new ChunkAnimationHandler(config); + } } diff --git a/src/main/java/cc/flogi/dev/smoothchunks/client/config/LoadAnimation.java b/src/main/java/cc/flogi/dev/smoothchunks/client/config/LoadAnimation.java new file mode 100644 index 0000000..a46ecb3 --- /dev/null +++ b/src/main/java/cc/flogi/dev/smoothchunks/client/config/LoadAnimation.java @@ -0,0 +1,13 @@ +package cc.flogi.dev.smoothchunks.client.config; + +/** + * @author Caden Kriese (flogic) + * + * Created on 09/28/2020 + */ +public enum LoadAnimation { + DOWNWARD, + UPWARD, + INWARD, + FADE +} 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 new file mode 100644 index 0000000..3bc2ad4 --- /dev/null +++ b/src/main/java/cc/flogi/dev/smoothchunks/client/config/SmoothChunksConfig.java @@ -0,0 +1,26 @@ +package cc.flogi.dev.smoothchunks.client.config; + +import lombok.Getter; +import me.sargunvohra.mcmods.autoconfig1u.ConfigData; +import me.sargunvohra.mcmods.autoconfig1u.annotation.Config; +import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry; +import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Comment; + +/** + * @author Caden Kriese (flogic) + * + * Created on 09/28/2020 + */ +@Config(name = "smooth-chunks") @Config.Gui.Background("minecraft:textures/block/stone.png") @Getter +public class SmoothChunksConfig implements ConfigData { + @Comment("Duration of the animation in seconds.") + @ConfigEntry.BoundedDiscrete(min = 0, max=10) + int duration = 1; + + @Comment("Type of animation for loading chunks.") + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + LoadAnimation loadAnimation = LoadAnimation.DOWNWARD; + + @Comment("Disable animating chunks close to you") + boolean disableNearby = false; +} \ No newline at end of file diff --git a/src/main/java/cc/flogi/dev/smoothchunks/client/config/SmoothChunksModMenu.java b/src/main/java/cc/flogi/dev/smoothchunks/client/config/SmoothChunksModMenu.java new file mode 100644 index 0000000..0c2d5d5 --- /dev/null +++ b/src/main/java/cc/flogi/dev/smoothchunks/client/config/SmoothChunksModMenu.java @@ -0,0 +1,21 @@ +package cc.flogi.dev.smoothchunks.client.config; + +import io.github.prospector.modmenu.api.ConfigScreenFactory; +import io.github.prospector.modmenu.api.ModMenuApi; +import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screen.Screen; + +/** + * @author Caden Kriese (flogic) + * + * Created on 09/28/2020 + */ +@Environment(EnvType.CLIENT) +public class SmoothChunksModMenu implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return (ConfigScreenFactory) parent -> AutoConfig.getConfigScreen(SmoothChunksConfig.class, parent).get(); + } +} 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 new file mode 100644 index 0000000..0161b55 --- /dev/null +++ b/src/main/java/cc/flogi/dev/smoothchunks/client/handler/ChunkAnimationHandler.java @@ -0,0 +1,71 @@ +package cc.flogi.dev.smoothchunks.client.handler; + +import cc.flogi.dev.smoothchunks.client.config.LoadAnimation; +import cc.flogi.dev.smoothchunks.client.config.SmoothChunksConfig; +import lombok.AllArgsConstructor; +import lombok.Data; +import net.minecraft.client.render.chunk.ChunkBuilder; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.math.BlockPos; + +import java.util.ArrayList; +import java.util.List; +import java.util.WeakHashMap; + +/** + * @author Caden Kriese (flogic) + * + * Created on 09/27/2020 + */ +public final class ChunkAnimationHandler { + private final long DURATION; + private final LoadAnimation LOAD_ANIMATION; + private final boolean DISABLE_NEARBY; + + private final WeakHashMap animations = new WeakHashMap<>(); + private final List completedChunks = new ArrayList<>(); + + public ChunkAnimationHandler(SmoothChunksConfig config) { + DURATION = config.getDuration() * 1000; + LOAD_ANIMATION = config.getLoadAnimation(); + DISABLE_NEARBY = config.isDisableNearby(); + } + + public void update(ChunkBuilder.BuiltChunk chunk, MatrixStack stack) { + if (completedChunks.contains(chunk.getOrigin())) return; + + AnimationController controller = animations.get(chunk); + + if (controller == null) { + controller = new AnimationController(chunk.getOrigin(), System.currentTimeMillis()); + animations.put(chunk, controller); + } + + double completion = (double) (System.currentTimeMillis() - controller.getStartTime()) / DURATION; + completion = Math.min(completion, 1.0); + + switch (LOAD_ANIMATION) { + default: + case UPWARD: + stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0); + break; + case DOWNWARD: + stack.translate(0, -(1 - completion) * controller.getFinalPos().getY(), 0); + break; +// case INWARD: +// stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0); +// break; + } + + if (completion >= 1.0) { + completedChunks.add(chunk.getOrigin()); + animations.remove(chunk); + } + } + + @AllArgsConstructor @Data + private static class AnimationController { + private BlockPos finalPos; + private long startTime; + } +} diff --git a/src/main/java/cc/flogi/dev/smoothchunks/mixin/WorldRendererMixin.java b/src/main/java/cc/flogi/dev/smoothchunks/mixin/WorldRendererMixin.java index 5085877..4ad71a0 100644 --- a/src/main/java/cc/flogi/dev/smoothchunks/mixin/WorldRendererMixin.java +++ b/src/main/java/cc/flogi/dev/smoothchunks/mixin/WorldRendererMixin.java @@ -1,18 +1,13 @@ package cc.flogi.dev.smoothchunks.mixin; -import cc.flogi.dev.smoothchunks.client.ChunkAnimationHandler; -import it.unimi.dsi.fastutil.objects.ObjectList; +import cc.flogi.dev.smoothchunks.client.SmoothChunksClient; import it.unimi.dsi.fastutil.objects.ObjectListIterator; import net.minecraft.client.gl.VertexBuffer; -import net.minecraft.client.render.BuiltChunkStorage; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.WorldRenderer; import net.minecraft.client.render.chunk.ChunkBuilder; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.client.world.ClientWorld; -import org.spongepowered.asm.mixin.Final; 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.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -32,12 +27,9 @@ public abstract class WorldRendererMixin { target = "Lnet/minecraft/client/gl/VertexBuffer;bind()V"), locals = LocalCapture.CAPTURE_FAILHARD ) - private void rotateRender(RenderLayer renderLayer, MatrixStack matrixStack, double d, double e, double f, - CallbackInfo ci, boolean bl, ObjectListIterator objectListIterator, - WorldRenderer.ChunkInfo chunkInfo2, ChunkBuilder.BuiltChunk builtChunk, VertexBuffer vertexBuffer) { - int chunkX = builtChunk.getOrigin().getX() / 16; - int chunkZ = builtChunk.getOrigin().getZ() / 16; - - ChunkAnimationHandler.update(builtChunk, matrixStack); + private void renderLayerInject(RenderLayer renderLayer, MatrixStack matrixStack, double d, double e, double f, + CallbackInfo ci, boolean bl, ObjectListIterator objectListIterator, + WorldRenderer.ChunkInfo chunkInfo2, ChunkBuilder.BuiltChunk builtChunk, VertexBuffer vertexBuffer) { + SmoothChunksClient.get().getChunkAnimationHandler().update(builtChunk, matrixStack); } } diff --git a/src/main/resources/assets/smooth-chunks/icon.png b/src/main/resources/assets/smooth-chunks/icon.png index a23f69e..2830bf2 100644 Binary files a/src/main/resources/assets/smooth-chunks/icon.png and b/src/main/resources/assets/smooth-chunks/icon.png differ diff --git a/src/main/resources/assets/smooth-chunks/lang/en_us.json b/src/main/resources/assets/smooth-chunks/lang/en_us.json new file mode 100644 index 0000000..b8a95e4 --- /dev/null +++ b/src/main/resources/assets/smooth-chunks/lang/en_us.json @@ -0,0 +1,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.disableNearby": "Disable for Nearby Chunks" +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 29020e2..01d9e5f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "smooth-chunks", - "version": "${version}", + "version": "@version@", "name": "Smooth Chunks", "description": "Smooth chunk load animations.", "authors": [ @@ -12,10 +12,14 @@ "repo": "repo.flogi.cc" }, "license": "MIT", - "accessWidener" : "smooth-chunks.accesswidener", "icon": "assets/smooth-chunks/icon.png", "environment": "client", + "accessWidener": "smooth-chunks.accesswidener", + "modmenu:clientsideOnly": "true", "entrypoints": { + "modmenu": [ + "cc.flogi.dev.smoothchunks.client.config.SmoothChunksModMenu" + ], "client": [ "cc.flogi.dev.smoothchunks.client.SmoothChunksClient" ], diff --git a/src/main/resources/smooth-chunks.accesswidener b/src/main/resources/smooth-chunks.accesswidener new file mode 100644 index 0000000..425f838 --- /dev/null +++ b/src/main/resources/smooth-chunks.accesswidener @@ -0,0 +1,3 @@ +accessWidener v1 named + +accessible class net/minecraft/client/render/WorldRenderer$ChunkInfo \ No newline at end of file diff --git a/src/main/resources/smooth-chunks.mixins.json b/src/main/resources/smooth-chunks.mixins.json index b74817b..6435739 100644 --- a/src/main/resources/smooth-chunks.mixins.json +++ b/src/main/resources/smooth-chunks.mixins.json @@ -3,11 +3,8 @@ "minVersion": "0.8", "package": "cc.flogi.dev.smoothchunks.mixin", "compatibilityLevel": "JAVA_8", - "mixins": [ - "BuiltChunkMixin" - ], + "mixins": [], "client": [ - "BuiltChunkStorageMixin", "WorldRendererMixin" ], "injectors": {