Refactor how config is accessed
This commit is contained in:
parent
81cfec154d
commit
f89e53c13d
17
build.gradle
17
build.gradle
@ -15,14 +15,15 @@ dependencies {
|
||||
|
||||
// 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))
|
||||
}
|
||||
// Set<String> apiModules = [
|
||||
// "fabric-api-base"
|
||||
//// "fabric-tool-attribute-api-v1"
|
||||
// ]
|
||||
//
|
||||
// // 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}"
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
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;
|
||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||
|
||||
/**
|
||||
* @author Caden Kriese (flogic)
|
||||
@ -19,7 +19,6 @@ import net.fabricmc.api.Environment;
|
||||
public static SmoothChunksClient get() {return instance;}
|
||||
|
||||
@Getter private SmoothChunksConfig config;
|
||||
@Getter private ChunkAnimationHandler chunkAnimationHandler;
|
||||
|
||||
@Override public void onInitializeClient() {
|
||||
instance = this;
|
||||
@ -27,6 +26,6 @@ import net.fabricmc.api.Environment;
|
||||
AutoConfig.register(SmoothChunksConfig.class, Toml4jConfigSerializer::new);
|
||||
config = AutoConfig.getConfigHolder(SmoothChunksConfig.class).getConfig();
|
||||
|
||||
chunkAnimationHandler = new ChunkAnimationHandler(config);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ public enum LoadAnimation {
|
||||
DOWNWARD,
|
||||
UPWARD,
|
||||
INWARD,
|
||||
FADE
|
||||
SCALE
|
||||
}
|
||||
|
@ -14,13 +14,13 @@ 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 {
|
||||
@Comment("Duration of the animation in seconds.")
|
||||
@ConfigEntry.BoundedDiscrete(min = 0, max=10)
|
||||
int duration = 1;
|
||||
@ConfigEntry.BoundedDiscrete(min = 0, max=4)
|
||||
double duration = 1;
|
||||
|
||||
@Comment("Type of animation for loading chunks.")
|
||||
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
|
||||
LoadAnimation loadAnimation = LoadAnimation.DOWNWARD;
|
||||
LoadAnimation loadAnimation = LoadAnimation.UPWARD;
|
||||
|
||||
@Comment("Disable animating chunks close to you")
|
||||
boolean disableNearby = false;
|
||||
boolean disableNearby = true;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package cc.flogi.dev.smoothchunks.client.handler;
|
||||
|
||||
import cc.flogi.dev.smoothchunks.client.config.LoadAnimation;
|
||||
import cc.flogi.dev.smoothchunks.client.SmoothChunksClient;
|
||||
import cc.flogi.dev.smoothchunks.client.config.SmoothChunksConfig;
|
||||
import cc.flogi.dev.smoothchunks.util.UtilEasing;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -18,49 +18,49 @@ import java.util.WeakHashMap;
|
||||
* Created on 09/27/2020
|
||||
*/
|
||||
public final class ChunkAnimationHandler {
|
||||
private final long DURATION;
|
||||
private final LoadAnimation LOAD_ANIMATION;
|
||||
private final boolean DISABLE_NEARBY;
|
||||
private static final ChunkAnimationHandler instance = new ChunkAnimationHandler();
|
||||
public static ChunkAnimationHandler get() {return instance;}
|
||||
|
||||
private final WeakHashMap<ChunkBuilder.BuiltChunk, AnimationController> animations = new WeakHashMap<>();
|
||||
|
||||
public ChunkAnimationHandler(SmoothChunksConfig config) {
|
||||
DURATION = config.getDuration() * 1000;
|
||||
LOAD_ANIMATION = config.getLoadAnimation();
|
||||
DISABLE_NEARBY = config.isDisableNearby();
|
||||
}
|
||||
|
||||
public void addChunk(ChunkBuilder.BuiltChunk chunk) {
|
||||
animations.put(chunk, new AnimationController(chunk.getOrigin(), System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
public void updateChunk(ChunkBuilder.BuiltChunk chunk, MatrixStack stack) {
|
||||
SmoothChunksConfig config = SmoothChunksClient.get().getConfig();
|
||||
|
||||
// System.out.println(config.getDuration() + " - " + config.getLoadAnimation().name() + " - " + config.isDisableNearby());
|
||||
|
||||
AnimationController controller = animations.get(chunk);
|
||||
if (controller == null || MinecraftClient.getInstance().getCameraEntity() == null) return;
|
||||
|
||||
if (DISABLE_NEARBY) {
|
||||
if (config.isDisableNearby()) {
|
||||
BlockPos cameraPos = MinecraftClient.getInstance().getCameraEntity().getBlockPos();
|
||||
BlockPos chunkPos = chunk.getOrigin();
|
||||
|
||||
if (chunkPos.isWithinDistance(cameraPos, 32)) return;
|
||||
}
|
||||
|
||||
double completion = (double) (System.currentTimeMillis() - controller.getStartTime()) / DURATION;
|
||||
completion = Math.min(completion, 1.0);
|
||||
double completion = (double) (System.currentTimeMillis() - controller.getStartTime()) / config.getDuration() / 1000d;
|
||||
completion = UtilEasing.easeOutSine(Math.min(completion, 1.0));
|
||||
|
||||
int chunkY = controller.getFinalPos().getY();
|
||||
|
||||
switch (LOAD_ANIMATION) {
|
||||
switch (config.getLoadAnimation()) {
|
||||
default:
|
||||
case DOWNWARD:
|
||||
stack.translate(0, 256 - chunkY - (UtilEasing.easeInOutSine(completion) * chunkY), 0);
|
||||
stack.translate(0, 256 - chunkY - (completion * chunkY), 0);
|
||||
break;
|
||||
case UPWARD:
|
||||
stack.translate(0, -chunkY + (UtilEasing.easeInOutSine(completion) * chunkY), 0);
|
||||
stack.translate(0, -chunkY + (completion * chunkY), 0);
|
||||
break;
|
||||
case INWARD:
|
||||
stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0);
|
||||
break;
|
||||
case SCALE:
|
||||
stack.scale((float) completion, (float) completion, (float) completion);
|
||||
break;
|
||||
// case INWARD:
|
||||
// stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0);
|
||||
// break;
|
||||
}
|
||||
|
||||
if (completion >= 1.0) animations.remove(chunk);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.flogi.dev.smoothchunks.mixin;
|
||||
|
||||
import cc.flogi.dev.smoothchunks.client.SmoothChunksClient;
|
||||
import cc.flogi.dev.smoothchunks.client.handler.ChunkAnimationHandler;
|
||||
import net.minecraft.client.render.chunk.BlockBufferBuilderStorage;
|
||||
import net.minecraft.client.render.chunk.ChunkBuilder;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -29,6 +29,6 @@ public abstract class ChunkBuilderMixin {
|
||||
)
|
||||
)
|
||||
public void onSetOrigin(BlockBufferBuilderStorage buffers, CallbackInfoReturnable<CompletableFuture> cir) {
|
||||
SmoothChunksClient.get().getChunkAnimationHandler().addChunk(field_20839);
|
||||
ChunkAnimationHandler.get().addChunk(field_20839);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.flogi.dev.smoothchunks.mixin;
|
||||
|
||||
import cc.flogi.dev.smoothchunks.client.SmoothChunksClient;
|
||||
import cc.flogi.dev.smoothchunks.client.handler.ChunkAnimationHandler;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
|
||||
import net.minecraft.client.gl.VertexBuffer;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
@ -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(builtChunk, matrixStack);
|
||||
ChunkAnimationHandler.get().updateChunk(builtChunk, matrixStack);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user