9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-19 15:09:23 +00:00

fixed is see through

This commit is contained in:
XiaoMoMi
2025-10-16 03:18:18 +08:00
parent dafe373f81
commit 084f7d1edf
9 changed files with 45 additions and 24 deletions

View File

@@ -190,7 +190,7 @@ public interface Platform {
*/ */
Consumer<List<Object>> createTranslationModifier(Vector3 translation); Consumer<List<Object>> createTranslationModifier(Vector3 translation);
Consumer<List<Object>> createSneakModifier(boolean isSneaking, NameTagConfig config); Consumer<List<Object>> createSneakModifier(boolean isSneaking, boolean seeThrough, NameTagConfig config);
/** /**
* Updates an existing text display entity with modifiers. * Updates an existing text display entity with modifiers.

View File

@@ -21,6 +21,7 @@ import net.momirealms.customnameplates.api.feature.CarouselText;
import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.requirement.Requirement;
import net.momirealms.customnameplates.api.util.Alignment; import net.momirealms.customnameplates.api.util.Alignment;
import net.momirealms.customnameplates.api.util.Vector3; import net.momirealms.customnameplates.api.util.Vector3;
import net.momirealms.customnameplates.common.util.Tristate;
/** /**
* NameTag Configuration * NameTag Configuration
@@ -79,10 +80,8 @@ public interface NameTagConfig {
/** /**
* Checks if the name tag is see-through. * Checks if the name tag is see-through.
* *
* @return true if the name tag is see-through, false otherwise
*/ */
@Deprecated Tristate isSeeThrough();
boolean isSeeThrough();
/** /**
* Checks if the default background color is used. * 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 * @param seeThrough true if the name tag is see-through, false otherwise
* @return the builder instance * @return the builder instance
*/ */
Builder seeThrough(boolean seeThrough); Builder seeThrough(Tristate seeThrough);
/** /**
* Sets whether the name tag uses the default background color. * Sets whether the name tag uses the default background color.

View File

@@ -21,6 +21,7 @@ import net.momirealms.customnameplates.api.feature.CarouselText;
import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.requirement.Requirement;
import net.momirealms.customnameplates.api.util.Alignment; import net.momirealms.customnameplates.api.util.Alignment;
import net.momirealms.customnameplates.api.util.Vector3; import net.momirealms.customnameplates.api.util.Vector3;
import net.momirealms.customnameplates.common.util.Tristate;
/** /**
* Implementation of NameTagConfig * Implementation of NameTagConfig
@@ -34,7 +35,7 @@ public class NameTagConfigImpl implements NameTagConfig {
private final byte opacity; private final byte opacity;
private final int backgroundColor; private final int backgroundColor;
private final boolean hasShadow; private final boolean hasShadow;
private final boolean isSeeThrough; private final Tristate isSeeThrough;
private final boolean useDefaultBackgroundColor; private final boolean useDefaultBackgroundColor;
private final Alignment alignment; private final Alignment alignment;
private final float viewRange; private final float viewRange;
@@ -46,7 +47,7 @@ public class NameTagConfigImpl implements NameTagConfig {
private final boolean affectedByScale; private final boolean affectedByScale;
private final boolean affectedBySpectator; 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.id = id;
this.ownerRequirements = ownerRequirements; this.ownerRequirements = ownerRequirements;
this.viewerRequirements = viewerRequirements; this.viewerRequirements = viewerRequirements;
@@ -104,7 +105,7 @@ public class NameTagConfigImpl implements NameTagConfig {
} }
@Override @Override
public boolean isSeeThrough() { public Tristate isSeeThrough() {
return isSeeThrough; return isSeeThrough;
} }
@@ -175,7 +176,7 @@ public class NameTagConfigImpl implements NameTagConfig {
private byte opacity; private byte opacity;
private int backgroundColor; private int backgroundColor;
private boolean hasShadow; private boolean hasShadow;
private boolean isSeeThrough; private Tristate isSeeThrough;
private boolean useDefaultBackgroundColor; private boolean useDefaultBackgroundColor;
private Alignment alignment; private Alignment alignment;
private float viewRange; private float viewRange;
@@ -236,7 +237,7 @@ public class NameTagConfigImpl implements NameTagConfig {
} }
@Override @Override
public Builder seeThrough(boolean seeThrough) { public Builder seeThrough(Tristate seeThrough) {
this.isSeeThrough = seeThrough; this.isSeeThrough = seeThrough;
return this; return this;
} }

View File

@@ -69,6 +69,21 @@ public enum Tristate {
this.booleanValue = booleanValue; 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. * Returns the value of the Tristate as a boolean.
* *

View File

@@ -66,7 +66,7 @@ public class NameTag extends AbstractTag implements RelationalFeature {
0, 0, 0, 0, 0, 0,
component, config.backgroundColor(), component, config.backgroundColor(),
(owner.isSpectator() && affectedBySpectator()) || (owner.isCrouching() && affectedByCrouching()) ? 64 : opacity(), (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(), config.alignment(), config.viewRange(), config.shadowRadius(), config.shadowStrength(),
(affectedByScaling() ? scale(viewer).multiply(tracker.getScale()) : scale(viewer)), (affectedByScaling() ? scale(viewer).multiply(tracker.getScale()) : scale(viewer)),
(affectedByScaling() ? translation(viewer).multiply(tracker.getScale()) : translation(viewer)), (affectedByScaling() ? translation(viewer).multiply(tracker.getScale()) : translation(viewer)),
@@ -77,7 +77,9 @@ public class NameTag extends AbstractTag implements RelationalFeature {
@Override @Override
public void darkTag(CNPlayer viewer, boolean dark) { public void darkTag(CNPlayer viewer, boolean dark) {
Consumer<List<Object>> modifiers = CustomNameplates.getInstance().getPlatform().createSneakModifier(dark, this.config); Tracker tracker = owner.getTracker(viewer);
boolean seeThrough = config.isSeeThrough().asBoolean() && (!affectedByCrouching() || !tracker.isCrouching());
Consumer<List<Object>> modifiers = CustomNameplates.getInstance().getPlatform().createSneakModifier(dark, seeThrough, this.config);
Object packet = CustomNameplates.getInstance().getPlatform().updateTextDisplayPacket(entityID, List.of(modifiers)); Object packet = CustomNameplates.getInstance().getPlatform().updateTextDisplayPacket(entityID, List.of(modifiers));
CustomNameplates.getInstance().getPacketSender().sendPacket(viewer, packet); CustomNameplates.getInstance().getPacketSender().sendPacket(viewer, packet);
} }

View File

@@ -43,6 +43,7 @@ import net.momirealms.customnameplates.api.requirement.Requirement;
import net.momirealms.customnameplates.api.util.Alignment; import net.momirealms.customnameplates.api.util.Alignment;
import net.momirealms.customnameplates.api.util.ConfigUtils; import net.momirealms.customnameplates.api.util.ConfigUtils;
import net.momirealms.customnameplates.api.util.Vector3; import net.momirealms.customnameplates.api.util.Vector3;
import net.momirealms.customnameplates.common.util.Tristate;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -302,7 +303,7 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, PlayerListe
.shadowStrength(section.getFloat("shadow-strength", 1f)) .shadowStrength(section.getFloat("shadow-strength", 1f))
.lineWidth(section.getInt("line-width", 200)) .lineWidth(section.getInt("line-width", 200))
.hasShadow(section.getBoolean("has-shadow", false)) .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)) .opacity(section.getByte("opacity", (byte) -1))
.useDefaultBackgroundColor(section.getBoolean("use-default-background-color", false)) .useDefaultBackgroundColor(section.getBoolean("use-default-background-color", false))
.backgroundColor(ConfigUtils.argb(section.getString("background-color", "64,0,0,0"))) .backgroundColor(ConfigUtils.argb(section.getString("background-color", "64,0,0,0")))

View File

@@ -22,6 +22,7 @@ unlimited:
affected-by-spectator: true affected-by-spectator: true
line-width: 1024 line-width: 1024
background-color: 64,0,0,0 background-color: 64,0,0,0
is-see-through: false
tag_image_part: tag_image_part:
text: '%np_tag-image%' text: '%np_tag-image%'
translation: 0,0.2,0 translation: 0,0.2,0
@@ -35,6 +36,7 @@ unlimited:
affected-by-spectator: true affected-by-spectator: true
line-width: 1024 line-width: 1024
background-color: 0,0,0,0 background-color: 0,0,0,0
is-see-through: false
tag_text_part: tag_text_part:
text: '%np_tag-text%' text: '%np_tag-text%'
translation: 0.01,0.2,0.01 translation: 0.01,0.2,0.01
@@ -47,4 +49,5 @@ unlimited:
affected-by-scale-attribute: true affected-by-scale-attribute: true
affected-by-spectator: true affected-by-spectator: true
line-width: 1024 line-width: 1024
background-color: 0,0,0,0 background-color: 0,0,0,0
is-see-through: false

View File

@@ -1,6 +1,6 @@
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=3.0.34 project_version=3.0.34.1
config_version=38 config_version=38
project_group=net.momirealms project_group=net.momirealms
@@ -47,9 +47,9 @@ lwjgl_version=3.3.6
fastutil_version=8.5.18 fastutil_version=8.5.18
# Proxy settings # Proxy settings
#systemProp.socks.proxyHost=127.0.0.1 systemProp.socks.proxyHost=127.0.0.1
#systemProp.socks.proxyPort=7890 systemProp.socks.proxyPort=7890
#systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyHost=127.0.0.1
#systemProp.http.proxyPort=7890 systemProp.http.proxyPort=7890
#systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1
#systemProp.https.proxyPort=7890 systemProp.https.proxyPort=7890

View File

@@ -639,7 +639,7 @@ public class BukkitPlatform implements Platform {
EntityData.LineWidth.addEntityDataIfNotDefaultValue( lineWidth, values); EntityData.LineWidth.addEntityDataIfNotDefaultValue( lineWidth, values);
EntityData.Scale.addEntityDataIfNotDefaultValue( scale.toVec3(), values); EntityData.Scale.addEntityDataIfNotDefaultValue( scale.toVec3(), values);
EntityData.Translation.addEntityDataIfNotDefaultValue( translation.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); Object setDataPacket = Reflections.constructor$ClientboundSetEntityDataPacket.newInstance(entityID, values);
@@ -679,10 +679,10 @@ public class BukkitPlatform implements Platform {
} }
@Override @Override
public Consumer<List<Object>> createSneakModifier(boolean sneak, NameTagConfig config) { public Consumer<List<Object>> createSneakModifier(boolean sneak, boolean seeThrough, NameTagConfig config) {
return (values) -> { return (values) -> {
EntityData.TextOpacity.addEntityData(sneak ? 64 : config.opacity(), 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);
}; };
} }