Calculate horse inventory size

This commit is contained in:
AJ Ferguson 2024-04-23 20:43:46 -04:00 committed by Camotoy
parent a1534e4535
commit 9490a091b5
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
3 changed files with 26 additions and 3 deletions

View file

@ -943,7 +943,7 @@ public final class EntityDefinitions {
LLAMA = EntityDefinition.inherited(LlamaEntity::new, chestedHorseEntityBase) LLAMA = EntityDefinition.inherited(LlamaEntity::new, chestedHorseEntityBase)
.type(EntityType.LLAMA) .type(EntityType.LLAMA)
.height(1.87f).width(0.9f) .height(1.87f).width(0.9f)
.addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.STRENGTH, entityMetadata.getValue())) .addTranslator(MetadataType.INT, LlamaEntity::setStrength)
.addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.VARIANT, entityMetadata.getValue())) .addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.VARIANT, entityMetadata.getValue()))
.build(); .build();
TRADER_LLAMA = EntityDefinition.inherited(TraderLlamaEntity::new, LLAMA) TRADER_LLAMA = EntityDefinition.inherited(TraderLlamaEntity::new, LLAMA)

View file

@ -25,16 +25,24 @@
package org.geysermc.geyser.entity.type.living.animal.horse; package org.geysermc.geyser.entity.type.living.animal.horse;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import lombok.Getter;
import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.MathUtils;
import java.util.UUID; import java.util.UUID;
public class LlamaEntity extends ChestedHorseEntity { public class LlamaEntity extends ChestedHorseEntity {
/**
* Used to calculate inventory size
*/
@Getter
private int strength = 1;
public LlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { public LlamaEntity(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); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
@ -42,6 +50,11 @@ public class LlamaEntity extends ChestedHorseEntity {
dirtyMetadata.put(EntityDataTypes.CONTAINER_STRENGTH_MODIFIER, 3); // Presumably 3 slots for every 1 strength dirtyMetadata.put(EntityDataTypes.CONTAINER_STRENGTH_MODIFIER, 3); // Presumably 3 slots for every 1 strength
} }
public void setStrength(IntEntityMetadata entityMetadata) {
strength = MathUtils.constrain(entityMetadata.getPrimitiveValue(), 1, 5);
this.dirtyMetadata.put(EntityDataTypes.STRENGTH, strength);
}
@Override @Override
public boolean canEat(Item item) { public boolean canEat(Item item) {
return item == Items.WHEAT || item == Items.HAY_BLOCK; return item == Items.WHEAT || item == Items.HAY_BLOCK;

View file

@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.Cli
import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.nbt.NbtType; import org.cloudburstmc.nbt.NbtType;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType;
import org.cloudburstmc.protocol.bedrock.packet.UpdateEquipPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateEquipPacket;
import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Entity;
@ -114,16 +115,25 @@ public class JavaHorseScreenOpenTranslator extends PacketTranslator<ClientboundH
// Since 1.20.5, the armor slot is not included in the container size, // Since 1.20.5, the armor slot is not included in the container size,
// but everything is still indexed the same. // but everything is still indexed the same.
int slotCount = packet.getNumberOfSlots() + 1; int slotCount = 2; // Don't depend on slot count sent from server
InventoryTranslator inventoryTranslator; InventoryTranslator inventoryTranslator;
if (entity instanceof LlamaEntity) { if (entity instanceof LlamaEntity llamaEntity) {
if (entity.getFlag(EntityFlag.CHESTED)) {
slotCount += llamaEntity.getStrength() * 3;
}
inventoryTranslator = new LlamaInventoryTranslator(slotCount); inventoryTranslator = new LlamaInventoryTranslator(slotCount);
slots.add(CARPET_SLOT); slots.add(CARPET_SLOT);
} else if (entity instanceof ChestedHorseEntity) { } else if (entity instanceof ChestedHorseEntity) {
if (entity.getFlag(EntityFlag.CHESTED)) {
slotCount += 15;
}
inventoryTranslator = new DonkeyInventoryTranslator(slotCount); inventoryTranslator = new DonkeyInventoryTranslator(slotCount);
slots.add(SADDLE_SLOT); slots.add(SADDLE_SLOT);
} else if (entity instanceof CamelEntity) { } else if (entity instanceof CamelEntity) {
if (entity.getFlag(EntityFlag.CHESTED)) {
slotCount += 15;
}
// The camel has an invisible armor slot and needs special handling, same as the donkey // The camel has an invisible armor slot and needs special handling, same as the donkey
inventoryTranslator = new DonkeyInventoryTranslator(slotCount); inventoryTranslator = new DonkeyInventoryTranslator(slotCount);
slots.add(SADDLE_SLOT); slots.add(SADDLE_SLOT);