Fix animations playing multiple times (finally)
This commit is contained in:
parent
6a39205ac6
commit
762df55c1d
@ -13,7 +13,7 @@ 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 {
|
||||
//TODO use localization for comment strings.
|
||||
//TODO use localization for comment strings. (Somehow, not super straightforward bc annotations need const value)
|
||||
@Comment("Duration of the animation in seconds.")
|
||||
double duration = 1;
|
||||
|
||||
|
@ -6,6 +6,7 @@ import cc.flogi.dev.smoothchunks.client.config.SmoothChunksConfig;
|
||||
import cc.flogi.dev.smoothchunks.util.UtilEasing;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.chunk.ChunkBuilder;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
@ -13,6 +14,8 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
@ -23,10 +26,15 @@ import java.util.WeakHashMap;
|
||||
public final class ChunkAnimationHandler {
|
||||
private static final ChunkAnimationHandler instance = new ChunkAnimationHandler();
|
||||
private final WeakHashMap<ChunkBuilder.BuiltChunk, AnimationController> animations = new WeakHashMap<>();
|
||||
@Getter private final List<Vec3i> loadedChunks = new ArrayList<>();
|
||||
|
||||
public static ChunkAnimationHandler get() {return instance;}
|
||||
|
||||
public void addChunk(ChunkBuilder.BuiltChunk chunk) {
|
||||
Vec3i origin = chunk.getOrigin();
|
||||
if (loadedChunks.contains(origin)) return;
|
||||
loadedChunks.add(origin);
|
||||
|
||||
Direction direction = null;
|
||||
|
||||
if (SmoothChunksClient.get().getConfig().getLoadAnimation() == LoadAnimation.INWARD
|
||||
|
@ -0,0 +1,28 @@
|
||||
package cc.flogi.dev.smoothchunks.mixin;
|
||||
|
||||
import cc.flogi.dev.smoothchunks.client.handler.ChunkAnimationHandler;
|
||||
import net.minecraft.client.render.chunk.ChunkBuilder;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Caden Kriese (flogic)
|
||||
*
|
||||
* Created on 11/01/2020
|
||||
*/
|
||||
@Mixin(ChunkBuilder.BuiltChunk.class)
|
||||
public abstract class BuiltChunkMixin {
|
||||
@Shadow public abstract BlockPos getOrigin();
|
||||
|
||||
@Inject(
|
||||
method = "clear",
|
||||
at = @At(value = "TAIL")
|
||||
)
|
||||
public void onDelete(CallbackInfo ci) {
|
||||
ChunkAnimationHandler.get().getLoadedChunks().remove(getOrigin());
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cc.flogi.dev.smoothchunks.mixin;
|
||||
|
||||
import cc.flogi.dev.smoothchunks.client.handler.ChunkAnimationHandler;
|
||||
import net.minecraft.client.render.WorldRenderer;
|
||||
import net.minecraft.client.render.chunk.BlockBufferBuilderStorage;
|
||||
import net.minecraft.client.render.chunk.ChunkBuilder;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -17,7 +18,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
* Created on 10/07/2020
|
||||
*/
|
||||
@SuppressWarnings("rawtypes") @Mixin(ChunkBuilder.BuiltChunk.RebuildTask.class)
|
||||
public abstract class ChunkBuilderMixin {
|
||||
public abstract class RebuildTaskMixin {
|
||||
//Parent class
|
||||
@SuppressWarnings("ShadowTarget") @Shadow private ChunkBuilder.BuiltChunk field_20839;
|
||||
|
@ -5,7 +5,8 @@
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [],
|
||||
"client": [
|
||||
"ChunkBuilderMixin",
|
||||
"BuiltChunkMixin",
|
||||
"RebuildTaskMixin",
|
||||
"WorldRendererMixin"
|
||||
],
|
||||
"injectors": {
|
||||
|
Loading…
Reference in New Issue
Block a user