Skip to content

Commit

Permalink
Clean up and fix more armor stand inconsistencies (GeyserMC#1988)
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy authored Feb 27, 2021
1 parent ae3f50a commit e09f33c
Showing 1 changed file with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,43 +123,38 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
isInvisible = (xd & 0x20) == 0x20;
updateSecondEntityStatus(false);
}
} else if (entityMetadata.getId() == 2 || entityMetadata.getId() == 3) {
} else if (entityMetadata.getId() == 2) {
updateSecondEntityStatus(false);
} else if (entityMetadata.getId() == 14 && entityMetadata.getType() == MetadataType.BYTE) {
byte xd = (byte) entityMetadata.getValue();

// isSmall
boolean newIsSmall = (xd & 0x01) == 0x01;
if ((newIsSmall != isSmall) && positionRequiresOffset) {
// Fix new inconsistency with offset
this.position = fixOffsetForSize(position, newIsSmall);
positionUpdateRequired = true;
}
isSmall = newIsSmall;
if (isSmall) {

float scale = metadata.getFloat(EntityData.SCALE);
if (scale != 0.55f && scale != 0.0f) {
metadata.put(EntityData.SCALE, 0.55f);
if (newIsSmall != isSmall) {
if (positionRequiresOffset) {
// Fix new inconsistency with offset
this.position = fixOffsetForSize(position, newIsSmall);
positionUpdateRequired = true;
}

if (metadata.getFloat(EntityData.BOUNDING_BOX_WIDTH) == 0.5f) {
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.25f);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.9875f);
isSmall = newIsSmall;
if (!isMarker) {
toggleSmallStatus();
}
} else if (metadata.getFloat(EntityData.BOUNDING_BOX_WIDTH) == 0.25f) {
metadata.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth());
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, entityType.getHeight());
}

// setMarker
boolean oldIsMarker = isMarker;
isMarker = (xd & 0x10) == 0x10;
if (isMarker) {
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.0f);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.0f);
}
if (oldIsMarker != isMarker) {
if (isMarker) {
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.0f);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.0f);
metadata.put(EntityData.SCALE, 0f);
} else {
toggleSmallStatus();
}

updateSecondEntityStatus(false);
}
}
Expand Down Expand Up @@ -226,6 +221,7 @@ private void updateSecondEntityStatus(boolean sendMetadata) {
if (!primaryEntity) return;
if (!isInvisible || isMarker) {
// It is either impossible to show armor, or the armor stand isn't invisible. We good.
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, false);
updateOffsetRequirement(false);
if (positionUpdateRequired) {
positionUpdateRequired = false;
Expand Down Expand Up @@ -306,6 +302,15 @@ private void updateSecondEntityStatus(boolean sendMetadata) {
}
}

/**
* If this armor stand is not a marker, set its bounding box size and scale.
*/
private void toggleSmallStatus() {
metadata.put(EntityData.BOUNDING_BOX_WIDTH, isSmall ? 0.25f : entityType.getWidth());
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, isSmall ? 0.9875f : entityType.getHeight());
metadata.put(EntityData.SCALE, isSmall ? 0.55f : 1f);
}

/**
* @return the selected position with the position offset applied.
*/
Expand Down

0 comments on commit e09f33c

Please sign in to comment.