From 40d1e3909301cbf9898fe2cbd45f24b3210f9b77 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 28 May 2021 16:35:54 -0400 Subject: [PATCH 1/3] Fix area effect cloud particle type for 1.16.220 (#2226) This commit stops hardcoded particle IDs from being used and instead uses the internal IDs per-version. --- connector/pom.xml | 2 +- .../entity/AreaEffectCloudEntity.java | 2 +- .../translators/effect/EffectRegistry.java | 24 +++++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index 9feb717b9..ba0f0cc39 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -32,7 +32,7 @@ com.github.CloudburstMC.Protocol bedrock-v431 - 9947665 + 530a0e3 compile diff --git a/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java b/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java index 6f3d0204f..2e450343e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java @@ -59,7 +59,7 @@ public class AreaEffectCloudEntity extends Entity { metadata.put(EntityData.EFFECT_COLOR, entityMetadata.getValue()); } else if (entityMetadata.getId() == 10) { Particle particle = (Particle) entityMetadata.getValue(); - int particleId = EffectRegistry.getParticleId(particle.getType()); + int particleId = EffectRegistry.getParticleId(session, particle.getType()); if (particleId != -1) { metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, particleId); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java index c71aa4f1d..f767b5827 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java @@ -32,10 +32,9 @@ import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.SoundEvent; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import lombok.NonNull; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.FileUtils; import java.io.InputStream; @@ -51,11 +50,6 @@ public class EffectRegistry { public static final Map SOUND_EFFECTS = new HashMap<>(); public static final Int2ObjectMap RECORDS = new Int2ObjectOpenHashMap<>(); - /** - * Java particle type to Bedrock particle ID - * Used for area effect clouds. - */ - private static final Object2IntMap PARTICLE_TO_ID = new Object2IntOpenHashMap<>(); /** * Java particle type to Bedrock level event */ @@ -84,11 +78,7 @@ public class EffectRegistry { while (particlesIterator.hasNext()) { Map.Entry entry = particlesIterator.next(); JsonNode bedrockId = entry.getValue().get("bedrockId"); - JsonNode bedrockIdNumeric = entry.getValue().get("bedrockNumericId"); JsonNode eventType = entry.getValue().get("eventType"); - if (bedrockIdNumeric != null) { - PARTICLE_TO_ID.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockIdNumeric.asInt()); - } if (bedrockId != null) { PARTICLE_TO_STRING.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockId.asText()); } @@ -164,11 +154,19 @@ public class EffectRegistry { } /** + * Used for area effect clouds. + * * @param type the Java particle to search for * @return the Bedrock integer ID of the particle, or -1 if it does not exist */ - public static int getParticleId(@NonNull ParticleType type) { - return PARTICLE_TO_ID.getOrDefault(type, -1); + public static int getParticleId(GeyserSession session, @NonNull ParticleType type) { + LevelEventType levelEventType = getParticleLevelEventType(type); + if (levelEventType == null) { + return -1; + } + + // Remove the legacy bit applied to particles for LevelEventType serialization + return session.getUpstream().getSession().getPacketCodec().getHelper().getLevelEventId(levelEventType) & ~0x4000; } /** From 08ba82a44e20eb82fe056e4961ac8102b8baf9dc Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 28 May 2021 20:38:17 -0400 Subject: [PATCH 2/3] GeyserOptionalPack support for zombie villager textures (#2237) Trade tier and profession now show on zombie villagers with this commit. --- .../living/merchant/VillagerEntity.java | 34 +++++++++---------- .../living/monster/ZombieVillagerEntity.java | 4 ++- connector/src/main/resources/mappings | 2 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java index fa5785fe5..be4228830 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java @@ -46,7 +46,7 @@ public class VillagerEntity extends AbstractMerchantEntity { /** * A map of Java profession IDs to Bedrock IDs */ - private static final Int2IntMap VILLAGER_VARIANTS = new Int2IntOpenHashMap(); + public static final Int2IntMap VILLAGER_PROFESSIONS = new Int2IntOpenHashMap(); /** * A map of all Java region IDs (plains, savanna...) to Bedrock */ @@ -54,21 +54,21 @@ public class VillagerEntity extends AbstractMerchantEntity { static { // Java villager profession IDs -> Bedrock - VILLAGER_VARIANTS.put(0, 0); - VILLAGER_VARIANTS.put(1, 8); - VILLAGER_VARIANTS.put(2, 11); - VILLAGER_VARIANTS.put(3, 6); - VILLAGER_VARIANTS.put(4, 7); - VILLAGER_VARIANTS.put(5, 1); - VILLAGER_VARIANTS.put(6, 2); - VILLAGER_VARIANTS.put(7, 4); - VILLAGER_VARIANTS.put(8, 12); - VILLAGER_VARIANTS.put(9, 5); - VILLAGER_VARIANTS.put(10, 13); - VILLAGER_VARIANTS.put(11, 14); - VILLAGER_VARIANTS.put(12, 3); - VILLAGER_VARIANTS.put(13, 10); - VILLAGER_VARIANTS.put(14, 9); + VILLAGER_PROFESSIONS.put(0, 0); + VILLAGER_PROFESSIONS.put(1, 8); + VILLAGER_PROFESSIONS.put(2, 11); + VILLAGER_PROFESSIONS.put(3, 6); + VILLAGER_PROFESSIONS.put(4, 7); + VILLAGER_PROFESSIONS.put(5, 1); + VILLAGER_PROFESSIONS.put(6, 2); + VILLAGER_PROFESSIONS.put(7, 4); + VILLAGER_PROFESSIONS.put(8, 12); + VILLAGER_PROFESSIONS.put(9, 5); + VILLAGER_PROFESSIONS.put(10, 13); + VILLAGER_PROFESSIONS.put(11, 14); + VILLAGER_PROFESSIONS.put(12, 3); + VILLAGER_PROFESSIONS.put(13, 10); + VILLAGER_PROFESSIONS.put(14, 9); VILLAGER_REGIONS.put(0, 1); VILLAGER_REGIONS.put(1, 2); @@ -88,7 +88,7 @@ public class VillagerEntity extends AbstractMerchantEntity { if (entityMetadata.getId() == 17) { VillagerData villagerData = (VillagerData) entityMetadata.getValue(); // Profession - metadata.put(EntityData.VARIANT, VILLAGER_VARIANTS.get(villagerData.getProfession())); + metadata.put(EntityData.VARIANT, VILLAGER_PROFESSIONS.get(villagerData.getProfession())); //metadata.put(EntityData.SKIN_ID, villagerData.getType()); Looks like this is modified but for any reason? // Region metadata.put(EntityData.MARK_VARIANT, VILLAGER_REGIONS.get(villagerData.getType())); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieVillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieVillagerEntity.java index c098fb5f6..c7fdc494a 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieVillagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/ZombieVillagerEntity.java @@ -48,8 +48,10 @@ public class ZombieVillagerEntity extends ZombieEntity { } if (entityMetadata.getId() == 19) { VillagerData villagerData = (VillagerData) entityMetadata.getValue(); - // Region - only one used on Bedrock + metadata.put(EntityData.VARIANT, VillagerEntity.VILLAGER_PROFESSIONS.get(villagerData.getProfession())); // Actually works properly with the OptionalPack metadata.put(EntityData.MARK_VARIANT, VillagerEntity.VILLAGER_REGIONS.get(villagerData.getType())); + // Used with the OptionalPack + metadata.put(EntityData.TRADE_TIER, villagerData.getLevel() - 1); } super.updateBedrockMetadata(entityMetadata, session); } diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index 53e13b7a0..c5925b01c 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 53e13b7a0d2ea14df71ed0c9582d29a9b4fb4453 +Subproject commit c5925b01cf8e7d8b284cf359e927145b9b4694aa From d80c31f1c25ca3c75ddf59c3f8e86d7242606c41 Mon Sep 17 00:00:00 2001 From: Dylan Ogle Date: Sat, 29 May 2021 14:37:03 +0100 Subject: [PATCH 3/3] Fix cats being larger than normal and implement resting (#2238) * Use the correct scale for cats. * Implement resting --- .../entity/living/animal/tameable/CatEntity.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 2d56d0c18..6869717a0 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -49,7 +49,14 @@ public class CatEntity extends TameableEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { super.updateBedrockMetadata(entityMetadata, session); - if (entityMetadata.getId() == 16) { + if (entityMetadata.getId() == 15) { + metadata.put(EntityData.SCALE, .8f); + boolean isBaby = (boolean) entityMetadata.getValue(); + if (isBaby) { + metadata.put(EntityData.SCALE, .4f); + metadata.getFlags().setFlag(EntityFlag.BABY, true); + } + } else if (entityMetadata.getId() == 16) { // Update collar color if tamed if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { metadata.put(EntityData.COLOR, collarColor); @@ -76,6 +83,9 @@ public class CatEntity extends TameableEntity { } metadata.put(EntityData.VARIANT, variantColor); } + if (entityMetadata.getId() == 19) { + metadata.getFlags().setFlag(EntityFlag.RESTING, (boolean) entityMetadata.getValue()); + } if (entityMetadata.getId() == 21) { collarColor = (byte) (int) entityMetadata.getValue(); // Needed or else wild cats are a red color