Fix default wolf and cat collar color (#4582)

This commit is contained in:
AJ Ferguson 2024-04-19 05:41:06 -04:00 committed by GitHub
parent 0cc2921eda
commit c3ffd65f48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 11 deletions

View file

@ -45,7 +45,7 @@ import java.util.UUID;
public class CatEntity extends TameableEntity { public class CatEntity extends TameableEntity {
private byte collarColor; private byte collarColor = 14; // Red - default
public CatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { public CatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
@ -76,10 +76,7 @@ public class CatEntity extends TameableEntity {
@Override @Override
public void setTameableFlags(ByteEntityMetadata entityMetadata) { public void setTameableFlags(ByteEntityMetadata entityMetadata) {
super.setTameableFlags(entityMetadata); super.setTameableFlags(entityMetadata);
// Update collar color if tamed updateCollarColor();
if (getFlag(EntityFlag.TAMED)) {
dirtyMetadata.put(EntityDataTypes.COLOR, collarColor);
}
} }
public void setCatVariant(IntEntityMetadata entityMetadata) { public void setCatVariant(IntEntityMetadata entityMetadata) {
@ -101,6 +98,10 @@ public class CatEntity extends TameableEntity {
public void setCollarColor(IntEntityMetadata entityMetadata) { public void setCollarColor(IntEntityMetadata entityMetadata) {
collarColor = (byte) entityMetadata.getPrimitiveValue(); collarColor = (byte) entityMetadata.getPrimitiveValue();
updateCollarColor();
}
private void updateCollarColor() {
// Needed or else wild cats are a red color // Needed or else wild cats are a red color
if (getFlag(EntityFlag.TAMED)) { if (getFlag(EntityFlag.TAMED)) {
dirtyMetadata.put(EntityDataTypes.COLOR, collarColor); dirtyMetadata.put(EntityDataTypes.COLOR, collarColor);

View file

@ -32,6 +32,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
@ -41,6 +42,7 @@ import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractionResult;
import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.geyser.util.InteractiveTag;
import java.util.Collections;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -54,7 +56,7 @@ public class WolfEntity extends TameableEntity {
Items.PORKCHOP, Items.BEEF, Items.RABBIT, Items.COOKED_PORKCHOP, Items.COOKED_BEEF, Items.ROTTEN_FLESH, Items.MUTTON, Items.COOKED_MUTTON, Items.PORKCHOP, Items.BEEF, Items.RABBIT, Items.COOKED_PORKCHOP, Items.COOKED_BEEF, Items.ROTTEN_FLESH, Items.MUTTON, Items.COOKED_MUTTON,
Items.COOKED_RABBIT); Items.COOKED_RABBIT);
private byte collarColor; private byte collarColor = 14; // Red - default
public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
@ -64,19 +66,27 @@ public class WolfEntity extends TameableEntity {
public void setTameableFlags(ByteEntityMetadata entityMetadata) { public void setTameableFlags(ByteEntityMetadata entityMetadata) {
super.setTameableFlags(entityMetadata); super.setTameableFlags(entityMetadata);
// Reset wolf color // Reset wolf color
byte xd = entityMetadata.getPrimitiveValue(); if (getFlag(EntityFlag.ANGRY)) {
boolean angry = (xd & 0x02) == 0x02;
if (angry) {
dirtyMetadata.put(EntityDataTypes.COLOR, (byte) 0); dirtyMetadata.put(EntityDataTypes.COLOR, (byte) 0);
} else if (getFlag(EntityFlag.TAMED)) {
updateCollarColor();
// This fixes tail angle when taming
UpdateAttributesPacket packet = new UpdateAttributesPacket();
packet.setRuntimeEntityId(geyserId);
packet.setAttributes(Collections.singletonList(createHealthAttribute()));
session.sendUpstreamPacket(packet);
} }
} }
public void setCollarColor(IntEntityMetadata entityMetadata) { public void setCollarColor(IntEntityMetadata entityMetadata) {
collarColor = (byte) entityMetadata.getPrimitiveValue(); collarColor = (byte) entityMetadata.getPrimitiveValue();
if (getFlag(EntityFlag.ANGRY)) { if (!getFlag(EntityFlag.ANGRY) && getFlag(EntityFlag.TAMED)) {
return; updateCollarColor();
}
} }
private void updateCollarColor() {
dirtyMetadata.put(EntityDataTypes.COLOR, collarColor); dirtyMetadata.put(EntityDataTypes.COLOR, collarColor);
if (ownerBedrockId == 0) { if (ownerBedrockId == 0) {
// If a color is set and there is no owner entity ID, set one. // If a color is set and there is no owner entity ID, set one.