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

improve shaders

This commit is contained in:
XiaoMoMi
2024-10-06 22:42:27 +08:00
parent 844e53ff1a
commit f935a61958
25 changed files with 147 additions and 66 deletions

View File

@@ -421,7 +421,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
@Override
public Set<Integer> getTrackedPassengerIds(CNPlayer another) {
return Optional.ofNullable(trackers.get(another)).map(tracker -> new HashSet<>(tracker.getPassengerIDs())).orElse(new HashSet<>());
return Optional.ofNullable(trackers.get(another)).map(Tracker::getPassengerIDs).orElse(new HashSet<>());
}
@Override

View File

@@ -209,6 +209,10 @@ public class AdventureHelper {
return "<#FFFEFD>" + text + "</#FFFEFD>";
}
public static String removeShadow(String text) {
return "<#F0F0F0>" + text + "</#F0F0F0>";
}
/**
* Surrounds text with a MiniMessage font tag.
*

View File

@@ -19,9 +19,8 @@ package net.momirealms.customnameplates.api.network;
import net.momirealms.customnameplates.api.CNPlayer;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
public class Tracker {
@@ -29,7 +28,7 @@ public class Tracker {
private double scale;
private final CNPlayer tracker;
private final Set<Integer> passengerIDs = Collections.synchronizedSet(new HashSet<>());
private final CopyOnWriteArrayList<Integer> passengerIDs = new CopyOnWriteArrayList<>();
/**
* Constructs a new Tracker for the specified player.
@@ -63,15 +62,15 @@ public class Tracker {
}
public void addPassengerID(int passengerID) {
passengerIDs.add(passengerID);
this.passengerIDs.add(passengerID);
}
public void removePassengerID(int passengerID) {
passengerIDs.remove(passengerID);
this.passengerIDs.remove((Object) passengerID);
}
public Set<Integer> getPassengerIDs() {
return passengerIDs;
return new HashSet<>(passengerIDs);
}
public boolean isEmpty() {

View File

@@ -31,23 +31,25 @@ public class AdaptiveImageText<T extends AdaptiveImage> {
private final String id;
private final String text;
private final T t;
private final boolean removeShadow;
private final boolean removeShadowOld;
private final boolean removeShadowNew;
private final PreParsedDynamicText preParsedDynamicText;
private final int leftMargin;
private final int rightMargin;
public AdaptiveImageText(String id, String text, T t, boolean removeShadow, int leftMargin, int rightMargin) {
public AdaptiveImageText(String id, String text, T t, boolean removeShadowOld, boolean removeShadowNew, int rightMargin, int leftMargin) {
this.text = text;
this.id = id;
this.t = t;
this.removeShadow = removeShadow;
this.removeShadowOld = removeShadowOld;
this.removeShadowNew = removeShadowNew;
this.preParsedDynamicText = new PreParsedDynamicText(text);
this.leftMargin = leftMargin;
this.rightMargin = rightMargin;
}
public static <T extends AdaptiveImage> AdaptiveImageText<T> create(String id, final String text, final T t, final boolean removeShadow, int leftMargin, int rightMargin) {
return new AdaptiveImageText<>(id, text, t, removeShadow, leftMargin, rightMargin);
public static <T extends AdaptiveImage> AdaptiveImageText<T> create(String id, final String text, final T t, final boolean removeShadowOld, final boolean removeShadowNew, int leftMargin, int rightMargin) {
return new AdaptiveImageText<>(id, text, t, removeShadowOld, removeShadowNew, rightMargin, leftMargin);
}
public PreParsedDynamicText getPreParsedDynamicText() {
@@ -71,8 +73,13 @@ public class AdaptiveImageText<T extends AdaptiveImage> {
String suffix = t.createImageSuffix(advance, leftMargin, rightMargin);
String prefixWithFont = AdventureHelper.surroundWithNameplatesFont(prefix);
String suffixWithFont = AdventureHelper.surroundWithNameplatesFont(suffix);
if (removeShadow) prefixWithFont = AdventureHelper.removeShadowTricky(prefixWithFont);
if (removeShadow) suffixWithFont = AdventureHelper.removeShadowTricky(suffixWithFont);
if (removeShadowOld) {
prefixWithFont = AdventureHelper.removeShadowTricky(prefixWithFont);
suffixWithFont = AdventureHelper.removeShadowTricky(suffixWithFont);
} else if (removeShadowNew) {
prefixWithFont = AdventureHelper.removeShadow(prefixWithFont);
suffixWithFont = AdventureHelper.removeShadow(suffixWithFont);
}
return prefixWithFont + parsed + suffixWithFont;
}
@@ -83,7 +90,8 @@ public class AdaptiveImageText<T extends AdaptiveImage> {
float advance = CustomNameplates.getInstance().getAdvanceManager().getLineAdvance(parsed);
String image = t.createImage(advance, leftMargin, rightMargin);
String imageWithFont = AdventureHelper.surroundWithNameplatesFont(image);
if (removeShadow) imageWithFont = AdventureHelper.removeShadowTricky(imageWithFont);
if (removeShadowOld) imageWithFont = AdventureHelper.removeShadowTricky(imageWithFont);
else if (removeShadowNew) imageWithFont = AdventureHelper.removeShadow(imageWithFont);
return imageWithFont;
}

View File

@@ -34,13 +34,11 @@ public class VanillaHud {
private final boolean reverse;
private final PreParsedDynamicText current;
private final PreParsedDynamicText max;
private final boolean removeShadow;
public VanillaHud(Image empty, Image half, Image full, boolean reverse, String current, String max, boolean removeShadow) {
public VanillaHud(Image empty, Image half, Image full, boolean reverse, String current, String max) {
this.empty = String.valueOf(empty.character().character()) + OffsetFont.NEG_2.character();
this.half = String.valueOf(half.character().character()) + OffsetFont.NEG_2.character();
this.full = String.valueOf(full.character().character()) + OffsetFont.NEG_2.character();
this.removeShadow = removeShadow;
this.reverse = reverse;
this.current = new PreParsedDynamicText(current);
this.max = new PreParsedDynamicText(max);
@@ -95,7 +93,6 @@ public class VanillaHud {
.append(String.valueOf(half).repeat(half_amount))
.append(String.valueOf(empty).repeat(empty_amount));
}
return removeShadow ? AdventureHelper.removeShadowTricky(AdventureHelper.surroundWithNameplatesFont(builder.toString())) :
AdventureHelper.surroundWithNameplatesFont(builder.toString());
return AdventureHelper.surroundWithNameplatesFont(builder.toString());
}
}

View File

@@ -487,41 +487,39 @@ public class ResourcePackManagerImpl implements ResourcePackManager {
public static final String Nameplates_Shader_1_20_5 =
"if (Color.xyz == vec3(255., 254., 253.) / 255.) {\n" +
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertex.y += 1;\n" +
" vertex.x += 1;\n" +
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
" } else if (Color.xyz == vec3(254., 254., 254.) / 255.) {\n" +
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertex.z *= 1.001;\n" +
" vertex.x *= 1.001;\n" +
" } else if (Color.xyz == vec3(240., 240., 240.) / 255.) {\n" +
" vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertexColor.rgb = texelFetch(Sampler2, UV2 / 16, 0).rgb;\n" +
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
" } else if (Color.xyz == vec3(253., 254., 254.) / 255.) {\n" +
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertex.z *= 1.001001;\n" +
" vertex.x *= 1.001001;\n" +
" } else if (Color.xyz == vec3(60., 60., 60.) / 255.) {\n" +
" vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);\n" +
" depthLevel = 114514.0;\n" +
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
" } else {\n" +
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);\n" +
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
" }";
public static final String Nameplates_Shader_1_20_4 =
"if (Color.xyz == vec3(255., 254., 253.) / 255.) {\n" +
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertex.y += 1;\n" +
" vertex.x += 1;\n" +
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
" } else if (Color.xyz == vec3(254., 254., 254.) / 255.) {\n" +
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertex.z -= 0.001;\n" +
" } else if (Color.xyz == vec3(240., 240., 240.) / 255.) {\n" +
" vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertexColor.rgb = texelFetch(Sampler2, UV2 / 16, 0).rgb;\n" +
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
" } else if (Color.xyz == vec3(253., 254., 254.) / 255.) {\n" +
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertex.z -= 0.0011;\n" +
" } else if (Color.xyz == vec3(60., 60., 60.) / 255.) {\n" +
" vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);\n" +
" depthLevel = 114514.0;\n" +
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
" } else {\n" +
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
" vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);\n" +
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
" }";

View File

@@ -179,6 +179,22 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
});
this.registerSharedPlaceholder("%shared_np_is-latest%", () -> String.valueOf(plugin.isUpToDate()));
this.registerPlayerPlaceholder("%np_is-latest%", (player) -> String.valueOf(plugin.isUpToDate()));
for (int i = 1; i <= 20; i++) {
int speed = i;
this.registerPlayerPlaceholder("%np_gradient_" + i + "%", (player) -> {
int currentTicks = MainTask.getTicks();
double progress = currentTicks * 0.01 * speed;
return String.format("%.2f", -1 + (progress % 2.0001));
});
}
for (int i = 1; i <= 20; i++) {
int speed = i;
this.registerPlayerPlaceholder("%np_gradient_" + i + "%", (player) -> {
int currentTicks = MainTask.getTicks();
double progress = currentTicks * 0.01 * speed;
return String.format("%.2f", -1 + (progress % 2.0001));
});
}
this.registerPlayerPlaceholder("%np_time%", (player) -> {
long time = player.playerTime() % 24_000;
String ap = time >= 6000 && time < 18000 ? " PM" : " AM";
@@ -284,8 +300,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
Image full = requireNonNull(plugin.getImageManager().imageById(inner.getString("images.full")), "image.full should not be null");
String currentValue = section.getString("placeholder.value", "1");
String maxValue = section.getString("placeholder.max-value", currentValue);
boolean removeShadow = section.getBoolean("remove-shadow", false);
VanillaHud vanillaHud = new VanillaHud(empty, half, full, reverse, currentValue, maxValue, removeShadow);
VanillaHud vanillaHud = new VanillaHud(empty, half, full, reverse, currentValue, maxValue);
List<PreParsedDynamicText> list = List.of(vanillaHud.getCurrent(), vanillaHud.getMax());
Placeholder placeholder1 = registerSharedPlaceholder("%shared_np_vanilla_" + id + "%", vanillaHud::create);
Placeholder placeholder2 = registerPlayerPlaceholder("%np_vanilla_" + id + "%", vanillaHud::create);
@@ -349,7 +364,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
Bubble bubble = plugin.getBubbleManager().bubbleById(bbID);
if (bubble != null) {
AdaptiveImageText<Bubble> adaptiveImageText = AdaptiveImageText.create(
id, inner.getString("text"), bubble, inner.getBoolean("remove-shadow"),
id, inner.getString("text"), bubble, inner.getBoolean("remove-shadow"), !inner.getBoolean("shadow", false),
inner.getInt("left-margin", 1), inner.getInt("right-margin", 1)
);
List<PreParsedDynamicText> list = new ArrayList<>();
@@ -387,7 +402,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
Nameplate nameplate = plugin.getNameplateManager().nameplateById(npID);
if (nameplate != null) {
AdaptiveImageText<Nameplate> adaptiveImageText = AdaptiveImageText.create(
id, inner.getString("text"), nameplate, inner.getBoolean("remove-shadow"),
id, inner.getString("text"), nameplate, inner.getBoolean("remove-shadow"), !inner.getBoolean("shadow", false),
inner.getInt("left-margin", 1), inner.getInt("right-margin", 1)
);
List<PreParsedDynamicText> list = new ArrayList<>();
@@ -425,8 +440,8 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
Background background = plugin.getBackgroundManager().backgroundById(bgID);
if (background != null) {
AdaptiveImageText<Background> adaptiveImageText = AdaptiveImageText.create(
id, inner.getString("text"), background, inner.getBoolean("remove-shadow"),
inner.getInt("left-margin", 2), inner.getInt("right-margin", 0)
id, inner.getString("text"), background, inner.getBoolean("remove-shadow"), !inner.getBoolean("shadow", false),
inner.getInt("left-margin", 1), inner.getInt("right-margin", 1)
);
List<PreParsedDynamicText> list = new ArrayList<>();
list.add(adaptiveImageText.getPreParsedDynamicText());

View File

@@ -52,8 +52,8 @@ public class StorageManagerImpl implements StorageManager, JoinQuitListener {
this.redisManager.getPlayerData(uuid, async).thenAccept(playerData1 -> {
if (playerData1.isPresent()) {
PlayerData data = playerData1.get();
handleDataLoad(player, data);
((AbstractCNPlayer) player).setLoaded(true);
handleDataLoad(player, data);
plugin.getEventManager().dispatch(DataLoadEvent.class, data);
this.redisManager.updatePlayerData(data, async).thenAccept(result -> {
if (!result) {
@@ -64,8 +64,8 @@ public class StorageManagerImpl implements StorageManager, JoinQuitListener {
this.dataSource().getPlayerData(uuid, async).thenAccept(playerData2 -> {
if (playerData2.isPresent()) {
PlayerData data = playerData2.get();
handleDataLoad(player, data);
((AbstractCNPlayer) player).setLoaded(true);
handleDataLoad(player, data);
plugin.getEventManager().dispatch(DataLoadEvent.class, data);
this.redisManager.updatePlayerData(data, async).thenAccept(result -> {
if (!result) {
@@ -82,8 +82,8 @@ public class StorageManagerImpl implements StorageManager, JoinQuitListener {
this.dataSource().getPlayerData(uuid, async).thenAccept(playerData -> {
if (playerData.isPresent()) {
PlayerData data = playerData.get();
handleDataLoad(player, data);
((AbstractCNPlayer) player).setLoaded(true);
handleDataLoad(player, data);
} else {
plugin.getPluginLogger().warn("Failed to load player data for " + player.name());
}

View File

@@ -20,8 +20,15 @@ void main() {
if (color.a < 0.1) {
discard;
}
if (depthLevel == 114514.0) {
discard;
}
if (texColor.a == 254.0/255.0) {
if (depthLevel == 0.00) {
if (depthLevel == 0.0
|| depthLevel == 100
|| depthLevel == 200
|| depthLevel == 400
) {
discard;
} else {
color = vec4(texColor.rgb, 1.0) * vertexColor * ColorModulator;

View File

@@ -20,8 +20,19 @@ void main() {
if (color.a < 0.1) {
discard;
}
if (depthLevel == 114514.0) {
discard;
}
if (texColor.a == 254.0/255.0) {
if (depthLevel == 1000.00) {
if (depthLevel == 1000.0
|| depthLevel == 2200
|| depthLevel == 50
|| depthLevel == 2650
|| depthLevel == 200
|| depthLevel == 400
|| depthLevel == 2800
|| depthLevel == 2400
) {
discard;
} else {
color = vec4(texColor.rgb, 1.0) * vertexColor * ColorModulator;

View File

@@ -56,7 +56,7 @@ resource-pack:
shader:
# Enables shader generation
enable: true
# Hides scoreboard numbers
# Hides scoreboard numbers (1.20.4- requires shader to remove that)
hide-scoreboard-number: false
# Enables support for animated text shaders
animated-text: false

View File

@@ -39,33 +39,47 @@ nameplate-text:
halloween:
nameplate: halloween
text: '<gradient:#FFD700:#FFA500:#FFD700>Today is Halloween! Trick or treat!</gradient>'
left-margin: 1
right-margin: 1
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/background-text
background-text:
location:
background: bedrock_1
text: '%np_image_compass% %np_shift_location%'
remove-shadow: true
shadow: false
left-margin: 1
right-margin: 1
time:
background: bedrock_1
text: '%np_image_clock% %np_shift_time%'
remove-shadow: true
shadow: false
left-margin: 1
right-margin: 1
weather:
background: bedrock_1
text: '%np_image_weather% %np_shift_weather%'
remove-shadow: true
shadow: false
left-margin: 1
right-margin: 1
hello:
background: bedrock_1
text: '%np_image_bubble% %np_shift_hello%'
remove-shadow: true
shadow: false
left-margin: 1
right-margin: 1
update:
background: bedrock_1
text: '%np_image_bell% %np_shift_update%'
remove-shadow: true
shadow: false
left-margin: 1
right-margin: 1
other_actionbar:
background: bedrock_2
text: '%np_actionbar%'
remove-shadow: true
shadow: false
left-margin: 1
right-margin: 1
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/static-text
static-text:
@@ -104,6 +118,34 @@ shift-text:
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/switch-text
switch-text:
nameplate_color_prefix:
switch: "%np_equipped_nameplate%"
default: ""
case:
'wither': "<gradient:#FF0000:#000000:%np_gradient_3%>"
'halloween': "<gradient:#FF0000:#000000:%np_gradient_3%>"
'hutao': "<gradient:#FFFFFF:#FF4500:%np_gradient_3%>"
'rabbit': "<gradient:#FFFFFF:#DB7093:%np_gradient_3%>"
'starsky': "<gradient:#FFFFF0:#696969:%np_gradient_3%>"
'trident': "<gradient:#E1FFFF:#008B8B:%np_gradient_10%>"
'cheems': "<gradient:#C0C0C0:#F5F5F5:%np_gradient_5%>"
'egg': "<gradient:#FFFFFF:#FFA500:%np_gradient_5%>"
'cat': "<gradient:#FFFFFF:#1E90FF:%np_gradient_5%>"
'xmas': "<gradient:#FFFFFF:#FF4500:%np_gradient_5%>"
nameplate_color_suffix:
switch: "%np_equipped_nameplate%"
default: ""
case:
'wither': "</gradient>"
'halloween': "</gradient>"
'hutao': "</gradient>"
'rabbit': "</gradient>"
'starsky': "</gradient>"
'trident': "</gradient>"
'cheems': "</gradient>"
'egg': "</gradient>"
'cat': "</gradient>"
'xmas': "</gradient>"
world:
switch: '%player_world%'
case:

View File

@@ -11,13 +11,13 @@ always-show: false
nameplate:
# Prefix to be displayed before the player's name.
# The prefix here will become part of the nameplate
prefix: ''
prefix: '%np_switch_nameplate_color_prefix%'
# Placeholder for the player's name
# The default configuration uses shift to ensure that the player name not affected by the clientside `force-unicode-font` setting.
player-name: '%np_shift_player_name%'
# Suffix to be displayed after the player's name.
# The suffix here will become part of the nameplate
suffix: ''
suffix: '%np_switch_nameplate_color_suffix%'
# Configuration for Unlimited tags.
unlimited:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 117 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 121 B

View File

@@ -1,16 +1,16 @@
left:
image: b0
height: 14
ascent: 7
ascent: 6
right:
image: b0
height: 14
ascent: 7
ascent: 6
middle:
height: 14
ascent: 7
ascent: 6
1: b1
2: b2
4: b4

View File

@@ -1,16 +1,16 @@
left:
image: b0
height: 14
ascent: 12
ascent: 11
right:
image: b0
height: 14
ascent: 12
ascent: 11
middle:
height: 14
ascent: 12
ascent: 11
1: b1
2: b2
4: b4

View File

@@ -1,6 +1,6 @@
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=3.0.0
project_version=3.0.0-beta-1
config_version=36
project_group=net.momirealms