Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix llama carpet decoration #2125

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -73,9 +73,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