Skip to content

Commit

Permalink
Fix llama carpet decoration (GeyserMC#2125)
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy authored Apr 16, 2021
1 parent 6a88a46 commit beb7e54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.network.translators.item.ItemRegistry;

public class LlamaEntity extends ChestedHorseEntity {

Expand All @@ -52,16 +52,13 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
if (entityMetadata.getId() == 20) {
// Bedrock treats llama decoration as armor
MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket();
equipmentPacket.setRuntimeEntityId(getGeyserId());
equipmentPacket.setRuntimeEntityId(geyserId);
// -1 means no armor
if ((int) entityMetadata.getValue() != -1) {
// The damage value is the dye color that Java sends us
int carpetIndex = (int) entityMetadata.getValue();
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(ItemData.builder()
.id(BlockTranslator.CARPET)
.damage((int) entityMetadata.getValue())
.count(1)
.build());
equipmentPacket.setChestplate(ItemRegistry.CARPETS.get(carpetIndex));
} else {
equipmentPacket.setChestplate(ItemData.AIR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public class ItemRegistry {
* Bucket item entries (excluding the milk bucket), used in BedrockInventoryTransactionTranslator.java
*/
public static final IntSet BUCKETS = new IntArraySet();
/**
* Carpet item data, used in LlamaEntity.java
*/
public static final List<ItemData> CARPETS = new ArrayList<>(16);
/**
* Crossbow item entry, used in PillagerEntity.java
*/
Expand Down Expand Up @@ -452,6 +456,13 @@ public static void init() {
BOATS.add(entry.getValue().get("bedrock_id").intValue());
} else if (entry.getKey().contains("bucket") && !entry.getKey().contains("milk")) {
BUCKETS.add(entry.getValue().get("bedrock_id").intValue());
} else if (entry.getKey().contains("_carpet")) {
// This should be the numerical order Java sends as an integer value for llamas
CARPETS.add(ItemData.builder()
.id(itemEntry.getBedrockId())
.damage(itemEntry.getBedrockData())
.count(1)
.blockRuntimeId(itemEntry.getBedrockBlockId()).build());
}

itemNames.add(entry.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ public abstract class BlockTranslator {
private final Object2IntMap<NbtMap> itemFrames = new Object2IntOpenHashMap<>();
private final Map<String, NbtMap> flowerPotBlocks = new HashMap<>();

// Bedrock carpet ID, used in LlamaEntity.java for decoration
public static final int CARPET = 171;

public static final Int2DoubleMap JAVA_RUNTIME_ID_TO_HARDNESS = new Int2DoubleOpenHashMap();
public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND = new Int2BooleanOpenHashMap();
public static final Int2ObjectMap<String> JAVA_RUNTIME_ID_TO_TOOL_TYPE = new Int2ObjectOpenHashMap<>();
Expand Down

0 comments on commit beb7e54

Please sign in to comment.