Skip to content

Commit

Permalink
Add new 1.9 packets
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulloy2 committed Apr 3, 2016
1 parent ecb89c0 commit 7c6b117
Show file tree
Hide file tree
Showing 21 changed files with 831 additions and 253 deletions.
14 changes: 7 additions & 7 deletions PacketWrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.comphenix.packetwrapper</groupId>
<artifactId>PacketWrapper</artifactId>
<packaging>jar</packaging>
<version>1.8.7-R0.1-SNAPSHOT</version>
<version>1.9-R0.1-SNAPSHOT</version>
<name>PacketWrapper</name>

<inceptionYear>2012</inceptionYear>
Expand Down Expand Up @@ -44,17 +44,17 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.7-R0.1-SNAPSHOT</version>
<version>1.9-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8.7-R0.1-SNAPSHOT</version>
<version>1.9-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>3.6.4</version>
<artifactId>ProtocolLib-API</artifactId>
<version>4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -114,8 +114,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,23 @@ public int getLightOffset() {
* Retrieve the starting index of the skylight data (4 bit per block).
* <p>
* This will be 2048 bytes in lenght if the skylight data exists (see {@link #hasSkylightOffset()}),
* no bytes if not.
* no bytes if not.
* @return The starting location of the skylight data.
*/
public int getSkylightOffset() {
return skylightOffset;
}

/**
* Determine if the current chunklet contains skylight data.
* Determine if the current chunklet contains skylight data.
* @return TRUE if it does, FALSE otherwise.
*/
public boolean hasSkylightOffset() {
return skylightOffset >= 0;
}

/**
* Retrieve the extra 4 bits in each block ID, if necessary.
* Retrieve the extra 4 bits in each block ID, if necessary.
* <p>
* This will be 2048 bytes in lenght if the extra data exists, no bytes if not.
* @return The starting location of the extra data.
Expand Down Expand Up @@ -149,7 +149,7 @@ public interface ChunkletProcessor {
public void processChunklet(Location origin, byte[] data, ChunkOffsets offsets);

/**
* Process the biome array for a chunk (16x256x16).
* Process the biome array for a chunk (16x256x16).
* <p>
* This method will not be called if the chunk is missing biome information.
* @param origin - the block with the lowest x, y and z coordinate in the chunk.
Expand Down Expand Up @@ -219,7 +219,8 @@ public static ChunkPacketProcessor fromMapPacket(PacketContainer packet, World w
* @param packet - the map chunk bulk packet.
* @return The chunk packet processors.
*/
public static ChunkPacketProcessor[] fromMapBulkPacket(PacketContainer packet, World world) {
// The MAP_CHUNK_BULK packet no longer exists
/*public static ChunkPacketProcessor[] fromMapBulkPacket(PacketContainer packet, World world) {
if (!packet.getType().equals(PacketType.Play.Server.MAP_CHUNK_BULK))
throw new IllegalArgumentException(packet + " must be a MAP_CHUNK_BULK packet.");
Expand Down Expand Up @@ -256,7 +257,7 @@ public static ChunkPacketProcessor[] fromMapBulkPacket(PacketContainer packet, W
dataStartIndex += processor.size;
}
return processors;
}
}*/

/**
* Begin processing the current chunk with the provided processor.
Expand All @@ -275,7 +276,7 @@ public void process(ChunkletProcessor processor) {

int skylightCount = getSkylightCount();

// The total size of a chunk is the number of blocks sent (depends on the number of sections) multiplied by the
// The total size of a chunk is the number of blocks sent (depends on the number of sections) multiplied by the
// amount of bytes per block. This last figure can be calculated by adding together all the data parts:
// For any block:
// * Block ID - 8 bits per block (byte)
Expand All @@ -287,18 +288,18 @@ public void process(ChunkletProcessor processor) {
// * Add array - 4 bits per block
// Biome array - only if the entire chunk (has continous) is sent:
// * Biome array - 256 bytes
//
// A section has 16 * 16 * 16 = 4096 blocks.
//
// A section has 16 * 16 * 16 = 4096 blocks.
size = BYTES_PER_NIBBLE_PART * (
(NIBBLES_REQUIRED + skylightCount) * chunkSectionNumber +
extraSectionNumber) +
(NIBBLES_REQUIRED + skylightCount) * chunkSectionNumber +
extraSectionNumber) +
(hasContinous ? BIOME_ARRAY_LENGTH : 0);

if ((getOffset(2) - startIndex) > data.length) {
return;
}

// Make sure the chunk is loaded
// Make sure the chunk is loaded
if (isChunkLoaded(world, chunkX, chunkZ)) {
translate(processor);
}
Expand Down Expand Up @@ -346,7 +347,7 @@ private void translate(ChunkletProcessor processor) {
}

if (hasContinous) {
processor.processBiomeArray(new Location(world, chunkX << 4, 0, chunkZ << 4),
processor.processBiomeArray(new Location(world, chunkX << 4, 0, chunkZ << 4),
data, startIndex + size - BIOME_ARRAY_LENGTH);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* This file is part of PacketWrapper.
* Copyright (C) 2012-2015 Kristian S. Strangeland
* Copyright (C) 2015 dmulloy2
*
* PacketWrapper is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PacketWrapper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PacketWrapper. If not, see <http://www.gnu.org/licenses/>.
*/
package com.comphenix.packetwrapper;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;

public class WrapperPlayClientBoatMove extends AbstractPacket {

public static final PacketType TYPE = PacketType.Play.Client.BOAT_MOVE;

public WrapperPlayClientBoatMove() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}

public WrapperPlayClientBoatMove(PacketContainer packet) {
super(packet, TYPE);
}

// TODO Figure out what these fields mean

public boolean getFlag() {
return handle.getBooleans().read(0);
}

public void setFlag(boolean value) {
handle.getBooleans().write(0, value);
}

public boolean getFlag1() {
return handle.getBooleans().read(1);
}

public void setFlag1(boolean value) {
handle.getBooleans().write(1, value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;

public class WrapperPlayServerSetCompression extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.SET_COMPRESSION;
public class WrapperPlayClientTeleportAccept extends AbstractPacket {

public static final PacketType TYPE = PacketType.Play.Client.TELEPORT_ACCEPT;

public WrapperPlayServerSetCompression() {
public WrapperPlayClientTeleportAccept() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}

public WrapperPlayServerSetCompression(PacketContainer packet) {
public WrapperPlayClientTeleportAccept(PacketContainer packet) {
super(packet, TYPE);
}

/**
* Retrieve Threshold.
* Retrieve Teleport ID.
* <p>
* Notes: threshold is the max size of a packet before its compressed
* @return The current Threshold
* Notes: the ID given by the Player Position And Look packet
* @return The current Teleport ID
*/
public int getThreshold() {
public int getTeleportId() {
return handle.getIntegers().read(0);
}

/**
* Set Threshold.
* Set Teleport ID.
* @param value - new value.
*/
public void setThreshold(int value) {
public void setTeleportId(int value) {
handle.getIntegers().write(0, value);
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* This file is part of PacketWrapper.
* Copyright (C) 2012-2015 Kristian S. Strangeland
* Copyright (C) 2015 dmulloy2
*
* PacketWrapper is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PacketWrapper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PacketWrapper. If not, see <http://www.gnu.org/licenses/>.
*/
package com.comphenix.packetwrapper;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.BlockPosition;

public class WrapperPlayClientUseItem extends AbstractPacket {

public static final PacketType TYPE = PacketType.Play.Client.USE_ITEM;

public WrapperPlayClientUseItem() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}

public WrapperPlayClientUseItem(PacketContainer packet) {
super(packet, TYPE);
}

/**
* Retrieve Location.
* <p>
* Notes: block position
* @return The current Location
*/
public BlockPosition getLocation() {
return handle.getBlockPositionModifier().read(0);
}

/**
* Set Location.
* @param value - new value.
*/
public void setLocation(BlockPosition value) {
handle.getBlockPositionModifier().write(0, value);
}

// TODO EnumDirection -> face

// TODO EnumHand -> hand

/**
* Retrieve Cursor Position X.
* <p>
* Notes: the position of the crosshair on the block, from 0 to 15 increasing from west to east
* @return The current Cursor Position X
*/
public float getCursorPositionX() {
return handle.getFloat().read(0);
}

/**
* Set Cursor Position X.
* @param value - new value.
*/
public void setCursorPositionX(float value) {
handle.getFloat().write(0, value);
}

/**
* Retrieve Cursor Position Y.
* <p>
* Notes: the position of the crosshair on the block, from 0 to 15 increasing from bottom to top
* @return The current Cursor Position Y
*/
public float getCursorPositionY() {
return handle.getFloat().read(1);
}

/**
* Set Cursor Position Y.
* @param value - new value.
*/
public void setCursorPositionY(float value) {
handle.getFloat().write(1, value);
}

/**
* Retrieve Cursor Position Z.
* <p>
* Notes: the position of the crosshair on the block, from 0 to 15 increasing from north to south
* @return The current Cursor Position Z
*/
public float getCursorPositionZ() {
return handle.getFloat().read(2);
}

/**
* Set Cursor Position Z.
* @param value - new value.
*/
public void setCursorPositionZ(float value) {
handle.getFloat().write(2, value);
}

}
Loading

0 comments on commit 7c6b117

Please sign in to comment.