diff --git a/api/src/main/java/net/momirealms/customnameplates/api/Platform.java b/api/src/main/java/net/momirealms/customnameplates/api/Platform.java index 391385f..7b2ce43 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/Platform.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/Platform.java @@ -190,7 +190,7 @@ public interface Platform { */ Consumer> createTranslationModifier(Vector3 translation); - Consumer> createSneakModifier(boolean isSneaking, NameTagConfig config); + Consumer> createSneakModifier(boolean isSneaking, boolean seeThrough, NameTagConfig config); /** * Updates an existing text display entity with modifiers. diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfig.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfig.java index 6eca9b8..4bce9f9 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfig.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfig.java @@ -21,6 +21,7 @@ import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.util.Alignment; import net.momirealms.customnameplates.api.util.Vector3; +import net.momirealms.customnameplates.common.util.Tristate; /** * NameTag Configuration @@ -79,10 +80,8 @@ public interface NameTagConfig { /** * Checks if the name tag is see-through. * - * @return true if the name tag is see-through, false otherwise */ - @Deprecated - boolean isSeeThrough(); + Tristate isSeeThrough(); /** * Checks if the default background color is used. @@ -245,7 +244,7 @@ public interface NameTagConfig { * @param seeThrough true if the name tag is see-through, false otherwise * @return the builder instance */ - Builder seeThrough(boolean seeThrough); + Builder seeThrough(Tristate seeThrough); /** * Sets whether the name tag uses the default background color. diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfigImpl.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfigImpl.java index e055c7e..d5524e0 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfigImpl.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfigImpl.java @@ -21,6 +21,7 @@ import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.util.Alignment; import net.momirealms.customnameplates.api.util.Vector3; +import net.momirealms.customnameplates.common.util.Tristate; /** * Implementation of NameTagConfig @@ -34,7 +35,7 @@ public class NameTagConfigImpl implements NameTagConfig { private final byte opacity; private final int backgroundColor; private final boolean hasShadow; - private final boolean isSeeThrough; + private final Tristate isSeeThrough; private final boolean useDefaultBackgroundColor; private final Alignment alignment; private final float viewRange; @@ -46,7 +47,7 @@ public class NameTagConfigImpl implements NameTagConfig { private final boolean affectedByScale; private final boolean affectedBySpectator; - private NameTagConfigImpl(String id, Requirement[] ownerRequirements, Requirement[] viewerRequirements, CarouselText[] carouselTexts, int lineWidth, byte opacity, int backgroundColor, boolean hasShadow, boolean isSeeThrough, boolean useDefaultBackgroundColor, Alignment alignment, float viewRange, float shadowRadius, float shadowStrength, Vector3 scale, Vector3 translation, boolean affectedByCrouching, boolean affectedByScale, boolean affectedBySpectator) { + private NameTagConfigImpl(String id, Requirement[] ownerRequirements, Requirement[] viewerRequirements, CarouselText[] carouselTexts, int lineWidth, byte opacity, int backgroundColor, boolean hasShadow, Tristate isSeeThrough, boolean useDefaultBackgroundColor, Alignment alignment, float viewRange, float shadowRadius, float shadowStrength, Vector3 scale, Vector3 translation, boolean affectedByCrouching, boolean affectedByScale, boolean affectedBySpectator) { this.id = id; this.ownerRequirements = ownerRequirements; this.viewerRequirements = viewerRequirements; @@ -104,7 +105,7 @@ public class NameTagConfigImpl implements NameTagConfig { } @Override - public boolean isSeeThrough() { + public Tristate isSeeThrough() { return isSeeThrough; } @@ -175,7 +176,7 @@ public class NameTagConfigImpl implements NameTagConfig { private byte opacity; private int backgroundColor; private boolean hasShadow; - private boolean isSeeThrough; + private Tristate isSeeThrough; private boolean useDefaultBackgroundColor; private Alignment alignment; private float viewRange; @@ -236,7 +237,7 @@ public class NameTagConfigImpl implements NameTagConfig { } @Override - public Builder seeThrough(boolean seeThrough) { + public Builder seeThrough(Tristate seeThrough) { this.isSeeThrough = seeThrough; return this; } diff --git a/api/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java b/api/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java index 554db8c..03000dd 100644 --- a/api/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java @@ -69,6 +69,21 @@ public enum Tristate { this.booleanValue = booleanValue; } + public boolean or(boolean val) { + if (this == UNDEFINED) { + return val; + } else { + return this.booleanValue; + } + } + + public static Tristate fromBoolean(Boolean val) { + if (val == null) { + return UNDEFINED; + } + return val ? TRUE : FALSE; + } + /** * Returns the value of the Tristate as a boolean. * diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/NameTag.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/NameTag.java index 2c2cf33..590e4a9 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/NameTag.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/NameTag.java @@ -66,7 +66,7 @@ public class NameTag extends AbstractTag implements RelationalFeature { 0, 0, 0, component, config.backgroundColor(), (owner.isSpectator() && affectedBySpectator()) || (owner.isCrouching() && affectedByCrouching()) ? 64 : opacity(), - config.hasShadow(), config.isSeeThrough(), config.useDefaultBackgroundColor(), + config.hasShadow(), config.isSeeThrough().asBoolean() && (!affectedByCrouching() || !tracker.isCrouching()), config.useDefaultBackgroundColor(), config.alignment(), config.viewRange(), config.shadowRadius(), config.shadowStrength(), (affectedByScaling() ? scale(viewer).multiply(tracker.getScale()) : scale(viewer)), (affectedByScaling() ? translation(viewer).multiply(tracker.getScale()) : translation(viewer)), @@ -77,7 +77,9 @@ public class NameTag extends AbstractTag implements RelationalFeature { @Override public void darkTag(CNPlayer viewer, boolean dark) { - Consumer> modifiers = CustomNameplates.getInstance().getPlatform().createSneakModifier(dark, this.config); + Tracker tracker = owner.getTracker(viewer); + boolean seeThrough = config.isSeeThrough().asBoolean() && (!affectedByCrouching() || !tracker.isCrouching()); + Consumer> modifiers = CustomNameplates.getInstance().getPlatform().createSneakModifier(dark, seeThrough, this.config); Object packet = CustomNameplates.getInstance().getPlatform().updateTextDisplayPacket(entityID, List.of(modifiers)); CustomNameplates.getInstance().getPacketSender().sendPacket(viewer, packet); } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java index b1e896d..947ff08 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java @@ -43,6 +43,7 @@ import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.util.Alignment; import net.momirealms.customnameplates.api.util.ConfigUtils; import net.momirealms.customnameplates.api.util.Vector3; +import net.momirealms.customnameplates.common.util.Tristate; import java.io.File; import java.io.IOException; @@ -302,7 +303,7 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, PlayerListe .shadowStrength(section.getFloat("shadow-strength", 1f)) .lineWidth(section.getInt("line-width", 200)) .hasShadow(section.getBoolean("has-shadow", false)) - .seeThrough(section.getBoolean("is-see-through", false)) + .seeThrough(Tristate.fromBoolean((Boolean) section.get("is-see-through"))) .opacity(section.getByte("opacity", (byte) -1)) .useDefaultBackgroundColor(section.getBoolean("use-default-background-color", false)) .backgroundColor(ConfigUtils.argb(section.getString("background-color", "64,0,0,0"))) diff --git a/backend/src/main/resources/configs/nameplate.yml b/backend/src/main/resources/configs/nameplate.yml index 34b0e7b..6a83892 100644 --- a/backend/src/main/resources/configs/nameplate.yml +++ b/backend/src/main/resources/configs/nameplate.yml @@ -22,6 +22,7 @@ unlimited: affected-by-spectator: true line-width: 1024 background-color: 64,0,0,0 + is-see-through: false tag_image_part: text: '%np_tag-image%' translation: 0,0.2,0 @@ -35,6 +36,7 @@ unlimited: affected-by-spectator: true line-width: 1024 background-color: 0,0,0,0 + is-see-through: false tag_text_part: text: '%np_tag-text%' translation: 0.01,0.2,0.01 @@ -47,4 +49,5 @@ unlimited: affected-by-scale-attribute: true affected-by-spectator: true line-width: 1024 - background-color: 0,0,0,0 \ No newline at end of file + background-color: 0,0,0,0 + is-see-through: false \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index d5ec0c9..a78309c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=3.0.34 +project_version=3.0.34.1 config_version=38 project_group=net.momirealms @@ -47,9 +47,9 @@ lwjgl_version=3.3.6 fastutil_version=8.5.18 # Proxy settings -#systemProp.socks.proxyHost=127.0.0.1 -#systemProp.socks.proxyPort=7890 -#systemProp.http.proxyHost=127.0.0.1 -#systemProp.http.proxyPort=7890 -#systemProp.https.proxyHost=127.0.0.1 -#systemProp.https.proxyPort=7890 +systemProp.socks.proxyHost=127.0.0.1 +systemProp.socks.proxyPort=7890 +systemProp.http.proxyHost=127.0.0.1 +systemProp.http.proxyPort=7890 +systemProp.https.proxyHost=127.0.0.1 +systemProp.https.proxyPort=7890 diff --git a/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java b/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java index df980d6..6252a64 100644 --- a/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java +++ b/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java @@ -639,7 +639,7 @@ public class BukkitPlatform implements Platform { EntityData.LineWidth.addEntityDataIfNotDefaultValue( lineWidth, values); EntityData.Scale.addEntityDataIfNotDefaultValue( scale.toVec3(), values); EntityData.Translation.addEntityDataIfNotDefaultValue( translation.toVec3(), values); - EntityData.TextDisplayMasks.addEntityDataIfNotDefaultValue(EntityData.encodeMask(hasShadow, !isCrouching, useDefaultBackgroundColor, alignment.getId()), values); + EntityData.TextDisplayMasks.addEntityDataIfNotDefaultValue(EntityData.encodeMask(hasShadow, isSeeThrough, useDefaultBackgroundColor, alignment.getId()), values); Object setDataPacket = Reflections.constructor$ClientboundSetEntityDataPacket.newInstance(entityID, values); @@ -679,10 +679,10 @@ public class BukkitPlatform implements Platform { } @Override - public Consumer> createSneakModifier(boolean sneak, NameTagConfig config) { + public Consumer> createSneakModifier(boolean sneak, boolean seeThrough, NameTagConfig config) { return (values) -> { EntityData.TextOpacity.addEntityData(sneak ? 64 : config.opacity(), values); - EntityData.TextDisplayMasks.addEntityData(EntityData.encodeMask(config.hasShadow(), !sneak, config.useDefaultBackgroundColor(), config.alignment().getId()), values); + EntityData.TextDisplayMasks.addEntityData(EntityData.encodeMask(config.hasShadow(), seeThrough, config.useDefaultBackgroundColor(), config.alignment().getId()), values); }; }