Initial Commit
This commit is contained in:
12
src/main/java/cc/flogi/dev/smoothchunks/SmoothChunks.java
Normal file
12
src/main/java/cc/flogi/dev/smoothchunks/SmoothChunks.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package cc.flogi.dev.smoothchunks;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
/**
|
||||
* @author Caden Kriese (flogic)
|
||||
*
|
||||
* Created on 09/21/2020
|
||||
*/
|
||||
public class SmoothChunks implements ModInitializer {
|
||||
@Override public void onInitialize() {}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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<ChunkBuilder.BuiltChunk, AnimationController> 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cc.flogi.dev.smoothchunks.client;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
/**
|
||||
* @author Caden Kriese (flogic)
|
||||
*
|
||||
* Created on 09/21/2020
|
||||
*/
|
||||
@Environment(EnvType.CLIENT) public class SmoothChunksClient implements ClientModInitializer {
|
||||
@Override public void onInitializeClient() {}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package cc.flogi.dev.smoothchunks.mixin;
|
||||
|
||||
import cc.flogi.dev.smoothchunks.client.ChunkAnimationHandler;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
/**
|
||||
* @author Caden Kriese (flogic)
|
||||
*
|
||||
* Created on 09/25/2020
|
||||
*/
|
||||
@Mixin(WorldRenderer.class)
|
||||
public abstract class WorldRendererMixin {
|
||||
@Inject(
|
||||
method = "renderLayer",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
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);
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/smooth-chunks/icon.png
Normal file
BIN
src/main/resources/assets/smooth-chunks/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 81 KiB |
34
src/main/resources/fabric.mod.json
Normal file
34
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "smooth-chunks",
|
||||
"version": "${version}",
|
||||
"name": "Smooth Chunks",
|
||||
"description": "Smooth chunk load animations.",
|
||||
"authors": [
|
||||
"flogic"
|
||||
],
|
||||
"contact": {
|
||||
"website": "flogi.cc",
|
||||
"repo": "repo.flogi.cc"
|
||||
},
|
||||
"license": "MIT",
|
||||
"accessWidener" : "smooth-chunks.accesswidener",
|
||||
"icon": "assets/smooth-chunks/icon.png",
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"cc.flogi.dev.smoothchunks.client.SmoothChunksClient"
|
||||
],
|
||||
"main": [
|
||||
"cc.flogi.dev.smoothchunks.SmoothChunks"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"smooth-chunks.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.9.3+build.207",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.3"
|
||||
}
|
||||
}
|
||||
16
src/main/resources/smooth-chunks.mixins.json
Normal file
16
src/main/resources/smooth-chunks.mixins.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "cc.flogi.dev.smoothchunks.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"BuiltChunkMixin"
|
||||
],
|
||||
"client": [
|
||||
"BuiltChunkStorageMixin",
|
||||
"WorldRendererMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user