From cd17dc5f4cbbbafa559194ad8dbfcbc00c5e0252 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 30 Nov 2019 13:26:51 -0600 Subject: [PATCH 01/12] Use FastUtil over Trove for maps/collections to reduce memory usage This should significantly decrease the amount of RAM being used by Geyser. Previously it was using 300mb - 400mb on average. This has dropped it down to 80mb - 120mb. Ideally I'd like to decrease this value further, but that will require some more work. --- .../org/geysermc/connector/entity/Entity.java | 4 +++- .../network/session/cache/EntityCache.java | 18 ++++++++++-------- .../network/session/cache/WindowCache.java | 4 +++- .../translators/item/ItemTranslator.java | 2 +- .../org/geysermc/connector/utils/Toolbox.java | 8 ++++---- .../connector/world/chunk/BlockStorage.java | 18 +++++++++--------- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index ba9fe4ab3..15100f13b 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -34,6 +34,8 @@ import com.nukkitx.protocol.bedrock.data.EntityDataDictionary; import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.EntityFlags; import com.nukkitx.protocol.bedrock.packet.*; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; import lombok.Getter; import lombok.Setter; import org.geysermc.connector.console.GeyserLogger; @@ -69,7 +71,7 @@ public class Entity { protected boolean valid; - protected Set passengers = new HashSet<>(); + protected LongSet passengers = new LongOpenHashSet(); protected Map attributes = new HashMap<>(); protected EntityDataDictionary metadata = new EntityDataDictionary(); diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java index 80b965007..fd0bd7c5a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java @@ -25,6 +25,10 @@ package org.geysermc.connector.network.session.cache; +import it.unimi.dsi.fastutil.longs.Long2LongMap; +import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import lombok.Getter; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.PlayerEntity; @@ -41,8 +45,8 @@ public class EntityCache { private GeyserSession session; @Getter - private Map entities = new HashMap<>(); - private Map entityIdTranslations = new HashMap<>(); + private Long2ObjectMap entities = new Long2ObjectOpenHashMap<>(); + private Long2LongMap entityIdTranslations = new Long2LongOpenHashMap(); private Map playerEntities = new HashMap<>(); private Map bossbars = new HashMap<>(); @@ -62,12 +66,10 @@ public class EntityCache { public boolean removeEntity(Entity entity, boolean force) { if (entity != null && entity.isValid() && (force || entity.despawnEntity(session))) { - Long geyserId = entityIdTranslations.remove(entity.getEntityId()); - if (geyserId != null) { - entities.remove(geyserId); - if (entity.is(PlayerEntity.class)) { - playerEntities.remove(entity.as(PlayerEntity.class).getUuid()); - } + long geyserId = entityIdTranslations.remove(entity.getEntityId()); + entities.remove(geyserId); + if (entity.is(PlayerEntity.class)) { + playerEntities.remove(entity.as(PlayerEntity.class).getUuid()); } return true; } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java index fc7de6144..5d21c55ca 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java @@ -26,6 +26,8 @@ package org.geysermc.connector.network.session.cache; import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.Getter; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.api.window.FormWindow; @@ -38,7 +40,7 @@ public class WindowCache { private GeyserSession session; @Getter - private Map windows = new HashMap(); + private Int2ObjectMap windows = new Int2ObjectOpenHashMap<>(); public WindowCache(GeyserSession session) { this.session = session; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index b8d56ccff..204210598 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -79,7 +79,7 @@ public class ItemTranslator { } public ItemEntry getItem(ItemData data) { - for (ItemEntry itemEntry : Toolbox.ITEM_ENTRIES.valueCollection()) { + for (ItemEntry itemEntry : Toolbox.ITEM_ENTRIES.values()) { if (itemEntry.getBedrockId() == data.getId() && itemEntry.getBedrockData() == data.getDamage()) { return itemEntry; } diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index 849ecc568..74a1be96f 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -7,8 +7,8 @@ import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.tag.ListTag; import com.nukkitx.protocol.bedrock.packet.StartGamePacket; -import gnu.trove.map.TIntObjectMap; -import gnu.trove.map.hash.TIntObjectHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.network.translators.block.BlockEntry; @@ -23,8 +23,8 @@ public class Toolbox { public static final Collection ITEMS = new ArrayList<>(); public static ListTag BLOCKS; - public static final TIntObjectMap ITEM_ENTRIES = new TIntObjectHashMap<>(); - public static final TIntObjectMap BLOCK_ENTRIES = new TIntObjectHashMap<>(); + public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); + public static final Int2ObjectMap BLOCK_ENTRIES = new Int2ObjectOpenHashMap<>(); public static void init() { InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat"); diff --git a/connector/src/main/java/org/geysermc/connector/world/chunk/BlockStorage.java b/connector/src/main/java/org/geysermc/connector/world/chunk/BlockStorage.java index db38d4bb0..dbb967d4e 100644 --- a/connector/src/main/java/org/geysermc/connector/world/chunk/BlockStorage.java +++ b/connector/src/main/java/org/geysermc/connector/world/chunk/BlockStorage.java @@ -1,12 +1,15 @@ package org.geysermc.connector.world.chunk; import com.nukkitx.network.VarInts; -import gnu.trove.list.array.TIntArrayList; import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import org.geysermc.connector.world.GlobalBlockPalette; import org.geysermc.connector.world.chunk.bitarray.BitArray; import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion; +import java.util.function.IntConsumer; + /** * Adapted from NukkitX: https://github.com/NukkitX/Nukkit */ @@ -14,7 +17,7 @@ public class BlockStorage { private static final int SIZE = 4096; - private final TIntArrayList palette; + private final IntList palette; private BitArray bitArray; public BlockStorage() { @@ -23,11 +26,11 @@ public class BlockStorage { public BlockStorage(BitArrayVersion version) { this.bitArray = version.createPalette(SIZE); - this.palette = new TIntArrayList(16, -1); + this.palette = new IntArrayList(16); this.palette.add(0); // Air is at the start of every palette. } - private BlockStorage(BitArray bitArray, TIntArrayList palette) { + private BlockStorage(BitArray bitArray, IntArrayList palette) { this.palette = palette; this.bitArray = bitArray; } @@ -57,10 +60,7 @@ public class BlockStorage { } VarInts.writeInt(buffer, palette.size()); - palette.forEach(id -> { - VarInts.writeInt(buffer, id); - return true; - }); + palette.forEach((IntConsumer) id -> VarInts.writeInt(buffer, id)); } private void onResize(BitArrayVersion version) { @@ -109,6 +109,6 @@ public class BlockStorage { } public BlockStorage copy() { - return new BlockStorage(this.bitArray.copy(), new TIntArrayList(this.palette)); + return new BlockStorage(this.bitArray.copy(), new IntArrayList(this.palette)); } } \ No newline at end of file From 2c10274fc3df22217d454c124d3f71b4a7915122 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 30 Nov 2019 18:19:03 -0600 Subject: [PATCH 02/12] Break entities into separate classes and add equipment translator This should make the process of translating entity metadata a whole lot easier and more organized. Future features involving entities and checking if they're capable of doing certain things should also be much easier now. --- .../connector/entity/ArrowEntity.java | 36 +++ .../org/geysermc/connector/entity/Entity.java | 8 +- .../entity/ItemedFireballEntity.java | 36 +++ .../connector/entity/LivingEntity.java | 82 +++++++ .../connector/entity/MinecartEntity.java | 36 +++ .../connector/entity/PlayerEntity.java | 24 +- .../connector/entity/ThrowableEntity.java | 36 +++ .../entity/living/AbstractFishEntity.java | 36 +++ .../entity/living/AbstractHorseEntity.java | 48 ++++ .../entity/living/AbstractIllagerEntity.java | 36 +++ .../entity/living/AbstractMerchantEntity.java | 36 +++ .../entity/living/AbstractSkeletonEntity.java | 36 +++ .../entity/living/AgeableEntity.java | 48 ++++ .../entity/living/AmbientEntity.java | 36 +++ .../connector/entity/living/AnimalEntity.java | 36 +++ .../entity/living/ChestedHorseEntity.java | 47 ++++ .../entity/living/CreatureEntity.java | 36 +++ .../connector/entity/living/FlyingEntity.java | 36 +++ .../connector/entity/living/GolemEntity.java | 36 +++ .../entity/living/InsentientEntity.java | 51 ++++ .../entity/living/MonsterEntity.java | 36 +++ .../entity/living/RaidParticipantEntity.java | 36 +++ .../living/SpellcasterIllagerEntity.java | 36 +++ .../entity/living/TameableEntity.java | 36 +++ .../connector/entity/living/WaterEntity.java | 36 +++ .../entity/living/monster/GuardianEntity.java | 53 ++++ .../entity/living/monster/ZombieEntity.java | 37 +++ .../connector/entity/type/EntityType.java | 226 +++++++++--------- .../network/translators/TranslatorsInit.java | 1 + .../entity/JavaEntityEquipmentTranslator.java | 79 ++++++ .../entity/spawn/JavaSpawnMobTranslator.java | 19 +- .../spawn/JavaSpawnObjectTranslator.java | 26 +- 32 files changed, 1245 insertions(+), 152 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/ArrowEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/ItemedFireballEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/ThrowableEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/AbstractFishEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/AbstractHorseEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/AbstractIllagerEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/AbstractMerchantEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/AbstractSkeletonEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/AgeableEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/AmbientEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/AnimalEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/ChestedHorseEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/CreatureEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/FlyingEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/GolemEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/InsentientEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/MonsterEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/RaidParticipantEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/SpellcasterIllagerEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/TameableEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/WaterEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/monster/GuardianEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/ArrowEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ArrowEntity.java new file mode 100644 index 000000000..1c70a1429 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/ArrowEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class ArrowEntity extends Entity { + + public ArrowEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 15100f13b..e348e1aa7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -64,7 +64,7 @@ public class Entity { */ protected Vector3f rotation; - protected int scale = 1; + protected float scale = 1; protected boolean movePending; protected EntityType entityType; @@ -178,7 +178,11 @@ public class Entity { metadata.getFlags().setFlag(EntityFlag.SPRINTING, (xd & 0x08) == 0x08); metadata.getFlags().setFlag(EntityFlag.SWIMMING, (xd & 0x10) == 0x10); metadata.getFlags().setFlag(EntityFlag.GLIDING, (xd & 0x80) == 0x80); - metadata.getFlags().setFlag(EntityFlag.INVISIBLE, (xd & 0x20) == 0x20); + // metadata.getFlags().setFlag(EntityFlag.INVISIBLE, (xd & 0x20) == 0x20); + if ((xd & 0x20) == 0x20) + metadata.put(EntityData.SCALE, 0.01f); + else + metadata.put(EntityData.SCALE, scale); } break; case 2: // custom name diff --git a/connector/src/main/java/org/geysermc/connector/entity/ItemedFireballEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ItemedFireballEntity.java new file mode 100644 index 000000000..f3008c12c --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/ItemedFireballEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class ItemedFireballEntity extends Entity { + + public ItemedFireballEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java new file mode 100644 index 000000000..052e9e98b --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.ItemData; +import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; +import lombok.Getter; +import lombok.Setter; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +@Getter +@Setter +public class LivingEntity extends Entity { + + protected ItemData helmet; + protected ItemData chestplate; + protected ItemData leggings; + protected ItemData boots; + protected ItemData hand = ItemData.of(0, (short) 0, 0); + + public LivingEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + switch (entityMetadata.getId()) { + case 8: + metadata.put(EntityData.HEALTH, (float) entityMetadata.getValue()); + break; + case 9: + metadata.put(EntityData.POTION_COLOR, (int) entityMetadata.getValue()); + break; + case 10: + // metadata.put(EntityData.POTION_AMBIENT, (boolean) entityMetadata.getValue()); + break; + } + + super.updateBedrockMetadata(entityMetadata, session); + } + + public void updateEquipment(GeyserSession session) { + if (!valid) + return; + + MobArmorEquipmentPacket armorEquipmentPacket = new MobArmorEquipmentPacket(); + armorEquipmentPacket.setRuntimeEntityId(geyserId); + armorEquipmentPacket.setHelmet(helmet); + armorEquipmentPacket.setChestplate(chestplate); + armorEquipmentPacket.setLeggings(leggings); + armorEquipmentPacket.setBoots(boots); + + session.getUpstream().sendPacket(armorEquipmentPacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java new file mode 100644 index 000000000..4d4fab4dc --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class MinecartEntity extends Entity { + + public MinecartEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java index 67393114c..afcc45052 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -27,9 +27,7 @@ package org.geysermc.connector.entity; import com.github.steveice10.mc.auth.data.GameProfile; import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; -import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import lombok.Getter; import lombok.Setter; @@ -41,19 +39,13 @@ import org.geysermc.connector.utils.SkinUtils; import java.util.UUID; @Getter @Setter -public class PlayerEntity extends Entity { +public class PlayerEntity extends LivingEntity { private GameProfile profile; private UUID uuid; private String username; private long lastSkinUpdate = -1; private boolean playerList = true; - private ItemData helmet; - private ItemData chestplate; - private ItemData leggings; - private ItemData boots; - private ItemData hand = ItemData.of(0, (short) 0, 0); - public PlayerEntity(GameProfile gameProfile, long entityId, long geyserId, Vector3f position, Vector3f motion, Vector3f rotation) { super(entityId, geyserId, EntityType.PLAYER, position, motion, rotation); @@ -63,20 +55,6 @@ public class PlayerEntity extends Entity { if (geyserId == 1) valid = true; } - // TODO: Break this into an EquippableEntity class - public void updateEquipment(GeyserSession session) { - if (!valid) return; - - MobArmorEquipmentPacket armorEquipmentPacket = new MobArmorEquipmentPacket(); - armorEquipmentPacket.setRuntimeEntityId(geyserId); - armorEquipmentPacket.setHelmet(helmet); - armorEquipmentPacket.setChestplate(chestplate); - armorEquipmentPacket.setLeggings(leggings); - armorEquipmentPacket.setBoots(boots); - - session.getUpstream().sendPacket(armorEquipmentPacket); - } - @Override public boolean despawnEntity(GeyserSession session) { super.despawnEntity(session); diff --git a/connector/src/main/java/org/geysermc/connector/entity/ThrowableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ThrowableEntity.java new file mode 100644 index 000000000..c395beba4 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/ThrowableEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class ThrowableEntity extends Entity { + + public ThrowableEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractFishEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractFishEntity.java new file mode 100644 index 000000000..db06ce1af --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractFishEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class AbstractFishEntity extends WaterEntity { + + public AbstractFishEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractHorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractHorseEntity.java new file mode 100644 index 000000000..c5ac8d2cc --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractHorseEntity.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class AbstractHorseEntity extends AnimalEntity { + + public AbstractHorseEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 17) { + metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + } + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractIllagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractIllagerEntity.java new file mode 100644 index 000000000..04b699d0a --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractIllagerEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class AbstractIllagerEntity extends RaidParticipantEntity { + + public AbstractIllagerEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractMerchantEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractMerchantEntity.java new file mode 100644 index 000000000..9ae0b600c --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractMerchantEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class AbstractMerchantEntity extends AgeableEntity { + + public AbstractMerchantEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractSkeletonEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractSkeletonEntity.java new file mode 100644 index 000000000..ed3d96fe7 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractSkeletonEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class AbstractSkeletonEntity extends MonsterEntity { + + public AbstractSkeletonEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AgeableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AgeableEntity.java new file mode 100644 index 000000000..926cfde38 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AgeableEntity.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class AgeableEntity extends CreatureEntity { + + public AgeableEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 14) { + metadata.getFlags().setFlag(EntityFlag.BABY, (boolean) entityMetadata.getValue()); + } + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AmbientEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AmbientEntity.java new file mode 100644 index 000000000..d3cbdbb59 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AmbientEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class AmbientEntity extends InsentientEntity { + + public AmbientEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AnimalEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AnimalEntity.java new file mode 100644 index 000000000..9ce560520 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AnimalEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class AnimalEntity extends AgeableEntity { + + public AnimalEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/ChestedHorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/ChestedHorseEntity.java new file mode 100644 index 000000000..a7eb65216 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/ChestedHorseEntity.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class ChestedHorseEntity extends AbstractHorseEntity { + + public ChestedHorseEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + // https://wiki.vg/Entity_metadata#Horse + metadata.getFlags().setFlag(EntityFlag.CHESTED, chestplate != null && chestplate.getId() != 0); + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/CreatureEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/CreatureEntity.java new file mode 100644 index 000000000..5d4c45ca5 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/CreatureEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class CreatureEntity extends InsentientEntity { + + public CreatureEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/FlyingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/FlyingEntity.java new file mode 100644 index 000000000..166d35707 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/FlyingEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class FlyingEntity extends InsentientEntity { + + public FlyingEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/GolemEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/GolemEntity.java new file mode 100644 index 000000000..da7b27125 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/GolemEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class GolemEntity extends CreatureEntity { + + public GolemEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/InsentientEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/InsentientEntity.java new file mode 100644 index 000000000..121174312 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/InsentientEntity.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.LivingEntity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class InsentientEntity extends LivingEntity { + + public InsentientEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 13 && entityMetadata.getType() == MetadataType.BYTE) { + byte xd = (byte) entityMetadata.getValue(); + metadata.getFlags().setFlag(EntityFlag.NO_AI, (xd & 0x01) == 0x01); + } + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/MonsterEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/MonsterEntity.java new file mode 100644 index 000000000..dd0dbc816 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/MonsterEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class MonsterEntity extends CreatureEntity { + + public MonsterEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/RaidParticipantEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/RaidParticipantEntity.java new file mode 100644 index 000000000..b64d55461 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/RaidParticipantEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class RaidParticipantEntity extends MonsterEntity { + + public RaidParticipantEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/SpellcasterIllagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/SpellcasterIllagerEntity.java new file mode 100644 index 000000000..1b7e16e7a --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/SpellcasterIllagerEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class SpellcasterIllagerEntity extends AbstractIllagerEntity { + + public SpellcasterIllagerEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/TameableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/TameableEntity.java new file mode 100644 index 000000000..8fd6496c2 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/TameableEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class TameableEntity extends AnimalEntity { + + public TameableEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/WaterEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/WaterEntity.java new file mode 100644 index 000000000..fe66036b5 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/WaterEntity.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.type.EntityType; + +public class WaterEntity extends CreatureEntity { + + public WaterEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/GuardianEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/GuardianEntity.java new file mode 100644 index 000000000..af6a18327 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/GuardianEntity.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living.monster; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.living.MonsterEntity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class GuardianEntity extends MonsterEntity { + + public GuardianEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 15) { + Entity entity = session.getEntityCache().getEntityByJavaId((int) entityMetadata.getValue()); + if (entity != null) { + metadata.put(EntityData.TARGET_EID, entity.getGeyserId()); + } + } + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieEntity.java new file mode 100644 index 000000000..162c2272f --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieEntity.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living.monster; + +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.living.MonsterEntity; +import org.geysermc.connector.entity.type.EntityType; + +public class ZombieEntity extends MonsterEntity { + + public ZombieEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index d3286c8d5..37ee1b0a9 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -26,137 +26,143 @@ package org.geysermc.connector.entity.type; import lombok.Getter; +import org.geysermc.connector.entity.*; +import org.geysermc.connector.entity.living.*; +import org.geysermc.connector.entity.living.monster.GuardianEntity; +import org.geysermc.connector.entity.living.monster.ZombieEntity; @Getter public enum EntityType { - CHICKEN(10, 0.7f, 0.4f), - COW(11, 1.4f, 0.9f), - PIG(12, 0.9f), - SHEEP(13, 1.3f, 0.9f), - WOLF(14, 0.85f, 0.6f), - VILLAGER(15, 1.8f, 0.6f, 0.6f, 1.62f), - MOOSHROOM(16, 1.4f, 0.9f), - SQUID(17, 0.8f), - RABBIT(18, 0.5f, 0.4f), - BAT(19, 0.9f, 0.5f), - IRON_GOLEM(20, 2.7f, 1.4f), - SNOW_GOLEM(21, 1.9f, 0.7f), - OCELOT(22, 0.35f, 0.3f), - HORSE(23, 1.6f, 1.3965f), - DONKEY(24, 1.6f, 1.3965f), - MULE(25, 1.6f, 1.3965f), - SKELETON_HORSE(26, 1.6f, 1.3965f), - ZOMBIE_HORSE(27, 1.6f, 1.3965f), - POLAR_BEAR(28, 1.4f, 1.3f), - LLAMA(29, 1.87f, 0.9f), - PARROT(30, 0.9f, 0.5f), - DOLPHIN(31, 0.6f, 0.9f), - ZOMBIE(32, 1.8f, 0.6f, 0.6f, 1.62f), - CREEPER(33, 1.7f, 0.6f, 0.6f, 1.62f), - SKELETON(34, 1.8f, 0.6f, 0.6f, 1.62f), - SPIDER(35, 0.9f, 1.4f, 1.4f, 1f), - ZOMBIE_PIGMAN(36, 1.8f, 0.6f, 0.6f, 1.62f), - SLIME(37, 0.51f), - ENDERMAN(38, 2.9f, 0.6f), - SILVERFISH(39, 0.3f, 0.4f), - CAVE_SPIDER(40, 0.5f, 0.7f), - GHAST(41, 4.0f), - MAGMA_CUBE(42, 0.51f), - BLAZE(43, 1.8f, 0.6f), - ZOMBIE_VILLAGER(44, 1.8f, 0.6f, 0.6f, 1.62f), - WITCH(45, 1.8f, 0.6f, 0.6f, 1.62f), - STRAY(46, 1.8f, 0.6f, 0.6f, 1.62f), - HUSK(47, 1.8f, 0.6f, 0.6f, 1.62f), - WITHER_SKELETON(48, 2.4f, 0.7f), - GUARDIAN(49, 0.85f), - ELDER_GUARDIAN(50, 1.9975f), - NPC(51, 1.8f, 0.6f, 0.6f, 1.62f), - WITHER(52, 3.5f, 0.9f), - ENDER_DRAGON(53, 4f, 13f), - SHULKER(54, 1f, 1f), - ENDERMITE(55, 0.3f, 0.4f), - AGENT(56, 0f), - VINDICATOR(57, 1.8f, 0.6f, 0.6f, 1.62f), - PILLAGER(114, 1.8f, 0.6f, 0.6f, 1.62f), - WANDERING_TRADER(118, 1.8f, 0.6f, 0.6f, 1.62f), - PHANTOM(58, 0.5f, 0.9f, 0.9f, 0.6f), - RAVAGER(59, 1.9f, 1.2f), + CHICKEN(AnimalEntity.class, 10, 0.7f, 0.4f), + COW(AnimalEntity.class, 11, 1.4f, 0.9f), + PIG(AnimalEntity.class, 12, 0.9f), + SHEEP(AnimalEntity.class, 13, 1.3f, 0.9f), + WOLF(AnimalEntity.class, 14, 0.85f, 0.6f), + VILLAGER(AbstractMerchantEntity.class, 15, 1.8f, 0.6f, 0.6f, 1.62f), + MOOSHROOM(AnimalEntity.class, 16, 1.4f, 0.9f), + SQUID(WaterEntity.class, 17, 0.8f), + RABBIT(AnimalEntity.class, 18, 0.5f, 0.4f), + BAT(AmbientEntity.class, 19, 0.9f, 0.5f), + IRON_GOLEM(GolemEntity.class, 20, 2.7f, 1.4f), + SNOW_GOLEM(GolemEntity.class, 21, 1.9f, 0.7f), + OCELOT(TameableEntity.class, 22, 0.35f, 0.3f), + HORSE(AbstractHorseEntity.class, 23, 1.6f, 1.3965f), + DONKEY(ChestedHorseEntity.class, 24, 1.6f, 1.3965f), + MULE(ChestedHorseEntity.class, 25, 1.6f, 1.3965f), + SKELETON_HORSE(AbstractHorseEntity.class, 26, 1.6f, 1.3965f), + ZOMBIE_HORSE(AbstractHorseEntity.class, 27, 1.6f, 1.3965f), + POLAR_BEAR(AnimalEntity.class, 28, 1.4f, 1.3f), + LLAMA(ChestedHorseEntity.class, 29, 1.87f, 0.9f), + PARROT(TameableEntity.class, 30, 0.9f, 0.5f), + DOLPHIN(WaterEntity.class, 31, 0.6f, 0.9f), + ZOMBIE(ZombieEntity.class, 32, 1.8f, 0.6f, 0.6f, 1.62f), + CREEPER(MonsterEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f), + SKELETON(AbstractSkeletonEntity.class, 34, 1.8f, 0.6f, 0.6f, 1.62f), + SPIDER(MonsterEntity.class, 35, 0.9f, 1.4f, 1.4f, 1f), + ZOMBIE_PIGMAN(MonsterEntity.class, 36, 1.8f, 0.6f, 0.6f, 1.62f), + SLIME(InsentientEntity.class, 37, 0.51f), + ENDERMAN(MonsterEntity.class, 38, 2.9f, 0.6f), + SILVERFISH(MonsterEntity.class, 39, 0.3f, 0.4f), + CAVE_SPIDER(MonsterEntity.class, 40, 0.5f, 0.7f), + GHAST(FlyingEntity.class, 41, 4.0f), + MAGMA_CUBE(InsentientEntity.class, 42, 0.51f), + BLAZE(MonsterEntity.class, 43, 1.8f, 0.6f), + ZOMBIE_VILLAGER(ZombieEntity.class, 44, 1.8f, 0.6f, 0.6f, 1.62f), + WITCH(RaidParticipantEntity.class, 45, 1.8f, 0.6f, 0.6f, 1.62f), + STRAY(AbstractSkeletonEntity.class, 46, 1.8f, 0.6f, 0.6f, 1.62f), + HUSK(ZombieEntity.class, 47, 1.8f, 0.6f, 0.6f, 1.62f), + WITHER_SKELETON(AbstractSkeletonEntity.class, 48, 2.4f, 0.7f), + GUARDIAN(MonsterEntity.class, 49, 0.85f), + ELDER_GUARDIAN(GuardianEntity.class, 50, 1.9975f), + NPC(PlayerEntity.class, 51, 1.8f, 0.6f, 0.6f, 1.62f), + WITHER(MonsterEntity.class, 52, 3.5f, 0.9f), + ENDER_DRAGON(InsentientEntity.class, 53, 4f, 13f), + SHULKER(GolemEntity.class, 54, 1f, 1f), + ENDERMITE(MonsterEntity.class, 55, 0.3f, 0.4f), + AGENT(Entity.class, 56, 0f), + VINDICATOR(AbstractIllagerEntity.class, 57, 1.8f, 0.6f, 0.6f, 1.62f), + PILLAGER(AbstractIllagerEntity.class, 114, 1.8f, 0.6f, 0.6f, 1.62f), + WANDERING_TRADER(AbstractMerchantEntity.class, 118, 1.8f, 0.6f, 0.6f, 1.62f), + PHANTOM(FlyingEntity.class, 58, 0.5f, 0.9f, 0.9f, 0.6f), + RAVAGER(RaidParticipantEntity.class, 59, 1.9f, 1.2f), - ARMOR_STAND(61, 0f), - TRIPOD_CAMERA(62, 0f), - PLAYER(63, 1.8f, 0.6f, 0.6f, 1.62f), - ITEM(64, 0.25f, 0.25f), - TNT(65, 0.98f, 0.98f), - FALLING_BLOCK(66, 0.98f, 0.98f), - MOVING_BLOCK(67, 0f), - EXPERIENCE_BOTTLE(68, 0.25f, 0.25f), - EXPERIENCE_ORB(69, 0f), - EYE_OF_ENDER(70, 0f), - END_CRYSTAL(71, 0f), - FIREWORK_ROCKET(72, 0f), - TRIDENT(73, 0f), - TURTLE(74, 0.4f, 1.2f), + ARMOR_STAND(LivingEntity.class, 61, 0f), + 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(Entity.class, 65, 0.98f, 0.98f), + FALLING_BLOCK(Entity.class, 66, 0.98f, 0.98f), + MOVING_BLOCK(Entity.class, 67, 0f), + EXPERIENCE_BOTTLE(ThrowableEntity.class, 68, 0.25f, 0.25f), + EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f), + EYE_OF_ENDER(Entity.class, 70, 0f), + END_CRYSTAL(Entity.class, 71, 0f), + FIREWORK_ROCKET(Entity.class, 72, 0f), + TRIDENT(ArrowEntity.class, 73, 0f), + TURTLE(AnimalEntity.class, 74, 0.4f, 1.2f), // TODO CAT (need to figure out how to deal with baby cats) https://github.com/NukkitX/Nukkit/blob/master/src/main/java/cn/nukkit/entity/passive/EntityCat.java - SHULKER_BULLET(76, 0f), - FISHING_BOBBER(77, 0f), - CHALKBOARD(78, 0f), - DRAGON_FIREBALL(79, 0f), - ARROW(80, 0.25f, 0.25f), - SNOWBALL(81, 0f), - EGG(82, 0f), - PAINTING(83, 0f), - MINECART(84, 0f), - FIREBALL(85, 0f), - SPLASH_POTION(86, 0f), - ENDER_PEARL(87, 0f), - LEASH_KNOT(88, 0f), - WITHER_SKULL(89, 0f), - BOAT(90, 0.7f, 1.6f, 1.6f, 0.35f), - WITHER_SKULL_DANGEROUS(91, 0f), - LIGHTNING_BOLT(93, 0f), - SMALL_FIREBALL(94, 0f), - AREA_EFFECT_CLOUD(95, 0f), - HOPPER_MINECART(96, 0f), - TNT_MINECART(97, 0f), - CHEST_MINECART(98, 0f), + SHULKER_BULLET(Entity.class, 76, 0f), + FISHING_BOBBER(Entity.class, 77, 0f), + CHALKBOARD(Entity.class, 78, 0f), + DRAGON_FIREBALL(ItemedFireballEntity.class, 79, 0f), + ARROW(ArrowEntity.class, 80, 0.25f, 0.25f), + SNOWBALL(ThrowableEntity.class, 81, 0f), + EGG(ThrowableEntity.class, 82, 0f), + PAINTING(PaintingEntity.class, 83, 0f), + MINECART(MinecartEntity.class, 84, 0f), + FIREBALL(ItemedFireballEntity.class, 85, 0f), + SPLASH_POTION(ThrowableEntity.class, 86, 0f), + ENDER_PEARL(ThrowableEntity.class, 87, 0f), + LEASH_KNOT(Entity.class, 88, 0f), + WITHER_SKULL(Entity.class, 89, 0f), + BOAT(Entity.class, 90, 0.7f, 1.6f, 1.6f, 0.35f), + WITHER_SKULL_DANGEROUS(Entity.class, 91, 0f), + LIGHTNING_BOLT(Entity.class, 93, 0f), + SMALL_FIREBALL(ItemedFireballEntity.class, 94, 0f), + AREA_EFFECT_CLOUD(Entity.class, 95, 0f), + HOPPER_MINECART(MinecartEntity.class, 96, 0f), + TNT_MINECART(MinecartEntity.class, 97, 0f), + CHEST_MINECART(MinecartEntity.class, 98, 0f), - COMMAND_BLOCK_MINECART(100, 0f), - LINGERING_POTION(101, 0f), - LLAMA_SPIT(102, 0f), - EVOKER_FANGS(103, 0f), - EVOKER(104, 0f), - VEX(105, 0f), - ICE_BOMB(106, 0f), - BALLOON(107, 0f), //TODO - PUFFERFISH(108, 0.7f, 0.7f), - SALMON(109, 0.5f, 0.7f), - DROWNED(110, 1.95f, 0.6f), - TROPICAL_FISH(111, 0.6f, 0.6f), - COD(112, 0.25f, 0.5f), - PANDA(113, 1.25f, 1.125f, 1.825f), - FOX(121, 0.5f, 1.25f); + COMMAND_BLOCK_MINECART(MinecartEntity.class, 100, 0f), + LINGERING_POTION(ThrowableEntity.class, 101, 0f), + LLAMA_SPIT(Entity.class, 102, 0f), + EVOKER_FANGS(Entity.class, 103, 0f), + EVOKER(SpellcasterIllagerEntity.class, 104, 0f), + VEX(MonsterEntity.class, 105, 0f), + ICE_BOMB(Entity.class, 106, 0f), + BALLOON(Entity.class, 107, 0f), //TODO + PUFFERFISH(AbstractFishEntity.class, 108, 0.7f, 0.7f), + SALMON(AbstractFishEntity.class, 109, 0.5f, 0.7f), + DROWNED(ZombieEntity.class, 110, 1.95f, 0.6f), + TROPICAL_FISH(AbstractFishEntity.class, 111, 0.6f, 0.6f), + COD(AbstractFishEntity.class, 112, 0.25f, 0.5f), + PANDA(AnimalEntity.class, 113, 1.25f, 1.125f, 1.825f), + FOX(AnimalEntity.class, 121, 0.5f, 1.25f); + private Class entityClass; private final int type; private final float height; private final float width; private final float length; private final float offset; - EntityType(int type, float height) { - this(type, height, 0f); + EntityType(Class entityClass, int type, float height) { + this(entityClass, type, height, 0f); } - EntityType(int type, float height, float width) { - this(type, height, width, width); + EntityType(Class entityClass, int type, float height, float width) { + this(entityClass, type, height, width, width); } - EntityType(int type, float height, float width, float length) { - this(type, height, width, length, 0f); + EntityType(Class entityClass, int type, float height, float width, float length) { + this(entityClass, type, height, width, length, 0f); } - EntityType(int type, float height, float width, float length, float offset) { + EntityType(Class entityClass, int type, float height, float width, float length, float offset) { + this.entityClass = entityClass; this.type = type; this.height = height; this.width = width; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index 4f6e21e76..a19de3f29 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -112,6 +112,7 @@ public class TranslatorsInit { Registry.registerJava(ServerEntityHeadLookPacket.class, new JavaEntityHeadLookTranslator()); Registry.registerJava(ServerEntityMetadataPacket.class, new JavaEntityMetadataTranslator()); Registry.registerJava(ServerEntityStatusPacket.class, new JavaEntityStatusTranslator()); + Registry.registerJava(ServerEntityEquipmentPacket.class, new JavaEntityEquipmentTranslator()); Registry.registerJava(ServerBossBarPacket.class, new JavaBossBarTranslator()); Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java new file mode 100644 index 000000000..8197b8a6d --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.network.translators.java.entity; + +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEquipmentPacket; +import com.nukkitx.protocol.bedrock.data.ItemData; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.LivingEntity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.TranslatorsInit; + +public class JavaEntityEquipmentTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityEquipmentPacket packet, GeyserSession session) { + Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); + if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { + entity = session.getPlayerEntity(); + } + + if (entity == null) + return; + + if (!(entity instanceof LivingEntity)) { + session.getConnector().getLogger().debug("Attempted to add armor to a non-living entity type (" + + entity.getEntityType().name() + ")."); + return; + } + + LivingEntity livingEntity = (LivingEntity) entity; + ItemData item = TranslatorsInit.getItemTranslator().translateToBedrock(packet.getItem()); + switch (packet.getSlot()) { + case HELMET: + livingEntity.setHelmet(item); + break; + case CHESTPLATE: + livingEntity.setChestplate(item); + break; + case LEGGINGS: + livingEntity.setLeggings(item); + break; + case BOOTS: + livingEntity.setBoots(item); + break; + case MAIN_HAND: + livingEntity.setHand(item); + break; + case OFF_HAND: + // TODO: livingEntity.setOffHand(item); + break; + } + + livingEntity.updateEquipment(session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java index e5c68ecaf..352d8b748 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java @@ -34,6 +34,9 @@ import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.utils.EntityUtils; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + public class JavaSpawnMobTranslator extends PacketTranslator { @Override @@ -48,11 +51,17 @@ public class JavaSpawnMobTranslator extends PacketTranslator entityClass = type.getEntityClass(); + try { + Constructor entityConstructor = entityClass.getConstructor(long.class, long.class, EntityType.class, + Vector3f.class, Vector3f.class, Vector3f.class); - session.getEntityCache().spawnEntity(entity); + Entity entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + type, position, motion, rotation + ); + session.getEntityCache().spawnEntity(entity); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { + ex.printStackTrace(); + } } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java index 57571bed4..a2c0c6538 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java @@ -30,12 +30,14 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.Serve import com.nukkitx.math.vector.Vector3f; import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.entity.Entity; -import org.geysermc.connector.entity.ItemEntity; 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.utils.EntityUtils; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + public class JavaSpawnObjectTranslator extends PacketTranslator { @Override @@ -53,17 +55,17 @@ public class JavaSpawnObjectTranslator extends PacketTranslator entityClass = type.getEntityClass(); + try { + Constructor entityConstructor = entityClass.getConstructor(long.class, long.class, EntityType.class, + Vector3f.class, Vector3f.class, Vector3f.class); - session.getEntityCache().spawnEntity(entity); + Entity entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + type, position, motion, rotation + ); + session.getEntityCache().spawnEntity(entity); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { + ex.printStackTrace(); + } } } From 37a77441736ce66bce6621ceaaf3c2b386bb3868 Mon Sep 17 00:00:00 2001 From: Redned Date: Sat, 30 Nov 2019 20:56:39 -0600 Subject: [PATCH 03/12] Include submodules in pull request build action --- .github/workflows/pullrequest.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index bea51a6e6..bf5972f2f 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -19,6 +19,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 1.8 + - name: submodules-init + uses: snickerbockers/submodules-init@v4 - name: Build with Maven run: mvn -B package - name: Archive artifacts From fe6b0e8afa9d7bd48f30fdbeb34b65b5df054900 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 3 Dec 2019 18:43:52 -0600 Subject: [PATCH 04/12] Update mappings submodule --- connector/src/main/resources/mappings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index 5ec6f1f33..3d4147f00 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 5ec6f1f339506129514de59d0e09e9b2c612e8be +Subproject commit 3d4147f001266d01eae6b8479428ca77bb5bf0c3 From 83d943e426adffbf9980df1d69fb3f8538247e11 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 3 Dec 2019 18:49:13 -0600 Subject: [PATCH 05/12] Only set variant for actual horses (Fixes #99) --- .../entity/living/AbstractHorseEntity.java | 4 -- .../entity/living/horse/HorseEntity.java | 49 +++++++++++++++++++ .../connector/entity/type/EntityType.java | 3 +- 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/horse/HorseEntity.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractHorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractHorseEntity.java index c5ac8d2cc..7b71d0409 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractHorseEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/AbstractHorseEntity.java @@ -39,10 +39,6 @@ public class AbstractHorseEntity extends AnimalEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { - if (entityMetadata.getId() == 17) { - metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); - } - super.updateBedrockMetadata(entityMetadata, session); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/horse/HorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/horse/HorseEntity.java new file mode 100644 index 000000000..3ad0b1145 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/horse/HorseEntity.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.entity.living.horse; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import org.geysermc.connector.entity.living.AbstractHorseEntity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class HorseEntity extends AbstractHorseEntity { + + public HorseEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 17) { + metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + } + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 37ee1b0a9..dab04a1d1 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -28,6 +28,7 @@ package org.geysermc.connector.entity.type; import lombok.Getter; import org.geysermc.connector.entity.*; import org.geysermc.connector.entity.living.*; +import org.geysermc.connector.entity.living.horse.HorseEntity; import org.geysermc.connector.entity.living.monster.GuardianEntity; import org.geysermc.connector.entity.living.monster.ZombieEntity; @@ -47,7 +48,7 @@ public enum EntityType { IRON_GOLEM(GolemEntity.class, 20, 2.7f, 1.4f), SNOW_GOLEM(GolemEntity.class, 21, 1.9f, 0.7f), OCELOT(TameableEntity.class, 22, 0.35f, 0.3f), - HORSE(AbstractHorseEntity.class, 23, 1.6f, 1.3965f), + HORSE(HorseEntity.class, 23, 1.6f, 1.3965f), DONKEY(ChestedHorseEntity.class, 24, 1.6f, 1.3965f), MULE(ChestedHorseEntity.class, 25, 1.6f, 1.3965f), SKELETON_HORSE(AbstractHorseEntity.class, 26, 1.6f, 1.3965f), From 8389cab95cb2f087303f5db2d25c434ef8475bfc Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Wed, 4 Dec 2019 18:02:27 +0000 Subject: [PATCH 06/12] Bump Protocol Lib to 1.4.1 --- connector/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/pom.xml b/connector/pom.xml index 60ecfc557..70f74df47 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -74,7 +74,7 @@ com.nukkitx.protocol bedrock-v388 - 2.4.0 + 2.4.1 compile From 6e8a0847b402beceb0b237b1d9bb215652986eea Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Wed, 4 Dec 2019 18:13:49 +0000 Subject: [PATCH 07/12] Fix typo from protocol lib --- .../connector/network/session/GeyserSession.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 8f4544d39..8fedc583a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -44,13 +44,7 @@ import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; import com.nukkitx.protocol.bedrock.data.GameRule; -import com.nukkitx.protocol.bedrock.packet.AvailableEntityIdentifiersPacket; -import com.nukkitx.protocol.bedrock.packet.BiomeDefinitionListPacket; -import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; -import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; -import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; -import com.nukkitx.protocol.bedrock.packet.StartGamePacket; -import com.nukkitx.protocol.bedrock.packet.TextPacket; +import com.nukkitx.protocol.bedrock.packet.*; import lombok.Getter; import lombok.Setter; import org.geysermc.api.Player; @@ -295,7 +289,7 @@ public class GeyserSession implements Player { startGamePacket.setLevelGamemode(0); startGamePacket.setDifficulty(1); startGamePacket.setDefaultSpawn(Vector3i.ZERO); - startGamePacket.setAcheivementsDisabled(true); + startGamePacket.setAchievementsDisabled(true); startGamePacket.setTime(-1); startGamePacket.setEduEditionOffers(0); startGamePacket.setEduFeaturesEnabled(false); From 855a25389441719641b6c05be6f37218fcaad8f0 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 4 Dec 2019 22:41:56 -0600 Subject: [PATCH 08/12] Add cat entity --- .../java/org/geysermc/connector/entity/type/EntityType.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index dab04a1d1..73c484104 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -102,8 +102,7 @@ public enum EntityType { FIREWORK_ROCKET(Entity.class, 72, 0f), TRIDENT(ArrowEntity.class, 73, 0f), TURTLE(AnimalEntity.class, 74, 0.4f, 1.2f), - // TODO CAT (need to figure out how to deal with baby cats) https://github.com/NukkitX/Nukkit/blob/master/src/main/java/cn/nukkit/entity/passive/EntityCat.java - + CAT(TameableEntity.class, 75, 0.35f, 0.3f), SHULKER_BULLET(Entity.class, 76, 0f), FISHING_BOBBER(Entity.class, 77, 0f), CHALKBOARD(Entity.class, 78, 0f), From a639d141e75f9388c90089c0bcfd02f25b1ab7f4 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Thu, 5 Dec 2019 14:32:39 +0000 Subject: [PATCH 09/12] Bump Protocol lib to 2.4.2 --- connector/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/pom.xml b/connector/pom.xml index 70f74df47..1674eb649 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -74,7 +74,7 @@ com.nukkitx.protocol bedrock-v388 - 2.4.1 + 2.4.2 compile From fd95b8b36a4de83f8c239dc727bc1eca3d473a82 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 5 Dec 2019 21:54:29 -0900 Subject: [PATCH 10/12] Slightly improve movement A lot more work is needed to fix movement. --- .../translators/bedrock/BedrockMovePlayerTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java index 678956d7c..d07e922d4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java @@ -64,7 +64,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator Date: Fri, 6 Dec 2019 11:02:31 +0000 Subject: [PATCH 11/12] General pom cleanup. --- api/pom.xml | 6 --- common/pom.xml | 46 ------------------- connector/pom.xml | 13 +----- .../geysermc/connector/utils/SkinUtils.java | 4 +- pom.xml | 37 ++++----------- 5 files changed, 13 insertions(+), 93 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index a0cbdf87f..6d4e1c856 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -10,12 +10,6 @@ api - - org.projectlombok - lombok - 1.18.4 - compile - com.google.code.gson gson diff --git a/common/pom.xml b/common/pom.xml index 6a0a6ff04..cd96ad23a 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -9,50 +9,4 @@ 1.0-SNAPSHOT common - - - com.github.steveice10 - opennbt - 1.3-SNAPSHOT - compile - - - com.github.steveice10 - packetlib - 1.4-SNAPSHOT - compile - - - com.github.steveice10 - mcauthlib - 1.1-SNAPSHOT - compile - - - com.github.steveice10 - mcprotocollib - 1.14.4-SNAPSHOT - compile - - - com.github.steveice10 - opennbt - - - com.github.steveice10 - packetlib - - - com.github.steveice10 - mcauthlib - - - - - com.auth0 - java-jwt - 3.3.0 - compile - - \ No newline at end of file diff --git a/connector/pom.xml b/connector/pom.xml index 70f74df47..d03c2ec12 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -44,7 +44,6 @@ net.minecrell terminalconsoleappender 1.0.0 - jar compile @@ -59,12 +58,6 @@ 1.6.4 compile - - org.projectlombok - lombok - 1.18.4 - provided - org.fusesource.jansi jansi @@ -129,7 +122,7 @@ - ${outputName}-noshade + ${project.parent.name} ../target @@ -146,9 +139,6 @@ org.apache.maven.plugins maven-javadoc-plugin - - ${outputName} - org.apache.maven.plugins @@ -162,7 +152,6 @@ - ${outputName} true true diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java index b4c9d7f63..91910c961 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java @@ -7,12 +7,12 @@ import com.nukkitx.protocol.bedrock.data.SerializedSkin; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import lombok.AllArgsConstructor; import lombok.Getter; -import org.apache.commons.codec.Charsets; import org.geysermc.api.Geyser; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; +import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Collections; import java.util.UUID; @@ -80,7 +80,7 @@ public class SkinUtils { try { GameProfile.Property skinProperty = profile.getProperty("textures"); - JsonObject skinObject = SkinProvider.GSON.fromJson(new String(Base64.getDecoder().decode(skinProperty.getValue()), Charsets.UTF_8), JsonObject.class); + JsonObject skinObject = SkinProvider.GSON.fromJson(new String(Base64.getDecoder().decode(skinProperty.getValue()), StandardCharsets.UTF_8), JsonObject.class); JsonObject textures = skinObject.getAsJsonObject("textures"); JsonObject skinTexture = textures.getAsJsonObject("SKIN"); diff --git a/pom.xml b/pom.xml index 79b7b5a1a..2f394b5a9 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ geyser-parent 1.0-SNAPSHOT pom - GeyserMC + Geyser Allows for players from Minecraft Bedrock Edition to join Minecraft Java Edition servers. https://geysermc.org @@ -83,33 +83,16 @@ + + + org.projectlombok + lombok + 1.18.4 + provided + + + clean install - - - src/main/resources/ - false - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.0 - - false - true - - - From 9c21bcc9e8dfc90f32bc777bbd92df7c688aa031 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Fri, 6 Dec 2019 11:08:25 +0000 Subject: [PATCH 12/12] Add back target fixes. --- connector/pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/connector/pom.xml b/connector/pom.xml index d03c2ec12..eec15583a 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -122,7 +122,7 @@ - ${project.parent.name} + ${project.parent.name}-noshade ../target @@ -139,6 +139,9 @@ org.apache.maven.plugins maven-javadoc-plugin + + ${project.parent.name} + org.apache.maven.plugins @@ -152,6 +155,7 @@ + ${project.parent.name} true true