Merge branch 'develop' into merge_branch
# Conflicts: # core/src/main/java/mc/core/Location.java
This commit is contained in:
@@ -14,6 +14,11 @@ import java.io.Serializable;
|
||||
public class Location implements Serializable{
|
||||
private double x, y, z;
|
||||
|
||||
private static int floor_double(double value) {
|
||||
int i = (int)value;
|
||||
return value < (double)i ? i - 1 : i;
|
||||
}
|
||||
|
||||
public static Location copyOf(Location location) {
|
||||
return new Location(
|
||||
location.x,
|
||||
@@ -26,12 +31,22 @@ public class Location implements Serializable{
|
||||
return new Location(0,10,0);
|
||||
}
|
||||
|
||||
public Location(long compactValue) {
|
||||
set(compactValue);
|
||||
}
|
||||
|
||||
public void set(Location location) {
|
||||
this.x = location.x;
|
||||
this.y = location.y;
|
||||
this.z = location.z;
|
||||
}
|
||||
|
||||
public void set(long compactValue) {
|
||||
this.x = compactValue >> 38;
|
||||
this.y = (compactValue >> 26) & 0xFFF;
|
||||
this.z = compactValue << 38 >> 38; // is normal?
|
||||
}
|
||||
|
||||
public Location diff(Location location) {
|
||||
return new Location(
|
||||
this.x - location.x,
|
||||
@@ -51,4 +66,10 @@ public class Location implements Serializable{
|
||||
public int getBlockZ() {
|
||||
return (int) z;
|
||||
}
|
||||
|
||||
public long toLong() {
|
||||
return ((floor_double(x) & 0x3FFFFFF) << 38)
|
||||
| ((floor_double(y) & 0xFFF) << 26)
|
||||
| (floor_double(z) & 0x3FFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-06-10
|
||||
*/
|
||||
package mc.core.network.proto_1_12_2.netty.wrappers;
|
||||
|
||||
import mc.core.network.proto_1_12_2.NetOutputStream_p340;
|
||||
package mc.core.network.proto_1_12_2;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
@@ -85,6 +85,7 @@ public enum State {
|
||||
.put(BossBarPacket.class, 0x0C)
|
||||
.put(ChatMessageServerPacket.class, 0x0F)
|
||||
.put(PluginMessagePacket.class, 0x18)
|
||||
.put(ChangeGameState.class, 0x1E)
|
||||
.put(KeepAlivePacket.class, 0x1F)
|
||||
.put(JoinGamePacket.class, 0x23)
|
||||
.put(PlayerAbilitiesPacket.class, 0x2C)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-07-27
|
||||
*/
|
||||
package mc.core.network.proto_1_12_2.packets;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.network.NetOutputStream;
|
||||
import mc.core.network.SCPacket;
|
||||
|
||||
@Setter
|
||||
public class ChangeGameState implements SCPacket {
|
||||
@RequiredArgsConstructor
|
||||
public enum Reason {
|
||||
INVALID_BED(0), // Would be used to switch between messages, but the only used message is 0 for invalid bed (wat?)
|
||||
RAINING_END(1),
|
||||
RAINING_BEGIN(2),
|
||||
CHANGE_GAMEMODE(3), // 0: Survival, 1: Creative, 2: Adventure, 3: Spectator
|
||||
ARROW_HITTING_PLAYER(6), // Appears to be played when an arrow strikes another player in Multiplayer
|
||||
FADE_VALUE(7), // The current darkness value. 1 = Dark, 0 = Bright, Setting the value higher causes the game to change color and freeze
|
||||
FADE_TIME(8), // Time in ticks for the sky to fade
|
||||
GUARDIAN_APPEARANCE(10); // Play elder guardian mob appearance (effect and sound)
|
||||
|
||||
private final int id;
|
||||
}
|
||||
|
||||
private Reason reason;
|
||||
private float value;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetOutputStream netStream) {
|
||||
netStream.writeUnsignedByte(reason.id);
|
||||
netStream.writeFloat(value);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import lombok.ToString;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.NetOutputStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.serializers.LocationSerializer;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@@ -22,6 +21,6 @@ public class SpawnPositionPacket implements SCPacket {
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetOutputStream netStream) {
|
||||
netStream.writeLong(LocationSerializer.serialize(location));
|
||||
netStream.writeLong(location.toLong());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ package mc.core.network.proto_1_12_2.packets;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.network.NetInputStream;
|
||||
import mc.core.network.proto_1_12_2.serializers.LocationSerializer;
|
||||
|
||||
public class TabCompletePacket implements CSPacket {
|
||||
private String text;
|
||||
@@ -22,7 +21,7 @@ public class TabCompletePacket implements CSPacket {
|
||||
this.hasPosition = netStream.readBoolean();
|
||||
|
||||
if (this.hasPosition) {
|
||||
this.location = LocationSerializer.deserialize(netStream.readLong());
|
||||
this.location = new Location(netStream.readLong());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-06-11
|
||||
*/
|
||||
package mc.core.network.proto_1_12_2.serializers;
|
||||
|
||||
import mc.core.Location;
|
||||
|
||||
public class LocationSerializer {
|
||||
private static int floor_double(double value) {
|
||||
int i = (int)value;
|
||||
return value < (double)i ? i - 1 : i;
|
||||
}
|
||||
|
||||
public static long serialize(Location location) {
|
||||
return ((floor_double(location.getX()) & 0x3FFFFFF) << 38)
|
||||
| ((floor_double(location.getY()) & 0xFFF) << 26)
|
||||
| (floor_double(location.getZ()) & 0x3FFFFFF);
|
||||
}
|
||||
|
||||
public static Location deserialize(long location) {
|
||||
return new Location(
|
||||
location >> 38,
|
||||
(location >> 26) & 0xFFF,
|
||||
location << 38 >> 38);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.network.NetOutputStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.State;
|
||||
import mc.core.network.proto_1_12_2.netty.wrappers.ByteArrayOutputNetStream;
|
||||
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
|
||||
import mc.core.network.proto_1_12_2.netty.wrappers.WrapperNetOutputStream;
|
||||
|
||||
import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE;
|
||||
|
||||
Reference in New Issue
Block a user