| 1 | package net.minecraft.network.play.server;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 6 | import net.minecraft.network.Packet;
|
| 7 | import net.minecraft.network.PacketBuffer;
|
| 8 | import net.minecraft.network.play.INetHandlerPlayClient;
|
| 9 | import net.minecraft.util.BlockPos;
|
| 10 | import net.minecraft.world.ChunkCoordIntPair;
|
| 11 | import net.minecraft.world.chunk.Chunk;
|
| 12 |
|
| 13 | public class S22PacketMultiBlockChange implements Packet<INetHandlerPlayClient>
|
| 14 | {
|
| 15 | private ChunkCoordIntPair chunkPosCoord;
|
| 16 | private S22PacketMultiBlockChange.BlockUpdateData[] changedBlocks;
|
| 17 |
|
| 18 | public S22PacketMultiBlockChange()
|
| 19 | {
|
| 20 | }
|
| 21 |
|
| 22 | public S22PacketMultiBlockChange(int p_i45181_1_, short[] crammedPositionsIn, Chunk chunkIn)
|
| 23 | {
|
| 24 | this.chunkPosCoord = new ChunkCoordIntPair(chunkIn.xPosition, chunkIn.zPosition);
|
| 25 | this.changedBlocks = new S22PacketMultiBlockChange.BlockUpdateData[p_i45181_1_];
|
| 26 |
|
| 27 | for (int i = 0; i < this.changedBlocks.length; ++i)
|
| 28 | {
|
| 29 | this.changedBlocks[i] = new S22PacketMultiBlockChange.BlockUpdateData(crammedPositionsIn[i], chunkIn);
|
| 30 | }
|
| 31 | }
|
| 32 |
|
| 33 | /**
|
| 34 | * Reads the raw packet data from the data stream.
|
| 35 | */
|
| 36 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 37 | {
|
| 38 | this.chunkPosCoord = new ChunkCoordIntPair(buf.readInt(), buf.readInt());
|
| 39 | this.changedBlocks = new S22PacketMultiBlockChange.BlockUpdateData[buf.readVarIntFromBuffer()];
|
| 40 |
|
| 41 | for (int i = 0; i < this.changedBlocks.length; ++i)
|
| 42 | {
|
| 43 | this.changedBlocks[i] = new S22PacketMultiBlockChange.BlockUpdateData(buf.readShort(), (IBlockState)Block.BLOCK_STATE_IDS.getByValue(buf.readVarIntFromBuffer()));
|
| 44 | }
|
| 45 | }
|
| 46 |
|
| 47 | /**
|
| 48 | * Writes the raw packet data to the data stream.
|
| 49 | */
|
| 50 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 51 | {
|
| 52 | buf.writeInt(this.chunkPosCoord.chunkXPos);
|
| 53 | buf.writeInt(this.chunkPosCoord.chunkZPos);
|
| 54 | buf.writeVarIntToBuffer(this.changedBlocks.length);
|
| 55 |
|
| 56 | for (S22PacketMultiBlockChange.BlockUpdateData s22packetmultiblockchange$blockupdatedata : this.changedBlocks)
|
| 57 | {
|
| 58 | buf.writeShort(s22packetmultiblockchange$blockupdatedata.func_180089_b());
|
| 59 | buf.writeVarIntToBuffer(Block.BLOCK_STATE_IDS.get(s22packetmultiblockchange$blockupdatedata.getBlockState()));
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | /**
|
| 64 | * Passes this Packet on to the NetHandler for processing.
|
| 65 | */
|
| 66 | public void processPacket(INetHandlerPlayClient handler)
|
| 67 | {
|
| 68 | handler.handleMultiBlockChange(this);
|
| 69 | }
|
| 70 |
|
| 71 | public S22PacketMultiBlockChange.BlockUpdateData[] getChangedBlocks()
|
| 72 | {
|
| 73 | return this.changedBlocks;
|
| 74 | }
|
| 75 |
|
| 76 | public class BlockUpdateData
|
| 77 | {
|
| 78 | private final short chunkPosCrammed;
|
| 79 | private final IBlockState blockState;
|
| 80 |
|
| 81 | public BlockUpdateData(short p_i45984_2_, IBlockState state)
|
| 82 | {
|
| 83 | this.chunkPosCrammed = p_i45984_2_;
|
| 84 | this.blockState = state;
|
| 85 | }
|
| 86 |
|
| 87 | public BlockUpdateData(short p_i45985_2_, Chunk chunkIn)
|
| 88 | {
|
| 89 | this.chunkPosCrammed = p_i45985_2_;
|
| 90 | this.blockState = chunkIn.getBlockState(this.getPos());
|
| 91 | }
|
| 92 |
|
| 93 | public BlockPos getPos()
|
| 94 | {
|
| 95 | return new BlockPos(S22PacketMultiBlockChange.this.chunkPosCoord.getBlock(this.chunkPosCrammed >> 12 & 15, this.chunkPosCrammed & 255, this.chunkPosCrammed >> 8 & 15));
|
| 96 | }
|
| 97 |
|
| 98 | public short func_180089_b()
|
| 99 | {
|
| 100 | return this.chunkPosCrammed;
|
| 101 | }
|
| 102 |
|
| 103 | public IBlockState getBlockState()
|
| 104 | {
|
| 105 | return this.blockState;
|
| 106 | }
|
| 107 | }
|
| 108 | }
|
| 109 |
|