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.
|
// Fabric API.
|
||||||
// Make a collection of all api modules we wish to use
|
// Make a collection of all api modules we wish to use
|
||||||
Set<String> apiModules = [
|
// Set<String> apiModules = [
|
||||||
"fabric-api-base"
|
// "fabric-api-base"
|
||||||
]
|
//// "fabric-tool-attribute-api-v1"
|
||||||
|
// ]
|
||||||
// Add each module as a dependency
|
//
|
||||||
apiModules.forEach {
|
// // Add each module as a dependency
|
||||||
modImplementation(fabricApi.module(it, project.fabric_version))
|
// 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}"
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package cc.flogi.dev.smoothchunks.client;
|
package cc.flogi.dev.smoothchunks.client;
|
||||||
|
|
||||||
import cc.flogi.dev.smoothchunks.client.config.SmoothChunksConfig;
|
import cc.flogi.dev.smoothchunks.client.config.SmoothChunksConfig;
|
||||||
import cc.flogi.dev.smoothchunks.client.handler.ChunkAnimationHandler;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||||
import me.sargunvohra.mcmods.autoconfig1u.serializer.Toml4jConfigSerializer;
|
import me.sargunvohra.mcmods.autoconfig1u.serializer.Toml4jConfigSerializer;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Caden Kriese (flogic)
|
* @author Caden Kriese (flogic)
|
||||||
@ -19,7 +19,6 @@ import net.fabricmc.api.Environment;
|
|||||||
public static SmoothChunksClient get() {return instance;}
|
public static SmoothChunksClient get() {return instance;}
|
||||||
|
|
||||||
@Getter private SmoothChunksConfig config;
|
@Getter private SmoothChunksConfig config;
|
||||||
@Getter private ChunkAnimationHandler chunkAnimationHandler;
|
|
||||||
|
|
||||||
@Override public void onInitializeClient() {
|
@Override public void onInitializeClient() {
|
||||||
instance = this;
|
instance = this;
|
||||||
@ -27,6 +26,6 @@ import net.fabricmc.api.Environment;
|
|||||||
AutoConfig.register(SmoothChunksConfig.class, Toml4jConfigSerializer::new);
|
AutoConfig.register(SmoothChunksConfig.class, Toml4jConfigSerializer::new);
|
||||||
config = AutoConfig.getConfigHolder(SmoothChunksConfig.class).getConfig();
|
config = AutoConfig.getConfigHolder(SmoothChunksConfig.class).getConfig();
|
||||||
|
|
||||||
chunkAnimationHandler = new ChunkAnimationHandler(config);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,5 @@ public enum LoadAnimation {
|
|||||||
DOWNWARD,
|
DOWNWARD,
|
||||||
UPWARD,
|
UPWARD,
|
||||||
INWARD,
|
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
|
@Config(name = "smooth-chunks") @Config.Gui.Background("minecraft:textures/block/stone.png") @Getter
|
||||||
public class SmoothChunksConfig implements ConfigData {
|
public class SmoothChunksConfig implements ConfigData {
|
||||||
@Comment("Duration of the animation in seconds.")
|
@Comment("Duration of the animation in seconds.")
|
||||||
@ConfigEntry.BoundedDiscrete(min = 0, max=10)
|
@ConfigEntry.BoundedDiscrete(min = 0, max=4)
|
||||||
int duration = 1;
|
double duration = 1;
|
||||||
|
|
||||||
@Comment("Type of animation for loading chunks.")
|
@Comment("Type of animation for loading chunks.")
|
||||||
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
|
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
|
||||||
LoadAnimation loadAnimation = LoadAnimation.DOWNWARD;
|
LoadAnimation loadAnimation = LoadAnimation.UPWARD;
|
||||||
|
|
||||||
@Comment("Disable animating chunks close to you")
|
@Comment("Disable animating chunks close to you")
|
||||||
boolean disableNearby = false;
|
boolean disableNearby = true;
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package cc.flogi.dev.smoothchunks.client.handler;
|
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.client.config.SmoothChunksConfig;
|
||||||
import cc.flogi.dev.smoothchunks.util.UtilEasing;
|
import cc.flogi.dev.smoothchunks.util.UtilEasing;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -18,49 +18,49 @@ import java.util.WeakHashMap;
|
|||||||
* Created on 09/27/2020
|
* Created on 09/27/2020
|
||||||
*/
|
*/
|
||||||
public final class ChunkAnimationHandler {
|
public final class ChunkAnimationHandler {
|
||||||
private final long DURATION;
|
private static final ChunkAnimationHandler instance = new ChunkAnimationHandler();
|
||||||
private final LoadAnimation LOAD_ANIMATION;
|
public static ChunkAnimationHandler get() {return instance;}
|
||||||
private final boolean DISABLE_NEARBY;
|
|
||||||
|
|
||||||
private final WeakHashMap<ChunkBuilder.BuiltChunk, AnimationController> animations = new WeakHashMap<>();
|
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) {
|
public void addChunk(ChunkBuilder.BuiltChunk chunk) {
|
||||||
animations.put(chunk, new AnimationController(chunk.getOrigin(), System.currentTimeMillis()));
|
animations.put(chunk, new AnimationController(chunk.getOrigin(), System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateChunk(ChunkBuilder.BuiltChunk chunk, MatrixStack stack) {
|
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);
|
AnimationController controller = animations.get(chunk);
|
||||||
if (controller == null || MinecraftClient.getInstance().getCameraEntity() == null) return;
|
if (controller == null || MinecraftClient.getInstance().getCameraEntity() == null) return;
|
||||||
|
|
||||||
if (DISABLE_NEARBY) {
|
if (config.isDisableNearby()) {
|
||||||
BlockPos cameraPos = MinecraftClient.getInstance().getCameraEntity().getBlockPos();
|
BlockPos cameraPos = MinecraftClient.getInstance().getCameraEntity().getBlockPos();
|
||||||
BlockPos chunkPos = chunk.getOrigin();
|
BlockPos chunkPos = chunk.getOrigin();
|
||||||
|
|
||||||
if (chunkPos.isWithinDistance(cameraPos, 32)) return;
|
if (chunkPos.isWithinDistance(cameraPos, 32)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double completion = (double) (System.currentTimeMillis() - controller.getStartTime()) / DURATION;
|
double completion = (double) (System.currentTimeMillis() - controller.getStartTime()) / config.getDuration() / 1000d;
|
||||||
completion = Math.min(completion, 1.0);
|
completion = UtilEasing.easeOutSine(Math.min(completion, 1.0));
|
||||||
|
|
||||||
int chunkY = controller.getFinalPos().getY();
|
int chunkY = controller.getFinalPos().getY();
|
||||||
|
|
||||||
switch (LOAD_ANIMATION) {
|
switch (config.getLoadAnimation()) {
|
||||||
default:
|
default:
|
||||||
case DOWNWARD:
|
case DOWNWARD:
|
||||||
stack.translate(0, 256 - chunkY - (UtilEasing.easeInOutSine(completion) * chunkY), 0);
|
stack.translate(0, 256 - chunkY - (completion * chunkY), 0);
|
||||||
break;
|
break;
|
||||||
case UPWARD:
|
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;
|
break;
|
||||||
// case INWARD:
|
|
||||||
// stack.translate(0, (1 - completion) * controller.getFinalPos().getY(), 0);
|
|
||||||
// break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completion >= 1.0) animations.remove(chunk);
|
if (completion >= 1.0) animations.remove(chunk);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cc.flogi.dev.smoothchunks.mixin;
|
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.BlockBufferBuilderStorage;
|
||||||
import net.minecraft.client.render.chunk.ChunkBuilder;
|
import net.minecraft.client.render.chunk.ChunkBuilder;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@ -29,6 +29,6 @@ public abstract class ChunkBuilderMixin {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
public void onSetOrigin(BlockBufferBuilderStorage buffers, CallbackInfoReturnable<CompletableFuture> cir) {
|
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;
|
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 it.unimi.dsi.fastutil.objects.ObjectListIterator;
|
||||||
import net.minecraft.client.gl.VertexBuffer;
|
import net.minecraft.client.gl.VertexBuffer;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
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,
|
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(builtChunk, matrixStack);
|
ChunkAnimationHandler.get().updateChunk(builtChunk, matrixStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user