Fix llama carpets

This commit is contained in:
Camotoy 2024-04-23 16:08:26 -04:00
parent d105dadf62
commit abea0131e4
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
5 changed files with 2 additions and 40 deletions

View file

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

View file

@ -25,11 +25,8 @@
package org.geysermc.geyser.entity.type.living.animal.horse;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
import org.cloudburstmc.protocol.bedrock.packet.MobArmorEquipmentPacket;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.Item;
@ -45,30 +42,6 @@ public class LlamaEntity extends ChestedHorseEntity {
dirtyMetadata.put(EntityDataTypes.CONTAINER_STRENGTH_MODIFIER, 3); // Presumably 3 slots for every 1 strength
}
/**
* Color equipped on the llama
*/
public void setCarpetedColor(IntEntityMetadata entityMetadata) {
// Bedrock treats llama decoration as armor
MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket();
equipmentPacket.setRuntimeEntityId(geyserId);
// -1 means no armor
int carpetIndex = entityMetadata.getPrimitiveValue();
if (carpetIndex > -1 && carpetIndex <= 15) {
// The damage value is the dye color that Java sends us, for pre-1.16.220
// The item is always going to be a carpet
equipmentPacket.setChestplate(session.getItemMappings().getCarpets().get(carpetIndex));
} else {
equipmentPacket.setChestplate(ItemData.AIR);
}
// Required to fill out the rest of the equipment or Bedrock ignores it, including above else statement if removing armor
equipmentPacket.setBoots(ItemData.AIR);
equipmentPacket.setHelmet(ItemData.AIR);
equipmentPacket.setLeggings(ItemData.AIR);
session.sendUpstreamPacket(equipmentPacket);
}
@Override
public boolean canEat(Item item) {
return item == Items.WHEAT || item == Items.HAY_BLOCK;

View file

@ -159,7 +159,6 @@ public class ItemRegistryPopulator {
Object2ObjectMap<CustomBlockData, ItemDefinition> customBlockItemDefinitions = new Object2ObjectOpenHashMap<>();
List<ItemDefinition> buckets = new ObjectArrayList<>();
List<ItemData> carpets = new ObjectArrayList<>();
List<ItemMapping> mappings = new ObjectArrayList<>();
// Temporary mapping to create stored items
@ -458,14 +457,6 @@ public class ItemRegistryPopulator {
if (javaItem.javaIdentifier().contains("bucket") && !javaItem.javaIdentifier().contains("milk")) {
buckets.add(definition);
} else if (javaItem.javaIdentifier().contains("_carpet") && !javaItem.javaIdentifier().contains("moss")) {
// This should be the numerical order Java sends as an integer value for llamas
carpets.add(ItemData.builder()
.definition(definition)
.damage(mapping.getBedrockData())
.count(1)
.blockDefinition(mapping.getBedrockBlockDefinition())
.build());
} else if (javaItem.javaIdentifier().startsWith("minecraft:music_disc_")) {
// The Java record level event uses the item ID as the "key" to play the record
Registries.RECORDS.register(javaItem.javaId(), SoundEvent.valueOf("RECORD_" +
@ -589,7 +580,6 @@ public class ItemRegistryPopulator {
.storedItems(new StoredItemMappings(javaItemToMapping))
.javaOnlyItems(javaOnlyItems)
.buckets(buckets)
.carpets(carpets)
.componentItemData(componentItemData)
.lodestoneCompass(lodestoneEntry)
.customIdMappings(customIdMappings)

View file

@ -69,7 +69,6 @@ public class ItemMappings implements DefinitionRegistry<ItemDefinition> {
List<ItemDefinition> buckets;
List<ItemDefinition> boats;
List<ItemData> carpets;
List<ComponentItemData> componentItemData;
Int2ObjectMap<String> customIdMappings;

View file

@ -74,7 +74,8 @@ public class JavaSetEquipmentTranslator extends PacketTranslator<ClientboundSetE
livingEntity.setHelmet(item);
armorUpdated = true;
}
case CHESTPLATE -> {
case CHESTPLATE, BODY -> {
// BODY is sent for llamas with a carpet equipped, as of 1.20.5
livingEntity.setChestplate(item);
armorUpdated = true;
}