mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Prepare the switch to netty
This commit is contained in:
parent
656ccac26d
commit
f52e0dd6ba
@ -24,6 +24,9 @@ dependencies {
|
|||||||
|
|
||||||
apt lombokDependency
|
apt lombokDependency
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/io.netty/netty-all
|
||||||
|
compile group: 'io.netty', name: 'netty-all', version: '4.1.48.Final'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/com.github.jhg023/SimpleNet
|
// https://mvnrepository.com/artifact/com.github.jhg023/SimpleNet
|
||||||
implementation group: 'com.github.jhg023', name: 'SimpleNet', version: '1.6.5'
|
implementation group: 'com.github.jhg023', name: 'SimpleNet', version: '1.6.5'
|
||||||
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
||||||
|
@ -54,8 +54,8 @@ public class MinecraftServer {
|
|||||||
public static final int THREAD_COUNT_SCHEDULER = 1;
|
public static final int THREAD_COUNT_SCHEDULER = 1;
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
public static final int CHUNK_VIEW_DISTANCE = 10;
|
public static final int CHUNK_VIEW_DISTANCE = 2;
|
||||||
public static final int ENTITY_VIEW_DISTANCE = 5;
|
public static final int ENTITY_VIEW_DISTANCE = 2;
|
||||||
// Can be modified at performance cost when decreased
|
// Can be modified at performance cost when decreased
|
||||||
private static final int MS_TO_SEC = 1000;
|
private static final int MS_TO_SEC = 1000;
|
||||||
public static final int TICK_MS = MS_TO_SEC / 20;
|
public static final int TICK_MS = MS_TO_SEC / 20;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package fr.themode.minestom.entity;
|
package fr.themode.minestom.entity;
|
||||||
|
|
||||||
import com.github.simplenet.packet.Packet;
|
|
||||||
import fr.themode.minestom.MinecraftServer;
|
import fr.themode.minestom.MinecraftServer;
|
||||||
import fr.themode.minestom.Viewable;
|
import fr.themode.minestom.Viewable;
|
||||||
import fr.themode.minestom.collision.BoundingBox;
|
import fr.themode.minestom.collision.BoundingBox;
|
||||||
@ -12,6 +11,7 @@ import fr.themode.minestom.event.Event;
|
|||||||
import fr.themode.minestom.instance.Chunk;
|
import fr.themode.minestom.instance.Chunk;
|
||||||
import fr.themode.minestom.instance.Instance;
|
import fr.themode.minestom.instance.Instance;
|
||||||
import fr.themode.minestom.item.Material;
|
import fr.themode.minestom.item.Material;
|
||||||
|
import fr.themode.minestom.net.packet.PacketWriter;
|
||||||
import fr.themode.minestom.net.packet.server.play.*;
|
import fr.themode.minestom.net.packet.server.play.*;
|
||||||
import fr.themode.minestom.net.player.PlayerConnection;
|
import fr.themode.minestom.net.player.PlayerConnection;
|
||||||
import fr.themode.minestom.utils.*;
|
import fr.themode.minestom.utils.*;
|
||||||
@ -617,7 +617,7 @@ public abstract class Entity implements Viewable, DataContainer {
|
|||||||
return metaDataPacket;
|
return metaDataPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Consumer<Packet> getMetadataConsumer() {
|
public Consumer<PacketWriter> getMetadataConsumer() {
|
||||||
return packet -> {
|
return packet -> {
|
||||||
fillMetadataIndex(packet, 0);
|
fillMetadataIndex(packet, 0);
|
||||||
fillMetadataIndex(packet, 1);
|
fillMetadataIndex(packet, 1);
|
||||||
@ -636,7 +636,7 @@ public abstract class Entity implements Viewable, DataContainer {
|
|||||||
sendPacketToViewersAndSelf(metaDataPacket);
|
sendPacketToViewersAndSelf(metaDataPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillMetadataIndex(Packet packet, int index) {
|
private void fillMetadataIndex(PacketWriter packet, int index) {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
fillStateMetadata(packet);
|
fillStateMetadata(packet);
|
||||||
@ -656,9 +656,9 @@ public abstract class Entity implements Viewable, DataContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillStateMetadata(Packet packet) {
|
private void fillStateMetadata(PacketWriter packet) {
|
||||||
packet.putByte((byte) 0);
|
packet.writeByte((byte) 0);
|
||||||
packet.putByte(METADATA_BYTE);
|
packet.writeByte(METADATA_BYTE);
|
||||||
byte index0 = 0;
|
byte index0 = 0;
|
||||||
if (onFire)
|
if (onFire)
|
||||||
index0 += 1;
|
index0 += 1;
|
||||||
@ -676,31 +676,31 @@ public abstract class Entity implements Viewable, DataContainer {
|
|||||||
index0 += 64;
|
index0 += 64;
|
||||||
if (usingElytra)
|
if (usingElytra)
|
||||||
index0 += 128;
|
index0 += 128;
|
||||||
packet.putByte(index0);
|
packet.writeByte(index0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillAirTickMetaData(Packet packet) {
|
private void fillAirTickMetaData(PacketWriter packet) {
|
||||||
packet.putByte((byte) 1);
|
packet.writeByte((byte) 1);
|
||||||
packet.putByte(METADATA_VARINT);
|
packet.writeByte(METADATA_VARINT);
|
||||||
Utils.writeVarInt(packet, air);
|
packet.writeVarInt(air);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillCustomNameMetaData(Packet packet) {
|
private void fillCustomNameMetaData(PacketWriter packet) {
|
||||||
packet.putByte((byte) 2);
|
packet.writeByte((byte) 2);
|
||||||
packet.putByte(METADATA_CHAT);
|
packet.writeByte(METADATA_CHAT);
|
||||||
Utils.writeString(packet, customName);
|
packet.writeSizedString(customName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillNoGravityMetaData(Packet packet) {
|
private void fillNoGravityMetaData(PacketWriter packet) {
|
||||||
packet.putByte((byte) 5);
|
packet.writeByte((byte) 5);
|
||||||
packet.putByte(METADATA_BOOLEAN);
|
packet.writeByte(METADATA_BOOLEAN);
|
||||||
packet.putBoolean(noGravity);
|
packet.writeBoolean(noGravity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillPoseMetaData(Packet packet) {
|
private void fillPoseMetaData(PacketWriter packet) {
|
||||||
packet.putByte((byte) 6);
|
packet.writeByte((byte) 6);
|
||||||
packet.putByte(METADATA_POSE);
|
packet.writeByte(METADATA_POSE);
|
||||||
Utils.writeVarInt(packet, pose.ordinal());
|
packet.writeVarInt(pose.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendSynchronization() {
|
protected void sendSynchronization() {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package fr.themode.minestom.entity;
|
package fr.themode.minestom.entity;
|
||||||
|
|
||||||
import com.github.simplenet.packet.Packet;
|
|
||||||
import fr.themode.minestom.item.ItemStack;
|
import fr.themode.minestom.item.ItemStack;
|
||||||
import fr.themode.minestom.utils.Utils;
|
import fr.themode.minestom.net.packet.PacketWriter;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -38,12 +37,12 @@ public class ItemEntity extends ObjectEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Consumer<Packet> getMetadataConsumer() {
|
public Consumer<PacketWriter> getMetadataConsumer() {
|
||||||
return packet -> {
|
return packet -> {
|
||||||
super.getMetadataConsumer().accept(packet);
|
super.getMetadataConsumer().accept(packet);
|
||||||
packet.putByte((byte) 7);
|
packet.writeByte((byte) 7);
|
||||||
packet.putByte(METADATA_SLOT);
|
packet.writeByte(METADATA_SLOT);
|
||||||
Utils.writeItemStack(packet, itemStack);
|
packet.writeItemStack(itemStack);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package fr.themode.minestom.entity;
|
package fr.themode.minestom.entity;
|
||||||
|
|
||||||
import com.github.simplenet.packet.Packet;
|
|
||||||
import fr.themode.minestom.collision.BoundingBox;
|
import fr.themode.minestom.collision.BoundingBox;
|
||||||
import fr.themode.minestom.entity.property.Attribute;
|
import fr.themode.minestom.entity.property.Attribute;
|
||||||
import fr.themode.minestom.event.DeathEvent;
|
import fr.themode.minestom.event.DeathEvent;
|
||||||
import fr.themode.minestom.event.PickupItemEvent;
|
import fr.themode.minestom.event.PickupItemEvent;
|
||||||
import fr.themode.minestom.instance.Chunk;
|
import fr.themode.minestom.instance.Chunk;
|
||||||
import fr.themode.minestom.item.ItemStack;
|
import fr.themode.minestom.item.ItemStack;
|
||||||
|
import fr.themode.minestom.net.packet.PacketWriter;
|
||||||
import fr.themode.minestom.net.packet.server.play.CollectItemPacket;
|
import fr.themode.minestom.net.packet.server.play.CollectItemPacket;
|
||||||
import fr.themode.minestom.net.packet.server.play.EntityAnimationPacket;
|
import fr.themode.minestom.net.packet.server.play.EntityAnimationPacket;
|
||||||
import fr.themode.minestom.net.packet.server.play.EntityPropertiesPacket;
|
import fr.themode.minestom.net.packet.server.play.EntityPropertiesPacket;
|
||||||
@ -76,11 +76,11 @@ public abstract class LivingEntity extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Consumer<Packet> getMetadataConsumer() {
|
public Consumer<PacketWriter> getMetadataConsumer() {
|
||||||
return packet -> {
|
return packet -> {
|
||||||
super.getMetadataConsumer().accept(packet);
|
super.getMetadataConsumer().accept(packet);
|
||||||
packet.putByte((byte) 7);
|
packet.writeByte((byte) 7);
|
||||||
packet.putByte(METADATA_BYTE);
|
packet.writeByte(METADATA_BYTE);
|
||||||
byte activeHandValue = 0;
|
byte activeHandValue = 0;
|
||||||
if (isHandActive) {
|
if (isHandActive) {
|
||||||
activeHandValue += 1;
|
activeHandValue += 1;
|
||||||
@ -89,7 +89,7 @@ public abstract class LivingEntity extends Entity {
|
|||||||
if (riptideSpinAttack)
|
if (riptideSpinAttack)
|
||||||
activeHandValue += 4;
|
activeHandValue += 4;
|
||||||
}
|
}
|
||||||
packet.putByte(activeHandValue);
|
packet.writeByte(activeHandValue);
|
||||||
|
|
||||||
// TODO all remaining metadata
|
// TODO all remaining metadata
|
||||||
};
|
};
|
||||||
|
@ -80,9 +80,9 @@ public class PacketWriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(Consumer<Packet> consumer) {
|
public void write(Consumer<PacketWriter> consumer) {
|
||||||
if (consumer != null)
|
if (consumer != null)
|
||||||
consumer.accept(packet);
|
consumer.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBufferAndFree(BufferWrapper buffer) {
|
public void writeBufferAndFree(BufferWrapper buffer) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package fr.themode.minestom.net.packet.server.play;
|
package fr.themode.minestom.net.packet.server.play;
|
||||||
|
|
||||||
import com.github.simplenet.packet.Packet;
|
|
||||||
import fr.themode.minestom.net.packet.PacketWriter;
|
import fr.themode.minestom.net.packet.PacketWriter;
|
||||||
import fr.themode.minestom.net.packet.server.ServerPacket;
|
import fr.themode.minestom.net.packet.server.ServerPacket;
|
||||||
import fr.themode.minestom.net.packet.server.ServerPacketIdentifier;
|
import fr.themode.minestom.net.packet.server.ServerPacketIdentifier;
|
||||||
@ -10,7 +9,7 @@ import java.util.function.Consumer;
|
|||||||
public class EntityMetaDataPacket implements ServerPacket {
|
public class EntityMetaDataPacket implements ServerPacket {
|
||||||
|
|
||||||
public int entityId;
|
public int entityId;
|
||||||
public Consumer<Packet> consumer;
|
public Consumer<PacketWriter> consumer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketWriter writer) {
|
public void write(PacketWriter writer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user