aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/neodymium/mixin/MixinChunkCache.java
blob: 331e3cf4bc9e7bb55f3e4ef5b8a58053460b7160 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package makamys.neodymium.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import makamys.neodymium.Neodymium;
import makamys.neodymium.renderer.FarChunkCache;
import makamys.neodymium.renderer.NeoRenderer;
import net.minecraft.world.ChunkCache;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;

@Mixin(ChunkCache.class)
abstract class MixinChunkCache {
    
    @Redirect(method = "<init>*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getChunkFromChunkCoords(II)Lnet/minecraft/world/chunk/Chunk;"))
    private Chunk redirectGetChunkFromChunkCoords(World world, int p1, int p2) {
        Chunk chunk = world.getChunkFromChunkCoords(p1, p2);
        if(Neodymium.isActive() && FarChunkCache.class.isInstance(this.getClass()) && chunk.isEmpty()) {
            Chunk myChunk = Neodymium.renderer.getChunkFromChunkCoords(p1, p2);
            if(myChunk != null) {
                chunk = myChunk;
            }
        }
        return chunk;
    }
    
}