aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/neodymium/mixin/MixinTessellator.java
blob: 935b86041b94f82d98abfdde82c836a0d061cfdb (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package makamys.neodymium.mixin;

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.CallbackInfoReturnable;

import makamys.neodymium.config.Config;
import makamys.neodymium.ducks.ITessellator;
import makamys.neodymium.renderer.ChunkMesh;
import net.minecraft.client.renderer.Tessellator;

@Mixin(Tessellator.class)
abstract class MixinTessellator implements ITessellator {
    
    private boolean nd$captureMeshes;
    
    @Shadow protected abstract void reset();

    @Shadow private boolean isDrawing;
    
    @Inject(method = "draw",
            at = @At(value = "HEAD"),
            cancellable = true,
            require = 1)
    private void preDraw(CallbackInfoReturnable<Integer> cir) {
        if(nd$captureMeshes) {
            ChunkMesh.preTessellatorDraw((Tessellator)(Object)this);
            
            if(Config.enabled && !Config.enableVanillaChunkMeshes) {
                isDrawing = false;
                reset();
                cir.setReturnValue(0);
            }
        }
    }
    
    @Override
    public void enableMeshCapturing(boolean enable) {
        nd$captureMeshes = enable;
    }
    
}