From 4163de9314204079def6d6f519648386b0cf17bd Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Thu, 28 Jul 2022 17:45:38 -0400 Subject: [PATCH] Translate allay dancing --- .../geyser/entity/EntityDefinitions.java | 2 ++ .../entity/type/living/AllayEntity.java | 26 +++++++++++++++++-- .../inventory/item/StoredItemMappings.java | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index 52d9250ac..a552d0875 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -453,6 +453,8 @@ public final class EntityDefinitions { ALLAY = EntityDefinition.inherited(AllayEntity::new, mobEntityBase) .type(EntityType.ALLAY) .height(0.6f).width(0.35f) + .addTranslator(MetadataType.BOOLEAN, AllayEntity::setDancing) + .addTranslator(MetadataType.BOOLEAN, AllayEntity::setCanDuplicate) .build(); BAT = EntityDefinition.inherited(BatEntity::new, mobEntityBase) .type(EntityType.BAT) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java index ab444c4ab..d37a67938 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java @@ -25,8 +25,10 @@ package org.geysermc.geyser.entity.type.living; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; @@ -37,14 +39,27 @@ import javax.annotation.Nonnull; import java.util.UUID; public class AllayEntity extends MobEntity { + private boolean canDuplicate; + public AllayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } + public void setDancing(BooleanEntityMetadata entityMetadata) { + setFlag(EntityFlag.DANCING, entityMetadata.getPrimitiveValue()); + } + + public void setCanDuplicate(BooleanEntityMetadata entityMetadata) { + this.canDuplicate = entityMetadata.getPrimitiveValue(); + } + @Nonnull @Override protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { - if (!this.hand.isValid() && !itemInHand.isEmpty()) { + if (this.canDuplicate && getFlag(EntityFlag.DANCING) && isDuplicationItem(itemInHand)) { + // Maybe better as another tag? + return InteractiveTag.GIVE_ITEM_TO_ALLAY; + } else if (!this.hand.isValid() && !itemInHand.isEmpty()) { return InteractiveTag.GIVE_ITEM_TO_ALLAY; } else if (this.hand.isValid() && hand == Hand.MAIN_HAND && itemInHand.isEmpty()) { // Seems like there isn't a good tag for this yet @@ -57,7 +72,10 @@ public class AllayEntity extends MobEntity { @Nonnull @Override protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { - if (!this.hand.isValid() && !itemInHand.isEmpty()) { + if (this.canDuplicate && getFlag(EntityFlag.DANCING) && isDuplicationItem(itemInHand)) { + //TOCHECK sound + return InteractionResult.SUCCESS; + } else if (!this.hand.isValid() && !itemInHand.isEmpty()) { //TODO play sound? return InteractionResult.SUCCESS; } else if (this.hand.isValid() && hand == Hand.MAIN_HAND && itemInHand.isEmpty()) { @@ -67,4 +85,8 @@ public class AllayEntity extends MobEntity { return super.mobInteract(hand, itemInHand); } } + + private boolean isDuplicationItem(GeyserItemStack itemStack) { + return itemStack.getJavaId() == session.getItemMappings().getStoredItems().amethystShard(); + } } diff --git a/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java b/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java index 8f9eb415f..b50a9f7d5 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java @@ -38,6 +38,7 @@ import java.util.Map; @Getter @Accessors(fluent = true) public class StoredItemMappings { + private final int amethystShard; private final ItemMapping bamboo; private final ItemMapping banner; private final ItemMapping barrier; @@ -71,6 +72,7 @@ public class StoredItemMappings { private final ItemMapping writableBook; public StoredItemMappings(Map itemMappings) { + this.amethystShard = load(itemMappings, "amethyst_shard").getJavaId(); this.bamboo = load(itemMappings, "bamboo"); this.banner = load(itemMappings, "white_banner"); // As of 1.17.10, all banners have the same Bedrock ID this.barrier = load(itemMappings, "barrier");