Skip to content

Commit

Permalink
Fix no setting to control if tall self disguises are scaled per disguise
Browse files Browse the repository at this point in the history
  • Loading branch information
libraryaddict committed Nov 30, 2024
1 parent ebf66ce commit 1fbda44
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
// If they're disguised, tall disguises are hidden, it's a tall disguise
// Then tell the player, it's not a bug! The disguise is too tall
if (disguise != null && !disguise.isTallDisguisesVisible() &&
(!NmsVersion.v1_20_R4.isSupported() || !DisguiseConfig.isTallSelfDisguisesScaling() ||
(!NmsVersion.v1_20_R4.isSupported() || !disguise.isTallSelfDisguisesScaling() ||
(disguise.isMiscDisguise() || disguise.getType() == DisguiseType.ENDER_DRAGON)) && disguise.canSee(player) &&
DisguiseUtilities.isTallDisguise(disguise)) {
LibsMsg.VIEW_SELF_TALL_NOTE.send(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public abstract class Disguise {
@Getter
private boolean scalePlayerToDisguise = DisguiseConfig.isScaleSelfDisguises();
@Getter
private boolean tallSelfDisguisesScaling = DisguiseConfig.isTallSelfDisguisesScaling();
@Getter
private final DisguiseInternals internals;

public Disguise(DisguiseType disguiseType) {
Expand Down Expand Up @@ -521,7 +523,7 @@ public Disguise setEntity(Entity entity) {
}

if (getEntity() instanceof Player && isSelfDisguiseVisible() && !isTallDisguisesVisible() && isTallDisguise()) {
if (DisguiseConfig.isTallSelfDisguisesScaling() && NmsVersion.v1_20_R4.isSupported() && canScaleDisguise()) {
if (isTallSelfDisguisesScaling() && NmsVersion.v1_20_R4.isSupported() && canScaleDisguise()) {
adjustTallSelfDisguiseScale();
} else {
setSelfDisguiseVisible(false);
Expand Down Expand Up @@ -550,6 +552,15 @@ public void setScalePlayerToDisguise(boolean scalePlayerToDisguise) {
adjustTallSelfDisguiseScale();
}

public void setTallSelfDisguisesScaling(boolean tallSelfDisguisesScaling) {
if (!NmsVersion.v1_20_R4.isSupported()) {
return;
}

this.tallSelfDisguisesScaling = tallSelfDisguisesScaling;
adjustTallSelfDisguiseScale();
}

protected void adjustTallSelfDisguiseScale() {
if (!canScaleDisguise() || !isDisguiseInUse() || getEntity() == null) {
return;
Expand Down Expand Up @@ -598,7 +609,7 @@ private void adjustSelfDisguiseScale(double prevPersonalDisguiseScaleMax, double
return;
}

if (prevPersonalDisguiseScaleMax != newPersonalDisguiseScaleMax && isSelfDisguiseVisible()) {
if (prevPersonalDisguiseScaleMax != newPersonalDisguiseScaleMax && isSelfDisguiseVisible() && isTallSelfDisguisesScaling()) {
double scaleToSend;

if (((LivingWatcher) getWatcher()).getScale() != null) {
Expand All @@ -607,7 +618,9 @@ private void adjustSelfDisguiseScale(double prevPersonalDisguiseScaleMax, double
scaleToSend = playerScaleWithoutLibsDisguises;
}

scaleToSend = Math.min(scaleToSend, newPersonalDisguiseScaleMax);
if (isScalePlayerToDisguise()) {
scaleToSend = Math.min(scaleToSend, newPersonalDisguiseScaleMax);
}

// The scale of the self disguise, not the player
WrapperPlayServerUpdateAttributes.Property property =
Expand Down Expand Up @@ -1000,8 +1013,7 @@ private void setupWatcher() {
@Deprecated
public Disguise setViewSelfDisguise(boolean viewSelfDisguise) {
if (viewSelfDisguise && !isTallDisguisesVisible() && isTallDisguise()) {
if (DisguiseConfig.isTallSelfDisguisesScaling() && NmsVersion.v1_20_R4.isSupported() && canScaleDisguise() &&
!isPlayerDisguise()) {
if (isTallSelfDisguisesScaling() && NmsVersion.v1_20_R4.isSupported() && canScaleDisguise() && !isPlayerDisguise()) {
adjustTallSelfDisguiseScale();
} else {
viewSelfDisguise = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void setScale(Double viewScale) {
Entity entity = getDisguise().getEntity();

for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
double toSend = player == entity && DisguiseConfig.isTallSelfDisguisesScaling() ?
double toSend = player == entity && getDisguise().isTallSelfDisguisesScaling() ?
Math.min(getDisguise().getInternals().getSelfDisguiseTallScaleMax(), scaleToSend) : scaleToSend;

WrapperPlayServerUpdateAttributes.Property property =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void handle(Disguise disguise, LibsPackets<WrapperPlayServerUpdateAttribu
Double scale = ((LivingWatcher) disguise.getWatcher()).getScale();

// If it's for the self disguise and the disguise had to be scaled down
if (entity == observer && DisguiseConfig.isTallSelfDisguisesScaling()) {
if (entity == observer && disguise.isTallSelfDisguisesScaling()) {
attributes.add(new WrapperPlayServerUpdateAttributes.Property(Attributes.GENERIC_SCALE,
Math.min(disguise.getInternals().getSelfDisguiseTallScaleMax(), scale == null ? property.getValue() : scale),
new ArrayList<>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private void constructSpawnPackets(final Player observer, LibsPackets packets, E
if (NmsVersion.v1_20_R4.isSupported()) {
Double scale = ((LivingWatcher) disguise.getWatcher()).getScale();

if (observer == disguisedEntity && DisguiseConfig.isTallSelfDisguisesScaling()) {
if (observer == disguisedEntity && disguise.isTallSelfDisguisesScaling()) {
if (scale == null) {
scale = DisguiseUtilities.getEntityScaleWithoutLibsDisguises(observer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private void loadMethods() {

if (NmsVersion.v1_20_R4.isSupported()) {
extraMethods.add("setScalePlayerToDisguise");
extraMethods.add("setTallSelfDisguisesScaling");
}

// Add these last as it's what we want to present to be called the least
Expand Down

0 comments on commit 1fbda44

Please sign in to comment.