Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-09-08 12:32:53 +02:00
Updated to support latest MCProtocolLib (#623)
* Updated to support latest MCProtocolLib * Cleaned up names and imports * Fixed minecarts * Fixed throwables * Fixed tnt
Dieser Commit ist enthalten in:
Ursprung
81d3b0ef10
Commit
8f01221275
@ -26,7 +26,7 @@
|
|||||||
package org.geysermc.connector.entity;
|
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.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.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
@ -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.EntityMetadata;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
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.Vector3f;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||||
|
@ -99,10 +99,10 @@ public enum EntityType {
|
|||||||
TRIPOD_CAMERA(Entity.class, 62, 0f),
|
TRIPOD_CAMERA(Entity.class, 62, 0f),
|
||||||
PLAYER(PlayerEntity.class, 63, 1.8f, 0.6f, 0.6f, 1.62f),
|
PLAYER(PlayerEntity.class, 63, 1.8f, 0.6f, 0.6f, 1.62f),
|
||||||
ITEM(ItemEntity.class, 64, 0.25f, 0.25f),
|
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),
|
FALLING_BLOCK(FallingBlockEntity.class, 66, 0.98f, 0.98f),
|
||||||
MOVING_BLOCK(Entity.class, 67, 0f),
|
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"),
|
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"),
|
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"),
|
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),
|
ARROW(TippedArrowEntity.class, 80, 0.25f, 0.25f),
|
||||||
SPECTRAL_ARROW(AbstractArrowEntity.class, 80, 0.25f, 0.25f, 0.25f, 0f, "minecraft:arrow"),
|
SPECTRAL_ARROW(AbstractArrowEntity.class, 80, 0.25f, 0.25f, 0.25f, 0f, "minecraft:arrow"),
|
||||||
SNOWBALL(ThrowableEntity.class, 81, 0.25f),
|
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),
|
PAINTING(PaintingEntity.class, 83, 0f),
|
||||||
MINECART(MinecartEntity.class, 84, 0.7f, 0.98f),
|
MINECART(MinecartEntity.class, 84, 0.7f, 0.98f),
|
||||||
FIREBALL(ItemedFireballEntity.class, 85, 1.0f),
|
FIREBALL(ItemedFireballEntity.class, 85, 1.0f),
|
||||||
POTION(ThrowableEntity.class, 86, 0.25f),
|
THROWN_POTION(ThrowableEntity.class, 86, 0.25f, 0.25f, 0.25f, 0f, "minecraft:splash_potion"),
|
||||||
ENDER_PEARL(ThrowableEntity.class, 87, 0.25f),
|
THROWN_ENDERPEARL(ThrowableEntity.class, 87, 0.25f, 0.25f, 0.25f, 0f, "minecraft:ender_pearl"),
|
||||||
LEASH_KNOT(LeashKnotEntity.class, 88, 0.5f, 0.375f),
|
LEASH_KNOT(LeashKnotEntity.class, 88, 0.5f, 0.375f),
|
||||||
WITHER_SKULL(Entity.class, 89, 0.3125f),
|
WITHER_SKULL(Entity.class, 89, 0.3125f),
|
||||||
BOAT(Entity.class, 90, 0.7f, 1.6f, 1.6f, 0.35f),
|
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),
|
LIGHTNING_BOLT(Entity.class, 93, 0f),
|
||||||
SMALL_FIREBALL(ItemedFireballEntity.class, 94, 0.3125f),
|
SMALL_FIREBALL(ItemedFireballEntity.class, 94, 0.3125f),
|
||||||
AREA_EFFECT_CLOUD(AreaEffectCloudEntity.class, 95, 0.5f, 1.0f),
|
AREA_EFFECT_CLOUD(AreaEffectCloudEntity.class, 95, 0.5f, 1.0f),
|
||||||
HOPPER_MINECART(MinecartEntity.class, 96, 0.7f, 0.98f),
|
MINECART_HOPPER(MinecartEntity.class, 96, 0.7f, 0.98f, 0.98f, 0f, "minecraft:hopper_minecart"),
|
||||||
TNT_MINECART(MinecartEntity.class, 97, 0.7f, 0.98f),
|
MINECART_TNT(MinecartEntity.class, 97, 0.7f, 0.98f, 0.98f, 0f, "minecraft:tnt_minecart"),
|
||||||
CHEST_MINECART(MinecartEntity.class, 98, 0.7f, 0.98f),
|
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),
|
LINGERING_POTION(ThrowableEntity.class, 101, 0f),
|
||||||
LLAMA_SPIT(Entity.class, 102, 0.25f),
|
LLAMA_SPIT(Entity.class, 102, 0.25f),
|
||||||
EVOKER_FANGS(Entity.class, 103, 0.8f, 0.5f),
|
EVOKER_FANGS(Entity.class, 103, 0.8f, 0.5f),
|
||||||
|
@ -25,17 +25,16 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.java.entity.spawn;
|
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.object.FallingBlockData;
|
||||||
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.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType;
|
import com.github.steveice10.mc.protocol.data.game.entity.object.ProjectileData;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.type.object.ProjectileData;
|
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnEntityPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.entity.FallingBlockEntity;
|
import org.geysermc.connector.entity.FallingBlockEntity;
|
||||||
import org.geysermc.connector.entity.FishingHookEntity;
|
import org.geysermc.connector.entity.FishingHookEntity;
|
||||||
import org.geysermc.connector.entity.ItemFrameEntity;
|
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.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
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.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
@Translator(packet = ServerSpawnObjectPacket.class)
|
@Translator(packet = ServerSpawnEntityPacket.class)
|
||||||
public class JavaSpawnObjectTranslator extends PacketTranslator<ServerSpawnObjectPacket> {
|
public class JavaSpawnEntityTranslator extends PacketTranslator<ServerSpawnEntityPacket> {
|
||||||
|
|
||||||
@Override
|
@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 position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
|
||||||
Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
|
Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
|
||||||
Vector3f rotation = Vector3f.from(packet.getYaw(), packet.getPitch(), 0);
|
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) {
|
if (type == null) {
|
||||||
session.getConnector().getLogger().warning("Entity type " + packet.getType() + " was null.");
|
session.getConnector().getLogger().warning("Entity type " + packet.getType() + " was null.");
|
||||||
return;
|
return;
|
||||||
@ -63,19 +62,19 @@ public class JavaSpawnObjectTranslator extends PacketTranslator<ServerSpawnObjec
|
|||||||
Class<? extends Entity> entityClass = type.getEntityClass();
|
Class<? extends Entity> entityClass = type.getEntityClass();
|
||||||
try {
|
try {
|
||||||
Entity entity;
|
Entity entity;
|
||||||
if (packet.getType() == ObjectType.FALLING_BLOCK) {
|
if (packet.getType() == EntityType.FALLING_BLOCK) {
|
||||||
entity = new FallingBlockEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
entity = new FallingBlockEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
||||||
type, position, motion, rotation, ((FallingBlockData) packet.getData()).getId());
|
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
|
// Item frames need the hanging direction
|
||||||
entity = new ItemFrameEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
entity = new ItemFrameEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
||||||
type, position, motion, rotation, (HangingDirection) packet.getData());
|
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
|
// Fishing bobbers need the owner for the line
|
||||||
entity = new FishingHookEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
entity = new FishingHookEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
||||||
type, position, motion, rotation, (ProjectileData) packet.getData());
|
type, position, motion, rotation, (ProjectileData) packet.getData());
|
||||||
} else {
|
} 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);
|
Vector3f.class, Vector3f.class, Vector3f.class);
|
||||||
|
|
||||||
entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
@ -25,9 +25,8 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.java.entity.spawn;
|
package org.geysermc.connector.network.translators.java.entity.spawn;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnLivingEntityPacket;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
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.network.translators.Translator;
|
||||||
import org.geysermc.connector.utils.EntityUtils;
|
import org.geysermc.connector.utils.EntityUtils;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket;
|
import java.lang.reflect.Constructor;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
@Translator(packet = ServerSpawnMobPacket.class)
|
@Translator(packet = ServerSpawnLivingEntityPacket.class)
|
||||||
public class JavaSpawnMobTranslator extends PacketTranslator<ServerSpawnMobPacket> {
|
public class JavaSpawnLivingEntityTranslator extends PacketTranslator<ServerSpawnLivingEntityPacket> {
|
||||||
|
|
||||||
@Override
|
@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 position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
|
||||||
Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
|
Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
|
||||||
Vector3f rotation = Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getHeadYaw());
|
Vector3f rotation = Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getHeadYaw());
|
@ -31,17 +31,17 @@ import org.geysermc.connector.network.session.GeyserSession;
|
|||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
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;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
|
||||||
@Translator(packet = ServerSpawnGlobalEntityPacket.class)
|
@Translator(packet = ServerSpawnWeatherEntityPacket.class)
|
||||||
public class JavaSpawnGlobalEntityTranslator extends PacketTranslator<ServerSpawnGlobalEntityPacket> {
|
public class JavaSpawnWeatherEntityTranslator extends PacketTranslator<ServerSpawnWeatherEntityPacket> {
|
||||||
|
|
||||||
@Override
|
@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());
|
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(
|
Entity entity = new Entity(
|
||||||
packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
|
||||||
EntityType.LIGHTNING_BOLT, position, Vector3f.ZERO, Vector3f.ZERO
|
EntityType.LIGHTNING_BOLT, position, Vector3f.ZERO, Vector3f.ZERO
|
@ -26,8 +26,6 @@
|
|||||||
package org.geysermc.connector.utils;
|
package org.geysermc.connector.utils;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
|
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;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
|
|
||||||
public class EntityUtils {
|
public class EntityUtils {
|
||||||
@ -64,21 +62,7 @@ public class EntityUtils {
|
|||||||
* @param type The MobType to convert
|
* @param type The MobType to convert
|
||||||
* @return Converted EntityType
|
* @return Converted EntityType
|
||||||
*/
|
*/
|
||||||
public static EntityType toBedrockEntity(MobType 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) {
|
|
||||||
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) {
|
|
||||||
try {
|
try {
|
||||||
return EntityType.valueOf(type.name());
|
return EntityType.valueOf(type.name());
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren