| 1 | package net.minecraft.network.play.server;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import java.util.Collection;
|
| 5 | import net.minecraft.network.Packet;
|
| 6 | import net.minecraft.network.PacketBuffer;
|
| 7 | import net.minecraft.network.play.INetHandlerPlayClient;
|
| 8 | import net.minecraft.util.Vec4b;
|
| 9 | import net.minecraft.world.storage.MapData;
|
| 10 |
|
| 11 | public class S34PacketMaps implements Packet<INetHandlerPlayClient>
|
| 12 | {
|
| 13 | private int mapId;
|
| 14 | private byte mapScale;
|
| 15 | private Vec4b[] mapVisiblePlayersVec4b;
|
| 16 | private int mapMinX;
|
| 17 | private int mapMinY;
|
| 18 | private int mapMaxX;
|
| 19 | private int mapMaxY;
|
| 20 | private byte[] mapDataBytes;
|
| 21 |
|
| 22 | public S34PacketMaps()
|
| 23 | {
|
| 24 | }
|
| 25 |
|
| 26 | public S34PacketMaps(int mapIdIn, byte scale, Collection<Vec4b> visiblePlayers, byte[] colors, int minX, int minY, int maxX, int maxY)
|
| 27 | {
|
| 28 | this.mapId = mapIdIn;
|
| 29 | this.mapScale = scale;
|
| 30 | this.mapVisiblePlayersVec4b = (Vec4b[])visiblePlayers.toArray(new Vec4b[visiblePlayers.size()]);
|
| 31 | this.mapMinX = minX;
|
| 32 | this.mapMinY = minY;
|
| 33 | this.mapMaxX = maxX;
|
| 34 | this.mapMaxY = maxY;
|
| 35 | this.mapDataBytes = new byte[maxX * maxY];
|
| 36 |
|
| 37 | for (int i = 0; i < maxX; ++i)
|
| 38 | {
|
| 39 | for (int j = 0; j < maxY; ++j)
|
| 40 | {
|
| 41 | this.mapDataBytes[i + j * maxX] = colors[minX + i + (minY + j) * 128];
|
| 42 | }
|
| 43 | }
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * Reads the raw packet data from the data stream.
|
| 48 | */
|
| 49 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 50 | {
|
| 51 | this.mapId = buf.readVarIntFromBuffer();
|
| 52 | this.mapScale = buf.readByte();
|
| 53 | this.mapVisiblePlayersVec4b = new Vec4b[buf.readVarIntFromBuffer()];
|
| 54 |
|
| 55 | for (int i = 0; i < this.mapVisiblePlayersVec4b.length; ++i)
|
| 56 | {
|
| 57 | short short1 = (short)buf.readByte();
|
| 58 | this.mapVisiblePlayersVec4b[i] = new Vec4b((byte)(short1 >> 4 & 15), buf.readByte(), buf.readByte(), (byte)(short1 & 15));
|
| 59 | }
|
| 60 |
|
| 61 | this.mapMaxX = buf.readUnsignedByte();
|
| 62 |
|
| 63 | if (this.mapMaxX > 0)
|
| 64 | {
|
| 65 | this.mapMaxY = buf.readUnsignedByte();
|
| 66 | this.mapMinX = buf.readUnsignedByte();
|
| 67 | this.mapMinY = buf.readUnsignedByte();
|
| 68 | this.mapDataBytes = buf.readByteArray();
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | /**
|
| 73 | * Writes the raw packet data to the data stream.
|
| 74 | */
|
| 75 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 76 | {
|
| 77 | buf.writeVarIntToBuffer(this.mapId);
|
| 78 | buf.writeByte(this.mapScale);
|
| 79 | buf.writeVarIntToBuffer(this.mapVisiblePlayersVec4b.length);
|
| 80 |
|
| 81 | for (Vec4b vec4b : this.mapVisiblePlayersVec4b)
|
| 82 | {
|
| 83 | buf.writeByte((vec4b.func_176110_a() & 15) << 4 | vec4b.func_176111_d() & 15);
|
| 84 | buf.writeByte(vec4b.func_176112_b());
|
| 85 | buf.writeByte(vec4b.func_176113_c());
|
| 86 | }
|
| 87 |
|
| 88 | buf.writeByte(this.mapMaxX);
|
| 89 |
|
| 90 | if (this.mapMaxX > 0)
|
| 91 | {
|
| 92 | buf.writeByte(this.mapMaxY);
|
| 93 | buf.writeByte(this.mapMinX);
|
| 94 | buf.writeByte(this.mapMinY);
|
| 95 | buf.writeByteArray(this.mapDataBytes);
|
| 96 | }
|
| 97 | }
|
| 98 |
|
| 99 | /**
|
| 100 | * Passes this Packet on to the NetHandler for processing.
|
| 101 | */
|
| 102 | public void processPacket(INetHandlerPlayClient handler)
|
| 103 | {
|
| 104 | handler.handleMaps(this);
|
| 105 | }
|
| 106 |
|
| 107 | public int getMapId()
|
| 108 | {
|
| 109 | return this.mapId;
|
| 110 | }
|
| 111 |
|
| 112 | /**
|
| 113 | * Sets new MapData from the packet to given MapData param
|
| 114 | */
|
| 115 | public void setMapdataTo(MapData mapdataIn)
|
| 116 | {
|
| 117 | mapdataIn.scale = this.mapScale;
|
| 118 | mapdataIn.mapDecorations.clear();
|
| 119 |
|
| 120 | for (int i = 0; i < this.mapVisiblePlayersVec4b.length; ++i)
|
| 121 | {
|
| 122 | Vec4b vec4b = this.mapVisiblePlayersVec4b[i];
|
| 123 | mapdataIn.mapDecorations.put("icon-" + i, vec4b);
|
| 124 | }
|
| 125 |
|
| 126 | for (int j = 0; j < this.mapMaxX; ++j)
|
| 127 | {
|
| 128 | for (int k = 0; k < this.mapMaxY; ++k)
|
| 129 | {
|
| 130 | mapdataIn.colors[this.mapMinX + j + (this.mapMinY + k) * 128] = this.mapDataBytes[j + k * this.mapMaxX];
|
| 131 | }
|
| 132 | }
|
| 133 | }
|
| 134 | }
|
| 135 |
|