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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
package com.detrav.net;
import com.detrav.DetravScannerMod;
import com.detrav.gui.DetravGuiProPick;
import com.detrav.gui.textures.DetravMapTexture;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Materials;
import gregtech.api.util.GT_LanguageManager;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.util.HashMap;
/**
* Created by wital_000 on 20.03.2016.
*/
public class DetravProPickPacket00 extends DetravPacket {
public int chunkX;
public int chunkZ;
public int size;
HashMap<Byte,Short>[][] map = null;
@Override
public int getPacketID() {
return 0;
}
public int level = -1;
@Override
public byte[] encode() {
ByteArrayDataOutput tOut = ByteStreams.newDataOutput(1);
tOut.writeInt(level);
tOut.writeInt(chunkX);
tOut.writeInt(chunkZ);
tOut.writeInt(size);
int aSize = (size*2+1)*16;
int checkOut = 0;
for(int i =0; i<aSize; i++)
for(int j =0; j<aSize; j++)
{
if(map[i][j]==null)
tOut.writeByte(0);
else
{
tOut.writeByte(map[i][j].keySet().size());
for(byte key : map[i][j].keySet())
{
tOut.writeByte(key);
tOut.writeShort(map[i][j].get(key));
checkOut++;
}
}
}
tOut.writeInt(checkOut);
return tOut.toByteArray();
}
@Override
public Object decode(ByteArrayDataInput aData) {
DetravProPickPacket00 packet = new DetravProPickPacket00();
packet.level = aData.readInt();
packet.chunkX = aData.readInt();
packet.chunkZ = aData.readInt();
packet.size = aData.readInt();
packet.map = new HashMap[(packet.size * 2 + 1) * 16][(packet.size * 2 + 1) * 16];
int aSize = (packet.size * 2 + 1) * 16;
int checkOut = 0;
for (int i = 0; i < aSize; i++)
for (int j = 0; j < aSize; j++) {
byte kSize = aData.readByte();
if(kSize == 0) continue;
packet.map[i][j] = new HashMap<Byte, Short>();
for (int k = 0; k < kSize; k++) {
packet.map[i][j].put(aData.readByte(),aData.readShort());
checkOut++;
}
}
int checkOut2 = aData.readInt();
if(checkOut != checkOut2) return new DetravProPickPacket00();
return packet;
}
@Override
public void process() {
DetravGuiProPick.newMap(new DetravMapTexture(this));
DetravScannerMod.proxy.openProPickGui();
}
public void addBlock(int x, int y, int z, short metaData) {
if(map == null) map = new HashMap[(size*2+1)*16][(size*2+1)*16];
int aX = x - (chunkX-size)*16;
int aZ = z - (chunkZ-size)*16;
if(map[aX][aZ] == null) map[aX][aZ] = new HashMap<Byte, Short>();
map[aX][aZ].put((byte)y,metaData);
//String key = String.format(("x_y"))
}
private HashMap<String,Integer> ores = null;
public BufferedImage getImage(int posX,int posZ) {
int wh = (size*2+1)*16;
//int aWh = 1024;
//while (aWh<wh) aWh*=2;
BufferedImage image = new BufferedImage(wh,wh,BufferedImage.TYPE_INT_ARGB );
WritableRaster raster = image.getRaster();
int playerI = posX - (chunkX-size)*16;
int playerJ = posZ - (chunkZ-size)*16;
if(ores == null) ores = new HashMap<String, Integer>();
int exception = 0;
for(int i =0; i<wh; i++)
for(int j =0; j<wh; j++) {
if (map[i][j] == null)
{
raster.setSample(i,j,0,255);
raster.setSample(i,j,1,255);
raster.setSample(i,j,2,255);
raster.setSample(i,j,3,255);
}
else
{
for(short meta : map[i][j].values()) {
String name;
short[] rgba;
if(meta>=0) {
//Пока только по одному буду
Materials tMaterial = GregTech_API.sGeneratedMaterials[meta % 1000];
if(tMaterial == null) { exception++; continue;}
rgba = tMaterial.getRGBA();
//ores.put(GT_Ore)
name = GT_LanguageManager.getTranslation("gt.blockores." + meta + ".name");
}
else
{
name = String.valueOf(meta);
rgba = new short[4];
rgba[0] =(short)( 255/(-meta + 1));
rgba[1] =(short)( 255/(-meta + 1));
rgba[2] =(short)( 255/(-meta + 1));
rgba[3] =(short)( 255 );
}
raster.setSample(i, j, 0, rgba[0]);
raster.setSample(i, j, 1, rgba[1]);
raster.setSample(i, j, 2, rgba[2]);
raster.setSample(i, j, 3, 255);
if(!ores.containsKey(name))
ores.put(name,(0xFF << 24) + ((rgba[0]&0xFF)<<16)+((rgba[1]&0xFF)<<8)+((rgba[2]&0xFF)));
}
}
if(playerI == i || playerJ == j)
{
raster.setSample(i,j,0,(raster.getSample(i,j,0)+255)/2);
raster.setSample(i,j,1,raster.getSample(i,j,1)/2);
raster.setSample(i,j,2,raster.getSample(i,j,2)/2);
}
if((i-15)%16 == 0 || (j-15)%16 == 0)
{
raster.setSample(i,j,0,raster.getSample(i,j,0)/2);
raster.setSample(i,j,1,raster.getSample(i,j,1)/2);
raster.setSample(i,j,2,raster.getSample(i,j,2)/2);
}
}
DetravScannerMod.proxy.sendPlayerExeption("null matertial exception: " + exception);
/*try {
File outputfile = new File("saved.png");
ImageIO.write(image, "png", outputfile);
}
catch (Exception e) {}*/
return image;
//image.set
//return null;
}
public HashMap<String,Integer> getOres()
{
if(ores == null) return new HashMap<String, Integer>();
return ores;
}
public int getSize() {
return (size*2+1)*16;
}
}
|