Skip to content

Commit 4abbd16

Browse files
committed
More options are added.
Fix project problems. Version up.
1 parent 73aa761 commit 4abbd16

13 files changed

Lines changed: 107 additions & 55 deletions

File tree

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ loader_version_range=[4,)
1616
mod_id=the_trackers
1717
mod_name=The Trackers
1818
mod_license=LGPLv3
19-
mod_version=1.21.1-0.2.1
19+
mod_version=1.21.1-0.2.3
2020
mod_group_id=nowebsite.makertechno.the_trackers
2121
mod_authors=MakerTechno
2222
mod_description=To follow the light to where all shadows begin.
2323

24+

src/main/java/nowebsite/makertechno/the_trackers/api/component/ComponentBuilder.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import nowebsite.makertechno.the_trackers.core.tool.TextureBuildTool;
1010

1111
import javax.annotation.Nullable;
12+
import java.util.function.Function;
1213
import java.util.function.Supplier;
1314

1415
/**
@@ -17,15 +18,17 @@
1718
@SuppressWarnings("unused")
1819
public class ComponentBuilder {
1920
private ComponentType type = ComponentType.DIRECT;
20-
private String cursorPattern;
21+
private String cursorPattern = null;
2122
private Supplier<Icon> icon1 = () -> Icon.NONE;
2223
private String component1Pattern = null;
2324
private Supplier<Icon> icon2 = () -> Icon.NONE;
2425
private String component2Pattern = null;
2526
private Supplier<Icon> icon3 = () -> Icon.NONE;
2627
private String component3Pattern = null;
2728
private boolean isSmoothMove = false;
29+
private boolean affectedByPlayerSettingsScale = false;
2830
private boolean autoLifecycle = false;
31+
private Function<Float, Float> definedScaleMultiple = scale -> scale;
2932

3033

3134
public ComponentBuilder() {}
@@ -138,18 +141,34 @@ public ComponentBuilder setIcon3Pattern(String pattern) {
138141
/**
139142
* 设置是否启用插值帧移动。
140143
*/
141-
public void setSmoothMove(boolean smoothMove) {
144+
public ComponentBuilder setSmoothMove(boolean smoothMove) {
142145
isSmoothMove = smoothMove;
146+
return this;
147+
}
148+
149+
/**
150+
* 设置是否受到用户设置大小的影响。
151+
*/
152+
public ComponentBuilder setAffectedByPlayerSettingsScale(boolean affectedByPlayerSettingsScale) {
153+
this.affectedByPlayerSettingsScale = affectedByPlayerSettingsScale;
154+
return this;
143155
}
144156

145157
/**
146158
* 设置是否自动管理生命周期。仅对实体类指针生效,当实体不再扫描到时清理指针。
147159
*/
148-
public void setAutoLifecycle(boolean autoLifecycle) {
160+
public ComponentBuilder setAutoLifecycle(boolean autoLifecycle) {
149161
this.autoLifecycle = autoLifecycle;
162+
return this;
150163
}
151164

152-
165+
/**
166+
* 设置乘数再运算器,一般建议在这里对最终大小进行区间移动和缩放。
167+
* */
168+
public ComponentBuilder defineScaleMultiple(Function<Float, Float> definedScaleMultipleApplier) {
169+
this.definedScaleMultiple = definedScaleMultipleApplier;
170+
return this;
171+
}
153172

154173
public BuilderResult build() {
155174
return new BuilderResult(
@@ -162,7 +181,9 @@ public BuilderResult build() {
162181
component3Pattern,
163182
cursorPattern,
164183
isSmoothMove,
165-
autoLifecycle
184+
autoLifecycle,
185+
affectedByPlayerSettingsScale,
186+
definedScaleMultiple
166187
);
167188
}
168189

@@ -174,7 +195,8 @@ public static final class BuilderResult {
174195
public final @Nullable String component1Pattern, component2Pattern, component3Pattern, cursorPattern;
175196
public final ComponentType type;
176197
public final Supplier<Icon> icon1, icon2, icon3;
177-
public final boolean isSmoothMove, autoLifecycle;
198+
public final boolean isSmoothMove, autoLifecycle, affectedBySettings;
199+
public final Function<Float, Float> multiple;
178200
private BuilderResult(
179201
ComponentType type,
180202
Supplier<Icon> icon1,
@@ -185,7 +207,9 @@ private BuilderResult(
185207
@Nullable String component3Pattern,
186208
@Nullable String cursorPattern,
187209
boolean isSmoothMove,
188-
boolean autoLifecycle
210+
boolean autoLifecycle,
211+
boolean affectedBySettings,
212+
Function<Float, Float> multiple
189213
) {
190214
this.type = type;
191215
this.icon1 = icon1;
@@ -197,6 +221,8 @@ private BuilderResult(
197221
this.cursorPattern = cursorPattern;
198222
this.isSmoothMove = isSmoothMove;
199223
this.autoLifecycle = autoLifecycle;
224+
this.affectedBySettings = affectedBySettings;
225+
this.multiple = multiple;
200226
}
201227
}
202228

src/main/java/nowebsite/makertechno/the_trackers/api/examples/TestAdd1.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
import nowebsite.makertechno.the_trackers.core.track.WorldSingletonTracker;
1616

1717
//@EventBusSubscriber(Dist.CLIENT)
18+
/** An example adding death point tag to world. */
1819
public class TestAdd1 {
1920
private static final ComponentBuilder.BuilderResult posTo0 = new ComponentBuilder()
2021
.setComponentType(ComponentBuilder.ComponentType.DIRECT)
2122
.setIcon1(Items.DIAMOND)
2223
.setIcon1Pattern("rainbow:2")
24+
.defineScaleMultiple(scale -> (float) (1F + Math.min(scale / 2.2, 1f) * Math.min(scale / 2.2, 1f)))
25+
.setSmoothMove(true)
2326
.build();
2427

2528
private static Vec3 pos;

src/main/java/nowebsite/makertechno/the_trackers/client/gui/components/TAbstractCursor.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77
import net.minecraft.world.phys.Vec3;
88
import nowebsite.makertechno.the_trackers.core.config.TConfig;
99

10+
import java.util.function.Function;
11+
1012
public abstract class TAbstractCursor implements TRenderComponent{
1113

1214
protected float scaleCached;
13-
protected float definedScale;
1415
protected boolean smoothMove = true;
1516
protected boolean affectedByPlayerScale = true;
17+
protected Function<Float, Float> multiple = scale -> scale ;
1618

17-
protected TAbstractCursor(float definedScale) {
18-
this.scaleCached = (float) TConfig.scale;
19-
this.definedScale = definedScale;
20-
}
2119
protected TAbstractCursor() {
22-
this(1F);
20+
this.scaleCached = (float) TConfig.scale;
2321
}
2422

2523
public void setSmoothMove(boolean smoothMove) {
@@ -30,6 +28,10 @@ public void setAffectedByPlayerScale(boolean affectedByPlayerScale) {
3028
this.affectedByPlayerScale = affectedByPlayerScale;
3129
}
3230

31+
public void setMultiple(Function<Float, Float> multiple) {
32+
this.multiple = multiple;
33+
}
34+
3335
@Override
3436
public void flush() {
3537
this.scaleCached = (float) TConfig.scale;
@@ -40,15 +42,17 @@ public void render(GuiGraphics graphics, Player player, Vec3 target, float parti
4042

4143
float[] projScrPoint = getProjectScr(graphics, player, target);
4244

43-
float scale = (affectedByPlayerScale ? scaleCached : 1) * definedScale;
45+
float scale = multiple.apply(calculateScale(projScrPoint));
4446

4547
updateTransformer(projScrPoint, partialTick, scale);
4648
RenderSystemInit(getAlpha(projScrPoint));
4749
renderInsights(graphics, projScrPoint, partialTick, scale);
4850
RenderSystemRestore();
4951
}
50-
5152
protected abstract float[] getProjectScr(GuiGraphics graphics, Player player, Vec3 target);
53+
protected float calculateScale(float[] projScrPoint) {
54+
return affectedByPlayerScale ? scaleCached : 1;
55+
}
5256
protected abstract void updateTransformer(float[] projScrPoint, float partialTick, float scale);
5357
protected abstract float getAlpha(float[] projScrPoint);
5458
protected abstract void renderInsights(GuiGraphics graphics, float[] projScrPoint, float partialTick, float scale);

src/main/java/nowebsite/makertechno/the_trackers/client/gui/components/TDir3BodyCursor.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ public TDir3BodyCursor(IconComponent component1, IconComponent component2, IconC
4242
this.component3 = component3;
4343
}
4444

45-
public TDir3BodyCursor(IconComponent component1, IconComponent component2, IconComponent component3, float definedScale) {
46-
super(component1, definedScale);
47-
this.component2 = component2;
48-
this.component3 = component3;
49-
}
50-
5145
public void setFaceCenter(boolean shouldFaceCenter) {
5246
this.shouldFaceCenter = shouldFaceCenter;
5347
}

src/main/java/nowebsite/makertechno/the_trackers/client/gui/components/TDirectProjCursor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ public TDirectProjCursor(IconComponent component) {
5151
this.component = component;
5252
}
5353

54-
public TDirectProjCursor(IconComponent component, float definedScale) {
55-
super(definedScale);
56-
this.component = component;
57-
}
58-
5954
@Override
6055
public void flush() {
6156
super.flush();
@@ -73,6 +68,11 @@ public void flush() {
7368
);
7469
}
7570

71+
@Override
72+
protected float calculateScale(float[] projScrPoint) {
73+
return super.calculateScale(projScrPoint) / projScrPoint[3] * 15;
74+
}
75+
7676
protected void updateTransformer(float[] projScrPoint, float partialTick, float scale) {
7777
if (smoothMove) transformer.makeSmooth(projScrPoint[0], projScrPoint[1], partialTick);
7878
else transformer.set(projScrPoint[0], projScrPoint[1]);
@@ -84,7 +84,6 @@ protected float getAlpha(float[] projScrPoint) {
8484
}
8585

8686
protected void renderInsights(GuiGraphics graphics, float[] projScrPoint, float partialTick, float scale) {
87-
scale = scale / projScrPoint[3] * 15;
8887
Matrix4fStack matrix4fStack = RenderSystem.getModelViewStack();
8988
matrix4fStack.pushMatrix();
9089
translateAndRenderComponents(graphics, component, matrix4fStack, partialTick, scale);

src/main/java/nowebsite/makertechno/the_trackers/client/gui/components/TRelativeCursor.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ public TRelativeCursor(IconComponent pointerIconComponent, IconComponent entityI
4545
this.entityIconComponent = entityIconComponent;
4646
}
4747

48-
public TRelativeCursor(IconComponent pointerIconComponent, IconComponent entityIconComponent, float definedScale) {
49-
super(definedScale);
50-
this.pointerIconComponent = pointerIconComponent;
51-
this.entityIconComponent = entityIconComponent;
52-
}
53-
5448
@Override
5549
public void flush() {
5650
super.flush();

src/main/java/nowebsite/makertechno/the_trackers/client/gui/components/TRenderComponent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
import org.jetbrains.annotations.Contract;
77
import org.jetbrains.annotations.Nullable;
88

9+
import java.util.function.Function;
10+
911
public interface TRenderComponent {
12+
void setSmoothMove(boolean smoothMove);
13+
void setAffectedByPlayerScale(boolean affectedByPlayerScale);
14+
void setMultiple(Function<Float, Float> multiple);
1015
void flush();
1116
void render(GuiGraphics graphics, Player player, Vec3 target, float partialTick);
1217
@Contract(pure = true)

src/main/java/nowebsite/makertechno/the_trackers/client/gui/provider/BuilderResultComposer.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,47 @@ public final class BuilderResultComposer {
1111
private BuilderResultComposer() {}
1212

1313
public static TRenderComponent compose(ComponentBuilder.BuilderResult result) {
14-
return switch (result.type) {
14+
TRenderComponent component = switch (result.type) {
1515
case RELATIVE -> composeRelativeComponent(result);
1616
case DIRECT -> composeDirectComponent(result);
1717
case HEAD_TAG -> composeRelativeComponent(result); // TODO
1818
};
19+
component.setSmoothMove(result.isSmoothMove);
20+
component.setAffectedByPlayerScale(result.affectedBySettings);
21+
component.setMultiple(result.multiple);
22+
return component;
1923
}
2024

2125
public static TRenderComponent composeRelativeComponent(ComponentBuilder.BuilderResult result) {
22-
TRelativeCursor cursor = new TRelativeCursor(getIconComponent(result.component1Pattern, result.icon1.get()), getIconComponent(result.component2Pattern, result.icon2.get()));
23-
cursor.setSmoothMove(result.isSmoothMove);
24-
return cursor;
26+
return new TRelativeCursor(
27+
getIconComponent(result.component1Pattern, result.icon1.get()),
28+
getIconComponent(result.component2Pattern, result.icon2.get())
29+
);
2530
}
2631

2732
public static TRenderComponent composeDirectComponent(ComponentBuilder.BuilderResult result) {
2833
TAbstractCursor cursor;
29-
if (result.cursorPattern != null && result.cursorPattern.equals("3body"))
30-
cursor = new TDir3BodyCursor(
31-
getIconComponent(result.component1Pattern, result.icon1.get()),
32-
getIconComponent(result.component2Pattern, result.icon2.get()),
33-
getIconComponent(result.component3Pattern, result.icon3.get())
34-
);
34+
if (result.cursorPattern != null) {
35+
String[] patterns = result.cursorPattern.split(",");
36+
if (patterns[0].equals("3body")) {
37+
if (result.component2Pattern == null){
38+
cursor = new TDir3BodyCursor(
39+
getIconComponent(result.component1Pattern, result.icon1.get()),
40+
getIconComponent(result.component1Pattern, result.icon1.get()),
41+
getIconComponent(result.component1Pattern, result.icon1.get())
42+
);
43+
} else {
44+
cursor = new TDir3BodyCursor(
45+
getIconComponent(result.component1Pattern, result.icon1.get()),
46+
getIconComponent(result.component2Pattern, result.icon2.get()),
47+
getIconComponent(result.component3Pattern, result.icon3.get())
48+
);
49+
}
50+
if (patterns.length > 1 && patterns[1].equals("faceCenter")) ((TDir3BodyCursor)cursor).setFaceCenter(true);
51+
}
52+
else cursor = new TDirectProjCursor(getIconComponent(result.component1Pattern, result.icon1.get()));
53+
}
3554
else cursor = new TDirectProjCursor(getIconComponent(result.component1Pattern, result.icon1.get()));
36-
cursor.setSmoothMove(result.isSmoothMove);
3755
return cursor;
3856
}
3957
/*public static TRenderComponent composeHeadTagComponent(ComponentBuilder.BuilderResult result) {

src/main/java/nowebsite/makertechno/the_trackers/core/config/TConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class TConfig {
5656
private static final ModConfigSpec.BooleanValue HEAD_FLAT_AVAILABLE = BUILDER
5757
.comment("Enable longitude icon display")
5858
.translation("the_trackers.configuration.head_flat_available")
59-
.define("Head flat available", true);
59+
.define("Head flat available", false);
6060

6161

6262
public static final ModConfigSpec.ConfigValue<List<? extends String>> CENTER_RELATIVE_BIND = BUILDER

0 commit comments

Comments
 (0)