package com.straice.smoothdoors.mixin.client;

import com.straice.smoothdoors.client.anim.SddAnimator;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.render.chunk.ChunkRendererRegion;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ChunkRendererRegion.class)
public class ChunkRendererRegionMixin {

    @Inject(method = "getBlockState", at = @At("HEAD"), cancellable = true)
    private void sdd$getBlockState(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
        if (SddAnimator.isAnimatingAt(pos)) {
            cir.setReturnValue(Blocks.AIR.getDefaultState());
            cir.cancel();
        }
    }
}
