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