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 default wolf and cat collar color #4582

Merged
merged 1 commit into from
Apr 19, 2024
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 @@ -45,7 +45,7 @@

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) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
Expand Down Expand Up @@ -76,10 +76,7 @@ protected float getBabySize() {
@Override
public void setTameableFlags(ByteEntityMetadata entityMetadata) {
super.setTameableFlags(entityMetadata);
// Update collar color if tamed
if (getFlag(EntityFlag.TAMED)) {
dirtyMetadata.put(EntityDataTypes.COLOR, collarColor);
}
updateCollarColor();
}

public void setCatVariant(IntEntityMetadata entityMetadata) {
Expand All @@ -101,6 +98,10 @@ public void setResting(BooleanEntityMetadata entityMetadata) {

public void setCollarColor(IntEntityMetadata entityMetadata) {
collarColor = (byte) entityMetadata.getPrimitiveValue();
updateCollarColor();
}

private void updateCollarColor() {
// Needed or else wild cats are a red color
if (getFlag(EntityFlag.TAMED)) {
dirtyMetadata.put(EntityDataTypes.COLOR, collarColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
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.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items;
Expand All @@ -41,6 +42,7 @@
import org.geysermc.geyser.util.InteractionResult;
import org.geysermc.geyser.util.InteractiveTag;

import java.util.Collections;
import java.util.Set;
import java.util.UUID;

Expand All @@ -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.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) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
Expand All @@ -64,19 +66,27 @@ public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid,
public void setTameableFlags(ByteEntityMetadata entityMetadata) {
super.setTameableFlags(entityMetadata);
// Reset wolf color
byte xd = entityMetadata.getPrimitiveValue();
boolean angry = (xd & 0x02) == 0x02;
if (angry) {
if (getFlag(EntityFlag.ANGRY)) {
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) {
collarColor = (byte) entityMetadata.getPrimitiveValue();
if (getFlag(EntityFlag.ANGRY)) {
return;
if (!getFlag(EntityFlag.ANGRY) && getFlag(EntityFlag.TAMED)) {
updateCollarColor();
}
}

private void updateCollarColor() {
dirtyMetadata.put(EntityDataTypes.COLOR, collarColor);
if (ownerBedrockId == 0) {
// If a color is set and there is no owner entity ID, set one.
Expand Down
Loading