Translate allay dancing

This commit is contained in:
Camotoy 2022-07-28 17:45:38 -04:00
parent c914938acb
commit 4163de9314
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
3 changed files with 28 additions and 2 deletions

View file

@ -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)

View file

@ -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();
}
}

View file

@ -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<String, ItemMapping> 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");