aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/detrav/gui/textures/DetravMapTexture.java
blob: 58d69260cefdcb8efc788b5ed1fec51d9eea04da (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.detrav.gui.textures;

import java.awt.image.BufferedImage;
import java.util.HashMap;

import org.lwjgl.opengl.GL11;

import com.detrav.net.DetravProPickPacket00;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManager;

/**
 * Created by wital_000 on 21.03.2016.
 */
public class DetravMapTexture extends AbstractTexture {

    private DetravProPickPacket00 packet;

    public DetravMapTexture(DetravProPickPacket00 aPacket)
    {
        packet = aPacket;
    }

    public int width = -1;
    public int height = -1;
    public HashMap<String,Integer> ores = null;

    @Override
    public void loadTexture(IResourceManager p_110551_1_){
        this.deleteGlTexture();
        if(packet!=null)
        {
            int tId = getGlTextureId();
            if(tId <0) return;
            BufferedImage bufferedimage = packet.getImage((int)Minecraft.getMinecraft().thePlayer.posX,(int)Minecraft.getMinecraft().thePlayer.posZ);
            TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), bufferedimage, false, false);
            width = packet.getSize();
            height = packet.getSize();
            ores = packet.getOres();
        }
        //GL11.glDrawPixels();
    }

    public int glBindTexture() {
        if (this.glTextureId < 0) return this.glTextureId;
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.getGlTextureId());
        return this.glTextureId;
    }

    public void draw(int x, int y)
    {
        float f = 1F / (float)width;
        float f1 = 1F / (float)height;
        int u = 0;
        int v = 0;
        Tessellator tessellator = Tessellator.instance;
        tessellator.startDrawingQuads();
        tessellator.addVertexWithUV((double)(x), (double)(y + height), 0, (double)((float)(u) * f), (double)((float)(v + height) * f1));
        tessellator.addVertexWithUV((double)(x + width), (double)(y + height), 0, (double)((float)(u + width) * f), (double)((float)(v + height) * f1));
        tessellator.addVertexWithUV((double)(x + width), (double)(y), 0, (double)((float)(u + width) * f), (double)((float)(v) * f1));
        tessellator.addVertexWithUV((double)(x), (double)(y), 0, (double)((float)(u) * f), (double)((float)(v) * f1));
        tessellator.draw();
    }

}