Minimizing & updating

This commit is contained in:
flogic 2020-10-24 01:17:39 -06:00
parent 9d731b8273
commit 81cfec154d
No known key found for this signature in database
GPG Key ID: AD25E4DF29DECD31
8 changed files with 46 additions and 55 deletions

View File

@ -3,9 +3,6 @@ plugins {
id 'maven-publish' id 'maven-publish'
} }
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = project.archives_base_name archivesBaseName = project.archives_base_name
version = project.mod_version as Object version = project.mod_version as Object
group = project.maven_group as Object group = project.maven_group as Object
@ -17,6 +14,16 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. // Fabric API.
// Make a collection of all api modules we wish to use
Set<String> apiModules = [
"fabric-api-base"
]
// Add each module as a dependency
apiModules.forEach {
modImplementation(fabricApi.module(it, project.fabric_version))
}
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Cloth Config / Autoconfig // Cloth Config / Autoconfig

View File

@ -1,14 +1,13 @@
# Check for updates on https://modmuss50.me/fabric.html
# Done to increase the memory available to gradle. # Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.3 minecraft_version=1.16.3
yarn_mappings=1.16.3+build.47 yarn_mappings=1.16.3+build.47
loader_version=0.10.1+build.209 loader_version=0.10.3+build.211
# Mod Properties # Mod Properties
mod_version=0.1.0-SNAPSHOT mod_version=0.1.0-SNAPSHOT
maven_group=cc.flogi.dev maven_group=cc.flogi.dev
archives_base_name=smooth-chunks archives_base_name=smooth-chunks
# Dependencies # Dependencies
# check this on https://modmuss50.me/fabric.html fabric_version=0.24.1+build.412-1.16
fabric_version=0.24.0+build.411-1.16

View File

@ -2,18 +2,15 @@ package cc.flogi.dev.smoothchunks.client.handler;
import cc.flogi.dev.smoothchunks.client.config.LoadAnimation; import cc.flogi.dev.smoothchunks.client.config.LoadAnimation;
import cc.flogi.dev.smoothchunks.client.config.SmoothChunksConfig; import cc.flogi.dev.smoothchunks.client.config.SmoothChunksConfig;
import cc.flogi.dev.smoothchunks.util.UtilEasing;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.chunk.ChunkBuilder; import net.minecraft.client.render.chunk.ChunkBuilder;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.List;
import java.util.Objects;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.stream.Collectors;
/** /**
* @author Caden Kriese (flogic) * @author Caden Kriese (flogic)
@ -26,7 +23,6 @@ public final class ChunkAnimationHandler {
private final boolean DISABLE_NEARBY; private final boolean DISABLE_NEARBY;
private final WeakHashMap<ChunkBuilder.BuiltChunk, AnimationController> animations = new WeakHashMap<>(); private final WeakHashMap<ChunkBuilder.BuiltChunk, AnimationController> animations = new WeakHashMap<>();
// private final HashMap<ChunkBuilder.BuiltChunk, AnimationController> animations = new HashMap<>();
public ChunkAnimationHandler(SmoothChunksConfig config) { public ChunkAnimationHandler(SmoothChunksConfig config) {
DURATION = config.getDuration() * 1000; DURATION = config.getDuration() * 1000;
@ -38,20 +34,16 @@ public final class ChunkAnimationHandler {
animations.put(chunk, new AnimationController(chunk.getOrigin(), System.currentTimeMillis())); animations.put(chunk, new AnimationController(chunk.getOrigin(), System.currentTimeMillis()));
} }
public void updateChunk(WorldRenderer renderer, WorldRenderer.ChunkInfo info, ChunkBuilder.BuiltChunk chunk, MatrixStack stack) { public void updateChunk(ChunkBuilder.BuiltChunk chunk, MatrixStack stack) {
AnimationController controller = animations.get(chunk); AnimationController controller = animations.get(chunk);
if (controller == null || MinecraftClient.getInstance().getCameraEntity() == null) return; if (controller == null || MinecraftClient.getInstance().getCameraEntity() == null) return;
// The chunk was not built last frame. if (DISABLE_NEARBY) {
// if () { BlockPos cameraPos = MinecraftClient.getInstance().getCameraEntity().getBlockPos();
// BlockPos chunkPos = chunk.getOrigin();
// }
// if (chunk.rebuildFrame - renderer.frame > -1) {
// addChunk(chunk);
// controller = animations.get(chunk);
// }
//TODO for disable_nearby, check if dY < radius || dX < radius. Or just check distSq for a minuscule performance hit. if (chunkPos.isWithinDistance(cameraPos, 32)) return;
}
double completion = (double) (System.currentTimeMillis() - controller.getStartTime()) / DURATION; double completion = (double) (System.currentTimeMillis() - controller.getStartTime()) / DURATION;
completion = Math.min(completion, 1.0); completion = Math.min(completion, 1.0);
@ -61,10 +53,10 @@ public final class ChunkAnimationHandler {
switch (LOAD_ANIMATION) { switch (LOAD_ANIMATION) {
default: default:
case DOWNWARD: case DOWNWARD:
stack.translate(0, 256 - chunkY - (completion * chunkY), 0); stack.translate(0, 256 - chunkY - (UtilEasing.easeInOutSine(completion) * chunkY), 0);
break; break;
case UPWARD: case UPWARD:
stack.translate(0, -chunkY + (completion * chunkY), 0); stack.translate(0, -chunkY + (UtilEasing.easeInOutSine(completion) * chunkY), 0);
break; break;
// case INWARD: // case INWARD:
// stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0); // stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0);
@ -74,22 +66,6 @@ public final class ChunkAnimationHandler {
if (completion >= 1.0) animations.remove(chunk); if (completion >= 1.0) animations.remove(chunk);
} }
private void cullDistantChunks(WorldRenderer renderer) {
List<ChunkBuilder.BuiltChunk> toCull = animations.keySet().stream().filter(chunk -> chunk.rebuildFrame - renderer.frame < -1).collect(Collectors.toList());
// .forEach(animations::remove);
if (toCull.size() > 0) {
System.out.printf("Found %d chunks. -- ", toCull.size());
System.out.printf("Frame difference is %d. -- ", toCull.get(0).rebuildFrame - renderer.frame);
String xBehind = toCull.get(0).getOrigin().getX() < Objects.requireNonNull(MinecraftClient.getInstance().getCameraEntity()).getBlockPos().getX() ? "behind" : "in-front of";
String zBehind = toCull.get(0).getOrigin().getZ() < Objects.requireNonNull(MinecraftClient.getInstance().getCameraEntity()).getBlockPos().getZ() ? "behind" : "in-front of";
System.out.printf("The chunk is %s you on the x-axis and %s you on the z-axis.\n", xBehind, zBehind);
}
// toCull.forEach(animations::remove);
}
@AllArgsConstructor @Data @AllArgsConstructor @Data
private static class AnimationController { private static class AnimationController {
private BlockPos finalPos; private BlockPos finalPos;

View File

@ -3,15 +3,12 @@ package cc.flogi.dev.smoothchunks.mixin;
import cc.flogi.dev.smoothchunks.client.SmoothChunksClient; import cc.flogi.dev.smoothchunks.client.SmoothChunksClient;
import net.minecraft.client.render.chunk.BlockBufferBuilderStorage; import net.minecraft.client.render.chunk.BlockBufferBuilderStorage;
import net.minecraft.client.render.chunk.ChunkBuilder; import net.minecraft.client.render.chunk.ChunkBuilder;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
/** /**
@ -21,19 +18,17 @@ import java.util.concurrent.CompletableFuture;
*/ */
@SuppressWarnings("rawtypes") @Mixin(ChunkBuilder.BuiltChunk.RebuildTask.class) @SuppressWarnings("rawtypes") @Mixin(ChunkBuilder.BuiltChunk.RebuildTask.class)
public abstract class ChunkBuilderMixin { public abstract class ChunkBuilderMixin {
//Parent class
@SuppressWarnings("ShadowTarget") @Shadow private ChunkBuilder.BuiltChunk field_20839; @SuppressWarnings("ShadowTarget") @Shadow private ChunkBuilder.BuiltChunk field_20839;
@Inject( @Inject(
method = "run", method = "run",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
args = "log=true",
target = "Ljava/util/Set;forEach(Ljava/util/function/Consumer;)V" target = "Ljava/util/Set;forEach(Ljava/util/function/Consumer;)V"
), )
locals = LocalCapture.CAPTURE_FAILHARD
) )
public void onSetOrigin(BlockBufferBuilderStorage buffers, CallbackInfoReturnable<CompletableFuture> cir, Vec3d vec3d, public void onSetOrigin(BlockBufferBuilderStorage buffers, CallbackInfoReturnable<CompletableFuture> cir) {
float f, float g, float h, ChunkBuilder.ChunkData chunkData, List list) {
SmoothChunksClient.get().getChunkAnimationHandler().addChunk(field_20839); SmoothChunksClient.get().getChunkAnimationHandler().addChunk(field_20839);
} }
} }

View File

@ -30,6 +30,6 @@ public abstract class WorldRendererMixin {
private void renderLayerInject(RenderLayer renderLayer, MatrixStack matrixStack, double d, double e, double f, private void renderLayerInject(RenderLayer renderLayer, MatrixStack matrixStack, double d, double e, double f,
CallbackInfo ci, boolean bl, ObjectListIterator objectListIterator, CallbackInfo ci, boolean bl, ObjectListIterator objectListIterator,
WorldRenderer.ChunkInfo chunkInfo2, ChunkBuilder.BuiltChunk builtChunk, VertexBuffer vertexBuffer) { WorldRenderer.ChunkInfo chunkInfo2, ChunkBuilder.BuiltChunk builtChunk, VertexBuffer vertexBuffer) {
SmoothChunksClient.get().getChunkAnimationHandler().updateChunk((WorldRenderer) (Object) this, chunkInfo2, builtChunk, matrixStack); SmoothChunksClient.get().getChunkAnimationHandler().updateChunk(builtChunk, matrixStack);
} }
} }

View File

@ -0,0 +1,18 @@
package cc.flogi.dev.smoothchunks.util;
/**
* @author Caden Kriese (flogic)
*
* Created on 10/24/2020
*/
public class UtilEasing {
private static final double PI = Math.PI;
public static double easeInOutSine(double completion) {
return -((Math.cos(PI * completion) - 1) / 2);
}
public static double easeOutSine(double completion) {
return Math.sin(PI * completion / 2);
}
}

View File

@ -1,7 +1,4 @@
accessWidener v1 named accessWidener v1 named
accessible class net/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk$RebuildTask accessible class net/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk$RebuildTask
accessible class net/minecraft/client/render/WorldRenderer$ChunkInfo accessible class net/minecraft/client/render/WorldRenderer$ChunkInfo
accessible field net/minecraft/client/render/WorldRenderer visibleChunks I
accessible field net/minecraft/client/render/WorldRenderer frame I
accessible field net/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk rebuildFrame I

View File

@ -6,8 +6,7 @@
"mixins": [], "mixins": [],
"client": [ "client": [
"WorldRendererMixin", "WorldRendererMixin",
"ChunkBuilderMixin", "ChunkBuilderMixin"
"BuiltChunkStorageMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1