Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-09-08 20:43:04 +02:00
Fix banners on entity heads (#2110)
On Bedrock, a banner must be placed in the chestplate slot in order to be visible. On Java Edition, banners are placed in the helmet slot. This commit fixes the issue by migrating banners to the chestplate spot if the chestplate spot is empty. This commit also fixes pillager poses if they're not holding a crossbow, along with a couple other optimizations.
Dieser Commit ist enthalten in:
Ursprung
e762448957
Commit
7a7cf18e99
@ -113,9 +113,28 @@ public class LivingEntity extends Entity {
|
|||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateEquipment(GeyserSession session) {
|
public void updateAllEquipment(GeyserSession session) {
|
||||||
if (!valid)
|
if (!valid) return;
|
||||||
return;
|
|
||||||
|
updateArmor(session);
|
||||||
|
updateMainHand(session);
|
||||||
|
updateOffHand(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateArmor(GeyserSession session) {
|
||||||
|
if (!valid) return;
|
||||||
|
|
||||||
|
ItemData helmet = this.helmet;
|
||||||
|
ItemData chestplate = this.chestplate;
|
||||||
|
// If an entity has a banner on them, it will be in the helmet slot in Java but the chestplate spot in Bedrock
|
||||||
|
// But don't overwrite the chestplate if it isn't empty
|
||||||
|
if (chestplate.getId() == ItemData.AIR.getId() && helmet.getId() == ItemRegistry.BANNER.getBedrockId()) {
|
||||||
|
chestplate = this.helmet;
|
||||||
|
helmet = ItemData.AIR;
|
||||||
|
} else if (chestplate.getId() == ItemRegistry.BANNER.getBedrockId()) {
|
||||||
|
// Prevent chestplate banners from showing erroneously
|
||||||
|
chestplate = ItemData.AIR;
|
||||||
|
}
|
||||||
|
|
||||||
MobArmorEquipmentPacket armorEquipmentPacket = new MobArmorEquipmentPacket();
|
MobArmorEquipmentPacket armorEquipmentPacket = new MobArmorEquipmentPacket();
|
||||||
armorEquipmentPacket.setRuntimeEntityId(geyserId);
|
armorEquipmentPacket.setRuntimeEntityId(geyserId);
|
||||||
@ -124,6 +143,12 @@ public class LivingEntity extends Entity {
|
|||||||
armorEquipmentPacket.setLeggings(leggings);
|
armorEquipmentPacket.setLeggings(leggings);
|
||||||
armorEquipmentPacket.setBoots(boots);
|
armorEquipmentPacket.setBoots(boots);
|
||||||
|
|
||||||
|
session.sendUpstreamPacket(armorEquipmentPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateMainHand(GeyserSession session) {
|
||||||
|
if (!valid) return;
|
||||||
|
|
||||||
MobEquipmentPacket handPacket = new MobEquipmentPacket();
|
MobEquipmentPacket handPacket = new MobEquipmentPacket();
|
||||||
handPacket.setRuntimeEntityId(geyserId);
|
handPacket.setRuntimeEntityId(geyserId);
|
||||||
handPacket.setItem(hand);
|
handPacket.setItem(hand);
|
||||||
@ -131,6 +156,12 @@ public class LivingEntity extends Entity {
|
|||||||
handPacket.setInventorySlot(0);
|
handPacket.setInventorySlot(0);
|
||||||
handPacket.setContainerId(ContainerId.INVENTORY);
|
handPacket.setContainerId(ContainerId.INVENTORY);
|
||||||
|
|
||||||
|
session.sendUpstreamPacket(handPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateOffHand(GeyserSession session) {
|
||||||
|
if (!valid) return;
|
||||||
|
|
||||||
MobEquipmentPacket offHandPacket = new MobEquipmentPacket();
|
MobEquipmentPacket offHandPacket = new MobEquipmentPacket();
|
||||||
offHandPacket.setRuntimeEntityId(geyserId);
|
offHandPacket.setRuntimeEntityId(geyserId);
|
||||||
offHandPacket.setItem(offHand);
|
offHandPacket.setItem(offHand);
|
||||||
@ -138,8 +169,6 @@ public class LivingEntity extends Entity {
|
|||||||
offHandPacket.setInventorySlot(0);
|
offHandPacket.setInventorySlot(0);
|
||||||
offHandPacket.setContainerId(ContainerId.OFFHAND);
|
offHandPacket.setContainerId(ContainerId.OFFHAND);
|
||||||
|
|
||||||
session.sendUpstreamPacket(armorEquipmentPacket);
|
|
||||||
session.sendUpstreamPacket(handPacket);
|
|
||||||
session.sendUpstreamPacket(offHandPacket);
|
session.sendUpstreamPacket(offHandPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,11 +59,13 @@ public class PiglinEntity extends BasePiglinEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEquipment(GeyserSession session) {
|
public void updateOffHand(GeyserSession session) {
|
||||||
// Check if the Piglin is holding Gold and set the ADMIRING flag accordingly
|
// Check if the Piglin is holding Gold and set the ADMIRING flag accordingly so its pose updates
|
||||||
metadata.getFlags().setFlag(EntityFlag.ADMIRING, offHand.getId() == ItemRegistry.GOLD.getBedrockId());
|
boolean changed = metadata.getFlags().setFlag(EntityFlag.ADMIRING, offHand.getId() == ItemRegistry.GOLD.getBedrockId());
|
||||||
super.updateBedrockMetadata(session);
|
if (changed) {
|
||||||
|
super.updateBedrockMetadata(session);
|
||||||
|
}
|
||||||
|
|
||||||
super.updateEquipment(session);
|
super.updateOffHand(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.entity.living.monster.raid;
|
package org.geysermc.connector.entity.living.monster.raid;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||||
|
|
||||||
public class PillagerEntity extends AbstractIllagerEntity {
|
public class PillagerEntity extends AbstractIllagerEntity {
|
||||||
|
|
||||||
@ -38,12 +38,30 @@ public class PillagerEntity extends AbstractIllagerEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateMainHand(GeyserSession session) {
|
||||||
if (entityMetadata.getId() == 16) {
|
checkForCrossbow(session);
|
||||||
// Java Edition always has the Pillager entity as positioning the crossbow
|
|
||||||
metadata.getFlags().setFlag(EntityFlag.USING_ITEM, true);
|
super.updateMainHand(session);
|
||||||
metadata.getFlags().setFlag(EntityFlag.CHARGED, true);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOffHand(GeyserSession session) {
|
||||||
|
checkForCrossbow(session);
|
||||||
|
|
||||||
|
super.updateOffHand(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for a crossbow in either the mainhand or offhand. If one exists, indicate that the pillager should be posing
|
||||||
|
*/
|
||||||
|
protected void checkForCrossbow(GeyserSession session) {
|
||||||
|
boolean hasCrossbow = this.hand.getId() == ItemRegistry.CROSSBOW.getBedrockId()
|
||||||
|
|| this.offHand.getId() == ItemRegistry.CROSSBOW.getBedrockId();
|
||||||
|
boolean usingItemChanged = metadata.getFlags().setFlag(EntityFlag.USING_ITEM, hasCrossbow);
|
||||||
|
boolean chargedChanged = metadata.getFlags().setFlag(EntityFlag.CHARGED, hasCrossbow);
|
||||||
|
|
||||||
|
if (usingItemChanged || chargedChanged) {
|
||||||
|
updateBedrockMetadata(session);
|
||||||
}
|
}
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ public class PlayerEntity extends LivingEntity {
|
|||||||
valid = true;
|
valid = true;
|
||||||
session.sendUpstreamPacket(addPlayerPacket);
|
session.sendUpstreamPacket(addPlayerPacket);
|
||||||
|
|
||||||
updateEquipment(session);
|
updateAllEquipment(session);
|
||||||
updateBedrockAttributes(session);
|
updateBedrockAttributes(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public class SkullPlayerEntity extends PlayerEntity {
|
|||||||
valid = true;
|
valid = true;
|
||||||
session.sendUpstreamPacket(addPlayerPacket);
|
session.sendUpstreamPacket(addPlayerPacket);
|
||||||
|
|
||||||
updateEquipment(session);
|
updateAllEquipment(session);
|
||||||
updateBedrockAttributes(session);
|
updateBedrockAttributes(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
|||||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArraySet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
@ -79,14 +79,22 @@ public class ItemRegistry {
|
|||||||
* Bamboo item entry, used in PandaEntity.java
|
* Bamboo item entry, used in PandaEntity.java
|
||||||
*/
|
*/
|
||||||
public static ItemEntry BAMBOO;
|
public static ItemEntry BAMBOO;
|
||||||
|
/**
|
||||||
|
* Banner item entry, used in LivingEntity.java
|
||||||
|
*/
|
||||||
|
public static ItemEntry BANNER;
|
||||||
/**
|
/**
|
||||||
* Boat item entries, used in BedrockInventoryTransactionTranslator.java
|
* Boat item entries, used in BedrockInventoryTransactionTranslator.java
|
||||||
*/
|
*/
|
||||||
public static IntList BOATS = new IntArrayList();
|
public static final IntSet BOATS = new IntArraySet();
|
||||||
/**
|
/**
|
||||||
* Bucket item entries (excluding the milk bucket), used in BedrockInventoryTransactionTranslator.java
|
* Bucket item entries (excluding the milk bucket), used in BedrockInventoryTransactionTranslator.java
|
||||||
*/
|
*/
|
||||||
public static IntList BUCKETS = new IntArrayList();
|
public static final IntSet BUCKETS = new IntArraySet();
|
||||||
|
/**
|
||||||
|
* Crossbow item entry, used in PillagerEntity.java
|
||||||
|
*/
|
||||||
|
public static ItemEntry CROSSBOW;
|
||||||
/**
|
/**
|
||||||
* Empty item bucket, used in BedrockInventoryTransactionTranslator.java
|
* Empty item bucket, used in BedrockInventoryTransactionTranslator.java
|
||||||
*/
|
*/
|
||||||
@ -305,6 +313,9 @@ public class ItemRegistry {
|
|||||||
case "minecraft:bamboo":
|
case "minecraft:bamboo":
|
||||||
BAMBOO = itemEntry;
|
BAMBOO = itemEntry;
|
||||||
break;
|
break;
|
||||||
|
case "minecraft:crossbow":
|
||||||
|
CROSSBOW = itemEntry;
|
||||||
|
break;
|
||||||
case "minecraft:egg":
|
case "minecraft:egg":
|
||||||
EGG = itemEntry;
|
EGG = itemEntry;
|
||||||
break;
|
break;
|
||||||
@ -320,6 +331,9 @@ public class ItemRegistry {
|
|||||||
case "minecraft:wheat":
|
case "minecraft:wheat":
|
||||||
WHEAT = itemEntry;
|
WHEAT = itemEntry;
|
||||||
break;
|
break;
|
||||||
|
case "minecraft:white_banner": // As of 1.16.220, all banners share the same Bedrock ID and differ their colors through their damage value
|
||||||
|
BANNER = itemEntry;
|
||||||
|
break;
|
||||||
case "minecraft:writable_book":
|
case "minecraft:writable_book":
|
||||||
WRITABLE_BOOK = itemEntry;
|
WRITABLE_BOOK = itemEntry;
|
||||||
break;
|
break;
|
||||||
|
@ -40,9 +40,11 @@ public class JavaEntityEquipmentTranslator extends PacketTranslator<ServerEntity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerEntityEquipmentPacket packet, GeyserSession session) {
|
public void translate(ServerEntityEquipmentPacket packet, GeyserSession session) {
|
||||||
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
|
Entity entity;
|
||||||
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
|
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
|
||||||
entity = session.getPlayerEntity();
|
entity = session.getPlayerEntity();
|
||||||
|
} else {
|
||||||
|
entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
@ -54,30 +56,48 @@ public class JavaEntityEquipmentTranslator extends PacketTranslator<ServerEntity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean armorUpdated = false;
|
||||||
|
boolean mainHandUpdated = false;
|
||||||
|
boolean offHandUpdated = false;
|
||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
LivingEntity livingEntity = (LivingEntity) entity;
|
||||||
for (Equipment equipment : packet.getEquipment()) {
|
for (Equipment equipment : packet.getEquipment()) {
|
||||||
ItemData item = ItemTranslator.translateToBedrock(session, equipment.getItem());
|
ItemData item = ItemTranslator.translateToBedrock(session, equipment.getItem());
|
||||||
switch (equipment.getSlot()) {
|
switch (equipment.getSlot()) {
|
||||||
case HELMET:
|
case HELMET:
|
||||||
livingEntity.setHelmet(item);
|
livingEntity.setHelmet(item);
|
||||||
|
armorUpdated = true;
|
||||||
break;
|
break;
|
||||||
case CHESTPLATE:
|
case CHESTPLATE:
|
||||||
livingEntity.setChestplate(item);
|
livingEntity.setChestplate(item);
|
||||||
|
armorUpdated = true;
|
||||||
break;
|
break;
|
||||||
case LEGGINGS:
|
case LEGGINGS:
|
||||||
livingEntity.setLeggings(item);
|
livingEntity.setLeggings(item);
|
||||||
|
armorUpdated = true;
|
||||||
break;
|
break;
|
||||||
case BOOTS:
|
case BOOTS:
|
||||||
livingEntity.setBoots(item);
|
livingEntity.setBoots(item);
|
||||||
|
armorUpdated = true;
|
||||||
break;
|
break;
|
||||||
case MAIN_HAND:
|
case MAIN_HAND:
|
||||||
livingEntity.setHand(item);
|
livingEntity.setHand(item);
|
||||||
|
mainHandUpdated = true;
|
||||||
break;
|
break;
|
||||||
case OFF_HAND:
|
case OFF_HAND:
|
||||||
livingEntity.setOffHand(item);
|
livingEntity.setOffHand(item);
|
||||||
|
offHandUpdated = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
livingEntity.updateEquipment(session);
|
|
||||||
|
if (armorUpdated) {
|
||||||
|
livingEntity.updateArmor(session);
|
||||||
|
}
|
||||||
|
if (mainHandUpdated) {
|
||||||
|
livingEntity.updateMainHand(session);
|
||||||
|
}
|
||||||
|
if (offHandUpdated) {
|
||||||
|
livingEntity.updateOffHand(session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren