Updated to support latest MCProtocolLib (#623)

* Updated to support latest MCProtocolLib

* Cleaned up names and imports

* Fixed minecarts

* Fixed throwables

* Fixed tnt
This commit is contained in:
rtm516 2020-05-23 21:56:49 +01:00 committed by GitHub
parent 81d3b0ef10
commit 8f01221275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 55 deletions

View file

@ -26,7 +26,7 @@
package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.ProjectileData;
import com.github.steveice10.mc.protocol.data.game.entity.object.ProjectileData;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import org.geysermc.connector.GeyserConnector;

View file

@ -27,7 +27,7 @@ package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.HangingDirection;
import com.github.steveice10.mc.protocol.data.game.entity.object.HangingDirection;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder;

View file

@ -99,10 +99,10 @@ public enum EntityType {
TRIPOD_CAMERA(Entity.class, 62, 0f),
PLAYER(PlayerEntity.class, 63, 1.8f, 0.6f, 0.6f, 1.62f),
ITEM(ItemEntity.class, 64, 0.25f, 0.25f),
TNT(TNTEntity.class, 65, 0.98f, 0.98f),
PRIMED_TNT(TNTEntity.class, 65, 0.98f, 0.98f, 0.98f, 0f, "minecraft:tnt"),
FALLING_BLOCK(FallingBlockEntity.class, 66, 0.98f, 0.98f),
MOVING_BLOCK(Entity.class, 67, 0f),
EXPERIENCE_BOTTLE(ThrowableEntity.class, 68, 0.25f, 0.25f, 0f, 0f, "minecraft:xp_bottle"),
THROWN_EXP_BOTTLE(ThrowableEntity.class, 68, 0.25f, 0.25f, 0f, 0f, "minecraft:xp_bottle"),
EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f, 0f, 0f, 0f, "minecraft:xp_orb"),
EYE_OF_ENDER(Entity.class, 70, 0.25f, 0.25f, 0f, 0f, "minecraft:eye_of_ender_signal"),
END_CRYSTAL(EnderCrystalEntity.class, 71, 0f, 0f, 0f, 0f, "minecraft:ender_crystal"),
@ -117,12 +117,12 @@ public enum EntityType {
ARROW(TippedArrowEntity.class, 80, 0.25f, 0.25f),
SPECTRAL_ARROW(AbstractArrowEntity.class, 80, 0.25f, 0.25f, 0.25f, 0f, "minecraft:arrow"),
SNOWBALL(ThrowableEntity.class, 81, 0.25f),
EGG(ThrowableEntity.class, 82, 0.25f),
THROWN_EGG(ThrowableEntity.class, 82, 0.25f, 0.25f, 0.25f, 0f, "minecraft:egg"),
PAINTING(PaintingEntity.class, 83, 0f),
MINECART(MinecartEntity.class, 84, 0.7f, 0.98f),
FIREBALL(ItemedFireballEntity.class, 85, 1.0f),
POTION(ThrowableEntity.class, 86, 0.25f),
ENDER_PEARL(ThrowableEntity.class, 87, 0.25f),
THROWN_POTION(ThrowableEntity.class, 86, 0.25f, 0.25f, 0.25f, 0f, "minecraft:splash_potion"),
THROWN_ENDERPEARL(ThrowableEntity.class, 87, 0.25f, 0.25f, 0.25f, 0f, "minecraft:ender_pearl"),
LEASH_KNOT(LeashKnotEntity.class, 88, 0.5f, 0.375f),
WITHER_SKULL(Entity.class, 89, 0.3125f),
BOAT(Entity.class, 90, 0.7f, 1.6f, 1.6f, 0.35f),
@ -130,11 +130,11 @@ public enum EntityType {
LIGHTNING_BOLT(Entity.class, 93, 0f),
SMALL_FIREBALL(ItemedFireballEntity.class, 94, 0.3125f),
AREA_EFFECT_CLOUD(AreaEffectCloudEntity.class, 95, 0.5f, 1.0f),
HOPPER_MINECART(MinecartEntity.class, 96, 0.7f, 0.98f),
TNT_MINECART(MinecartEntity.class, 97, 0.7f, 0.98f),
CHEST_MINECART(MinecartEntity.class, 98, 0.7f, 0.98f),
MINECART_HOPPER(MinecartEntity.class, 96, 0.7f, 0.98f, 0.98f, 0f, "minecraft:hopper_minecart"),
MINECART_TNT(MinecartEntity.class, 97, 0.7f, 0.98f, 0.98f, 0f, "minecraft:tnt_minecart"),
MINECART_CHEST(MinecartEntity.class, 98, 0.7f, 0.98f, 0.98f, 0f, "minecraft:chest_minecart"),
COMMAND_BLOCK_MINECART(MinecartEntity.class, 100, 0.7f, 0.98f),
MINECART_COMMAND_BLOCK(MinecartEntity.class, 100, 0.7f, 0.98f, 0.98f, 0f, "minecraft:command_block_minecart"),
LINGERING_POTION(ThrowableEntity.class, 101, 0f),
LLAMA_SPIT(Entity.class, 102, 0.25f),
EVOKER_FANGS(Entity.class, 103, 0.8f, 0.5f),

View file

@ -25,17 +25,16 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.FallingBlockData;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.HangingDirection;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.ProjectileData;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket;
import com.github.steveice10.mc.protocol.data.game.entity.object.FallingBlockData;
import com.github.steveice10.mc.protocol.data.game.entity.object.HangingDirection;
import com.github.steveice10.mc.protocol.data.game.entity.object.ProjectileData;
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnEntityPacket;
import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.FallingBlockEntity;
import org.geysermc.connector.entity.FishingHookEntity;
import org.geysermc.connector.entity.ItemFrameEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
@ -44,17 +43,17 @@ import org.geysermc.connector.utils.EntityUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@Translator(packet = ServerSpawnObjectPacket.class)
public class JavaSpawnObjectTranslator extends PacketTranslator<ServerSpawnObjectPacket> {
@Translator(packet = ServerSpawnEntityPacket.class)
public class JavaSpawnEntityTranslator extends PacketTranslator<ServerSpawnEntityPacket> {
@Override
public void translate(ServerSpawnObjectPacket packet, GeyserSession session) {
public void translate(ServerSpawnEntityPacket packet, GeyserSession session) {
Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
Vector3f rotation = Vector3f.from(packet.getYaw(), packet.getPitch(), 0);
EntityType type = EntityUtils.toBedrockEntity(packet.getType());
org.geysermc.connector.entity.type.EntityType type = EntityUtils.toBedrockEntity(packet.getType());
if (type == null) {
session.getConnector().getLogger().warning("Entity type " + packet.getType() + " was null.");
return;
@ -63,19 +62,19 @@ public class JavaSpawnObjectTranslator extends PacketTranslator<ServerSpawnObjec
Class<? extends Entity> entityClass = type.getEntityClass();
try {
Entity entity;
if (packet.getType() == ObjectType.FALLING_BLOCK) {
if (packet.getType() == EntityType.FALLING_BLOCK) {
entity = new FallingBlockEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation, ((FallingBlockData) packet.getData()).getId());
} else if (packet.getType() == ObjectType.ITEM_FRAME) {
} else if (packet.getType() == EntityType.ITEM_FRAME) {
// Item frames need the hanging direction
entity = new ItemFrameEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation, (HangingDirection) packet.getData());
} else if (packet.getType() == ObjectType.FISHING_BOBBER) {
} else if (packet.getType() == EntityType.FISHING_BOBBER) {
// Fishing bobbers need the owner for the line
entity = new FishingHookEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation, (ProjectileData) packet.getData());
} else {
Constructor<? extends Entity> entityConstructor = entityClass.getConstructor(long.class, long.class, EntityType.class,
Constructor<? extends Entity> entityConstructor = entityClass.getConstructor(long.class, long.class, org.geysermc.connector.entity.type.EntityType.class,
Vector3f.class, Vector3f.class, Vector3f.class);
entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),

View file

@ -25,9 +25,8 @@
package org.geysermc.connector.network.translators.java.entity.spawn;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnLivingEntityPacket;
import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
@ -35,14 +34,14 @@ import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.EntityUtils;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket;
import com.nukkitx.math.vector.Vector3f;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@Translator(packet = ServerSpawnMobPacket.class)
public class JavaSpawnMobTranslator extends PacketTranslator<ServerSpawnMobPacket> {
@Translator(packet = ServerSpawnLivingEntityPacket.class)
public class JavaSpawnLivingEntityTranslator extends PacketTranslator<ServerSpawnLivingEntityPacket> {
@Override
public void translate(ServerSpawnMobPacket packet, GeyserSession session) {
public void translate(ServerSpawnLivingEntityPacket packet, GeyserSession session) {
Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
Vector3f rotation = Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getHeadYaw());

View file

@ -31,17 +31,17 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnWeatherEntityPacket;
import com.nukkitx.math.vector.Vector3f;
@Translator(packet = ServerSpawnGlobalEntityPacket.class)
public class JavaSpawnGlobalEntityTranslator extends PacketTranslator<ServerSpawnGlobalEntityPacket> {
@Translator(packet = ServerSpawnWeatherEntityPacket.class)
public class JavaSpawnWeatherEntityTranslator extends PacketTranslator<ServerSpawnWeatherEntityPacket> {
@Override
public void translate(ServerSpawnGlobalEntityPacket packet, GeyserSession session) {
public void translate(ServerSpawnWeatherEntityPacket packet, GeyserSession session) {
Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
// Currently GlobalEntityType only has a lightning bolt
// Currently WeatherEntityType only has a lightning bolt
Entity entity = new Entity(
packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
EntityType.LIGHTNING_BOLT, position, Vector3f.ZERO, Vector3f.ZERO

View file

@ -26,8 +26,6 @@
package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
import com.github.steveice10.mc.protocol.data.game.entity.type.MobType;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType;
import org.geysermc.connector.entity.type.EntityType;
public class EntityUtils {
@ -64,21 +62,7 @@ public class EntityUtils {
* @param type The MobType to convert
* @return Converted EntityType
*/
public static EntityType toBedrockEntity(MobType type) {
try {
return EntityType.valueOf(type.name());
} catch (IllegalArgumentException ex) {
return null;
}
}
/**
* Converts a ObjectType to a Bedrock edition EntityType, returns null if the EntityType is not found
*
* @param type The ObjectType to convert
* @return Converted EntityType
*/
public static EntityType toBedrockEntity(ObjectType type) {
public static EntityType toBedrockEntity(com.github.steveice10.mc.protocol.data.game.entity.type.EntityType type) {
try {
return EntityType.valueOf(type.name());
} catch (IllegalArgumentException ex) {