Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 08:30:12 +01:00
Strider mounting fixes; update mappings
This commit refactors health visual logic to make it a global system for each living entity.
Dieser Commit ist enthalten in:
Ursprung
eb3bde15a7
Commit
ba6adc988b
@ -27,15 +27,23 @@ package org.geysermc.connector.entity;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
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.AttributeData;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
|
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket;
|
import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.geysermc.connector.entity.attribute.AttributeType;
|
||||||
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.utils.AttributeUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -98,4 +106,34 @@ public class LivingEntity extends Entity {
|
|||||||
session.sendUpstreamPacket(handPacket);
|
session.sendUpstreamPacket(handPacket);
|
||||||
session.sendUpstreamPacket(offHandPacket);
|
session.sendUpstreamPacket(offHandPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBedrockAttributes(GeyserSession session) {
|
||||||
|
if (!valid) return;
|
||||||
|
|
||||||
|
float maxHealth = this.attributes.containsKey(AttributeType.MAX_HEALTH) ? this.attributes.get(AttributeType.MAX_HEALTH).getValue() : getDefaultMaxHealth();
|
||||||
|
|
||||||
|
List<AttributeData> attributes = new ArrayList<>();
|
||||||
|
for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) {
|
||||||
|
if (!entry.getValue().getType().isBedrockAttribute())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
attributes.add(AttributeUtils.getBedrockAttribute(entry.getValue()));
|
||||||
|
}
|
||||||
|
// Add health attribute to properly show hearts when mounting
|
||||||
|
attributes.add(new AttributeData("minecraft:health", 0.0f, maxHealth, metadata.getFloat(EntityData.HEALTH, 20f), maxHealth));
|
||||||
|
|
||||||
|
UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket();
|
||||||
|
updateAttributesPacket.setRuntimeEntityId(geyserId);
|
||||||
|
updateAttributesPacket.setAttributes(attributes);
|
||||||
|
session.sendUpstreamPacket(updateAttributesPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for the health visual when mounting an entity.
|
||||||
|
* @return the default maximum health for the entity.
|
||||||
|
*/
|
||||||
|
protected float getDefaultMaxHealth() {
|
||||||
|
return 20f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,33 +27,18 @@ package org.geysermc.connector.entity.living.animal;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
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.AttributeData;
|
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||||
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
|
|
||||||
import org.geysermc.connector.entity.attribute.AttributeType;
|
|
||||||
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.utils.AttributeUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class PigEntity extends AnimalEntity {
|
public class PigEntity extends AnimalEntity {
|
||||||
|
|
||||||
// For updating the pig heart visual easier
|
|
||||||
private float health = 20f;
|
|
||||||
|
|
||||||
public PigEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public PigEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
super(entityId, geyserId, entityType, position, motion, rotation);
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
if (entityMetadata.getId() == 8) {
|
|
||||||
health = (float) entityMetadata.getValue();
|
|
||||||
updateBedrockAttributes(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entityMetadata.getId() == 16) {
|
if (entityMetadata.getId() == 16) {
|
||||||
metadata.getFlags().setFlag(EntityFlag.SADDLED, (boolean) entityMetadata.getValue());
|
metadata.getFlags().setFlag(EntityFlag.SADDLED, (boolean) entityMetadata.getValue());
|
||||||
@ -62,23 +47,7 @@ public class PigEntity extends AnimalEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateBedrockAttributes(GeyserSession session) {
|
protected float getDefaultMaxHealth() {
|
||||||
if (!valid) return;
|
return 10f;
|
||||||
|
|
||||||
float maxHealth = attributes.containsKey(AttributeType.MAX_HEALTH) ? attributes.get(AttributeType.MAX_HEALTH).getValue() : 20f;
|
|
||||||
|
|
||||||
List<AttributeData> attributesLocal = new ArrayList<>();
|
|
||||||
for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) {
|
|
||||||
if (!entry.getValue().getType().isBedrockAttribute())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
attributesLocal.add(AttributeUtils.getBedrockAttribute(entry.getValue()));
|
|
||||||
}
|
|
||||||
attributesLocal.add(new AttributeData("minecraft:health", 0.0f, maxHealth, health, maxHealth));
|
|
||||||
|
|
||||||
UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket();
|
|
||||||
updateAttributesPacket.setRuntimeEntityId(geyserId);
|
|
||||||
updateAttributesPacket.setAttributes(attributesLocal);
|
|
||||||
session.sendUpstreamPacket(updateAttributesPacket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,24 +27,13 @@ package org.geysermc.connector.entity.living.animal.horse;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
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.AttributeData;
|
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||||
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
|
|
||||||
import org.geysermc.connector.entity.attribute.AttributeType;
|
|
||||||
import org.geysermc.connector.entity.living.animal.AnimalEntity;
|
import org.geysermc.connector.entity.living.animal.AnimalEntity;
|
||||||
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.utils.AttributeUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class AbstractHorseEntity extends AnimalEntity {
|
public class AbstractHorseEntity extends AnimalEntity {
|
||||||
|
|
||||||
// For updating the horse visual easier
|
|
||||||
private float health = 20f;
|
|
||||||
|
|
||||||
public AbstractHorseEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public AbstractHorseEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
super(entityId, geyserId, entityType, position, motion, rotation);
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
}
|
}
|
||||||
@ -52,11 +41,6 @@ public class AbstractHorseEntity extends AnimalEntity {
|
|||||||
@Override
|
@Override
|
||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
|
|
||||||
if (entityMetadata.getId() == 8) {
|
|
||||||
health = (float) entityMetadata.getValue();
|
|
||||||
updateBedrockAttributes(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entityMetadata.getId() == 16) {
|
if (entityMetadata.getId() == 16) {
|
||||||
byte xd = (byte) entityMetadata.getValue();
|
byte xd = (byte) entityMetadata.getValue();
|
||||||
metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x02) == 0x02);
|
metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x02) == 0x02);
|
||||||
@ -71,25 +55,4 @@ public class AbstractHorseEntity extends AnimalEntity {
|
|||||||
|
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateBedrockAttributes(GeyserSession session) {
|
|
||||||
if (!valid) return;
|
|
||||||
|
|
||||||
float maxHealth = attributes.containsKey(AttributeType.MAX_HEALTH) ? attributes.get(AttributeType.MAX_HEALTH).getValue() : 20f;
|
|
||||||
|
|
||||||
List<AttributeData> attributesLocal = new ArrayList<>();
|
|
||||||
for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) {
|
|
||||||
if (!entry.getValue().getType().isBedrockAttribute())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
attributesLocal.add(AttributeUtils.getBedrockAttribute(entry.getValue()));
|
|
||||||
}
|
|
||||||
attributesLocal.add(new AttributeData("minecraft:health", 0.0f, maxHealth, health, maxHealth));
|
|
||||||
|
|
||||||
UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket();
|
|
||||||
updateAttributesPacket.setRuntimeEntityId(geyserId);
|
|
||||||
updateAttributesPacket.setAttributes(attributesLocal);
|
|
||||||
session.sendUpstreamPacket(updateAttributesPacket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -140,8 +140,14 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
|
|||||||
case ARMOR_STAND:
|
case ARMOR_STAND:
|
||||||
yOffset = 1.3f;
|
yOffset = 1.3f;
|
||||||
break;
|
break;
|
||||||
|
case STRIDER:
|
||||||
|
yOffset = 2.8200102f;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
Vector3f offset = Vector3f.from(0f, yOffset, 0f);
|
Vector3f offset = Vector3f.from(0f, yOffset, 0f);
|
||||||
|
if (mountType == EntityType.STRIDER) {
|
||||||
|
offset = offset.add(0f, 0f, -0.2f);
|
||||||
|
}
|
||||||
// Without the X offset, more than one entity on a boat is stacked on top of each other
|
// Without the X offset, more than one entity on a boat is stacked on top of each other
|
||||||
if (rider && moreThanOneEntity) {
|
if (rider && moreThanOneEntity) {
|
||||||
offset = offset.add(Vector3f.from(0.2, 0, 0));
|
offset = offset.add(Vector3f.from(0.2, 0, 0));
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit fdc65607994b924261f43170f4d4d563b14167d7
|
Subproject commit 668156d559be2c0e081950194342da7fb68f1543
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren