-
Notifications
You must be signed in to change notification settings - Fork 497
/
DynamicTexturePaletted.java
executable file
·107 lines (91 loc) · 2.84 KB
/
DynamicTexturePaletted.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.lib.render;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.DynamicTexture;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class DynamicTexturePaletted {
public int width, height;
public int[] colorMap;
@SideOnly(Side.CLIENT)
private DynamicTexture dynamicTexture;
public DynamicTexturePaletted(int iWidth, int iHeight) {
width = iWidth;
height = iHeight;
colorMap = new int[iWidth * iHeight];
}
@SideOnly(Side.CLIENT)
public void createDynamicTexture() {
dynamicTexture = new DynamicTexture(width, height);
colorMap = dynamicTexture.getTextureData();
}
public void setColor(int index, double r, double g, double b, double a) {
int i = (int) (a * 255.0F);
int j = (int) (r * 255.0F);
int k = (int) (g * 255.0F);
int l = (int) (b * 255.0F);
colorMap[index] = i << 24 | j << 16 | k << 8 | l;
}
public void setColor(int x, int y, double r, double g, double b, double a) {
int i = (int) (a * 255.0F);
int j = (int) (r * 255.0F);
int k = (int) (g * 255.0F);
int l = (int) (b * 255.0F);
colorMap[x + y * width] = i << 24 | j << 16 | k << 8 | l;
}
public void setColor(int x, int y, int color) {
colorMap[x + y * height] = 255 << 24 | color;
}
public void setColor(int x, int y, int color, float alpha) {
int a = (int) (alpha * 255.0F);
colorMap[x + y * height] = a << 24 | color;
}
@SideOnly(Side.CLIENT)
public void drawMap(int screenX, int screenY, float zLevel) {
drawMap(screenX, screenY, zLevel, 0, 0, width, height);
}
@SideOnly(Side.CLIENT)
public void updateDynamicTexture() {
dynamicTexture.updateDynamicTexture();
}
@SideOnly(Side.CLIENT)
public void drawMap(int screenX, int screenY, float zLevel, int clipX, int clipY, int clipWidth, int clipHeight) {
dynamicTexture.updateDynamicTexture();
float f = 1F / width;
float f1 = 1F / height;
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(
screenX + 0,
screenY + clipHeight,
zLevel,
(clipX + 0) * f,
(clipY + clipHeight) * f1);
tessellator.addVertexWithUV(
screenX + clipWidth,
screenY + clipHeight,
zLevel,
(clipX + clipWidth) * f,
(clipY + clipHeight) * f1);
tessellator.addVertexWithUV(
screenX + clipWidth,
screenY + 0,
zLevel,
(clipX + clipWidth) * f,
(clipY + 0) * f1);
tessellator.addVertexWithUV(
screenX + 0,
screenY + 0,
zLevel,
(clipX + 0) * f,
(clipY + 0) * f1);
tessellator.draw();
}
}