package asm.mixins;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.world.chunk.ChunkNibbleArray;
import net.minecraft.world.chunk.light.LightStorage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Environment(EnvType.CLIENT)
@Mixin({LightStorage.class})
public class MixinLightStorage {
   @Redirect(
      method = {"get(J)I"},
      at = @At(
         value = "INVOKE",
         target = "Lnet/minecraft/world/chunk/ChunkNibbleArray;get(III)I"
      ),
      require = 0
   )
   private static int redirectChunkNibbleGetDesc(ChunkNibbleArray chunkNibbleArray, int x, int y, int z) {
      return chunkNibbleArray == null ? 0 : chunkNibbleArray.get(x, y, z);
   }

   @Redirect(
      method = {"get"},
      at = @At(
         value = "INVOKE",
         target = "Lnet/minecraft/world/chunk/ChunkNibbleArray;get(III)I"
      ),
      require = 0
   )
   private static int redirectChunkNibbleGet(ChunkNibbleArray chunkNibbleArray, int x, int y, int z) {
      return chunkNibbleArray == null ? 0 : chunkNibbleArray.get(x, y, z);
   }
}
