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'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = project.archives_base_name
version = project.mod_version as Object
group = project.maven_group as Object
@ -17,6 +14,16 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// 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}"
// 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.
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.47
loader_version=0.10.1+build.209
loader_version=0.10.3+build.211
# 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.24.0+build.411-1.16
fabric_version=0.24.1+build.412-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.SmoothChunksConfig;
import cc.flogi.dev.smoothchunks.util.UtilEasing;
import lombok.AllArgsConstructor;
import lombok.Data;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.chunk.ChunkBuilder;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import java.util.List;
import java.util.Objects;
import java.util.WeakHashMap;
import java.util.stream.Collectors;
/**
* @author Caden Kriese (flogic)
@ -26,7 +23,6 @@ public final class ChunkAnimationHandler {
private final boolean DISABLE_NEARBY;
private final WeakHashMap<ChunkBuilder.BuiltChunk, AnimationController> animations = new WeakHashMap<>();
// private final HashMap<ChunkBuilder.BuiltChunk, AnimationController> animations = new HashMap<>();
public ChunkAnimationHandler(SmoothChunksConfig config) {
DURATION = config.getDuration() * 1000;
@ -38,20 +34,16 @@ public final class ChunkAnimationHandler {
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);
if (controller == null || MinecraftClient.getInstance().getCameraEntity() == null) return;
// The chunk was not built last frame.
// if () {
//
// }
// if (chunk.rebuildFrame - renderer.frame > -1) {
// addChunk(chunk);
// controller = animations.get(chunk);
// }
if (DISABLE_NEARBY) {
BlockPos cameraPos = MinecraftClient.getInstance().getCameraEntity().getBlockPos();
BlockPos chunkPos = chunk.getOrigin();
//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;
completion = Math.min(completion, 1.0);
@ -61,10 +53,10 @@ public final class ChunkAnimationHandler {
switch (LOAD_ANIMATION) {
default:
case DOWNWARD:
stack.translate(0, 256 - chunkY - (completion * chunkY), 0);
stack.translate(0, 256 - chunkY - (UtilEasing.easeInOutSine(completion) * chunkY), 0);
break;
case UPWARD:
stack.translate(0, -chunkY + (completion * chunkY), 0);
stack.translate(0, -chunkY + (UtilEasing.easeInOutSine(completion) * chunkY), 0);
break;
// case INWARD:
// stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0);
@ -74,22 +66,6 @@ public final class ChunkAnimationHandler {
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
private static class AnimationController {
private BlockPos finalPos;

View File

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

@ -2,6 +2,3 @@ accessWidener v1 named
accessible class net/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk$RebuildTask
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": [],
"client": [
"WorldRendererMixin",
"ChunkBuilderMixin",
"BuiltChunkStorageMixin"
"ChunkBuilderMixin"
],
"injectors": {
"defaultRequire": 1