Skip to content

Commit 614ebe4

Browse files
committed
chore: some map rendering fixes
no circular maps yet :/
1 parent 8b7c474 commit 614ebe4

File tree

17 files changed

+284
-155
lines changed

17 files changed

+284
-155
lines changed

common/src/main/java/dev/ftb/mods/ftbchunks/client/ClientTaskQueue.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ static void runQueuedTasks() {
2727

2828
for (MapTask task : tasks) {
2929
if (task != null) {
30-
try {
31-
task.runMapTask();
32-
} catch (Exception ex) {
33-
FTBChunks.LOGGER.error("Failed to run task " + task);
34-
ex.printStackTrace();
35-
}
30+
tryRunTask(task);
3631
}
3732
}
3833
}
@@ -41,17 +36,20 @@ static void runQueuedTasks() {
4136
public static void flushTasks() {
4237
MapTask task;
4338
while ((task = taskQueue.pollFirst()) != null) {
44-
try {
45-
task.runMapTask();
46-
} catch (Exception ex) {
47-
FTBChunks.LOGGER.error("Failed to run task " + task);
48-
ex.printStackTrace();
49-
}
39+
tryRunTask(task);
40+
}
41+
}
42+
43+
private static void tryRunTask(MapTask task) {
44+
try {
45+
task.runMapTask();
46+
} catch (Exception ex) {
47+
FTBChunks.LOGGER.error("Failed to run task {}: {} ", task, ex.getMessage());
5048
}
5149
}
5250

5351
public static void dumpTaskInfo() {
54-
FTBChunks.LOGGER.info("=== Task Queue: " + taskQueue.size());
52+
FTBChunks.LOGGER.info("=== Task Queue: {}", taskQueue.size());
5553
taskQueue.stream().map(Object::toString).forEach(FTBChunks.LOGGER::info);
5654
FTBChunks.LOGGER.info("===");
5755
}

common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClient.java

Lines changed: 94 additions & 107 deletions
Large diffs are not rendered by default.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dev.ftb.mods.ftbchunks.client;
2+
3+
import com.mojang.blaze3d.pipeline.RenderPipeline;
4+
import com.mojang.blaze3d.platform.DepthTestFunction;
5+
import com.mojang.blaze3d.systems.RenderSystem;
6+
import com.mojang.blaze3d.textures.FilterMode;
7+
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
8+
import com.mojang.blaze3d.vertex.VertexFormat;
9+
import net.minecraft.client.renderer.RenderPipelines;
10+
import net.minecraft.client.renderer.rendertype.LayeringTransform;
11+
import net.minecraft.client.renderer.rendertype.RenderSetup;
12+
import net.minecraft.client.renderer.rendertype.RenderType;
13+
import net.minecraft.resources.Identifier;
14+
import net.minecraft.util.Util;
15+
16+
import java.util.function.Function;
17+
18+
public class ModRenderPipelines {
19+
public static final RenderPipeline.Snippet MASKED_SNIPPET = RenderPipeline.builder(RenderPipelines.MATRICES_PROJECTION_SNIPPET)
20+
.withVertexShader("core/position_tex_color")
21+
.withFragmentShader("core/position_tex_color")
22+
.withVertexFormat(DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS)
23+
.withSampler("Sampler0")
24+
// .withBlend(BlendFunction.TRANSLUCENT)
25+
// .withColorWrite(true)
26+
// .withDepthWrite(true)
27+
.withCull(false)
28+
.buildSnippet();
29+
30+
public static final RenderPipeline MASKED = RenderPipeline.builder(MASKED_SNIPPET)
31+
.withLocation("ftb/pipeline/masked")
32+
.withDepthTestFunction(DepthTestFunction.GREATER_DEPTH_TEST)
33+
.build();
34+
35+
private static final Function<Identifier,RenderType> M = Util.memoize(texture ->
36+
RenderType.create("masked", RenderSetup.builder(MASKED)
37+
.withTexture("Sampler0", texture, () -> RenderSystem.getSamplerCache().getClampToEdge(FilterMode.NEAREST))
38+
.setLayeringTransform(LayeringTransform.NO_LAYERING)
39+
.createRenderSetup())
40+
);
41+
42+
public static RenderType getMaskedRender(Identifier maskTexture) {
43+
return M.apply(maskTexture);
44+
}
45+
}

common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/AddWaypointOverlay.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@
88
import dev.ftb.mods.ftblibrary.client.gui.GuiHelper;
99
import dev.ftb.mods.ftblibrary.client.gui.input.MouseButton;
1010
import dev.ftb.mods.ftblibrary.client.gui.theme.Theme;
11-
import dev.ftb.mods.ftblibrary.client.gui.widget.Button;
12-
import dev.ftb.mods.ftblibrary.client.gui.widget.ColorSelectorPanel;
13-
import dev.ftb.mods.ftblibrary.client.gui.widget.ContextMenuItem;
14-
import dev.ftb.mods.ftblibrary.client.gui.widget.DropDownMenu;
15-
import dev.ftb.mods.ftblibrary.client.gui.widget.IntTextBox;
16-
import dev.ftb.mods.ftblibrary.client.gui.widget.Panel;
17-
import dev.ftb.mods.ftblibrary.client.gui.widget.SimpleButton;
18-
import dev.ftb.mods.ftblibrary.client.gui.widget.SimpleTextButton;
19-
import dev.ftb.mods.ftblibrary.client.gui.widget.TextBox;
11+
import dev.ftb.mods.ftblibrary.client.gui.widget.*;
2012
import dev.ftb.mods.ftblibrary.client.icon.IconHelper;
2113
import dev.ftb.mods.ftblibrary.icon.Color4I;
2214
import dev.ftb.mods.ftblibrary.icon.Icon;
@@ -28,8 +20,8 @@
2820
import net.minecraft.core.GlobalPos;
2921
import net.minecraft.core.registries.Registries;
3022
import net.minecraft.network.chat.Component;
31-
import net.minecraft.resources.ResourceKey;
3223
import net.minecraft.resources.Identifier;
24+
import net.minecraft.resources.ResourceKey;
3325
import net.minecraft.world.level.Level;
3426
import org.jspecify.annotations.Nullable;
3527

@@ -198,7 +190,7 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int
198190
}
199191

200192
private class ColorButton extends SimpleButton {
201-
public ColorButton(Icon icon, Callback c) {
193+
public ColorButton(Color4I icon, Callback c) {
202194
super(AddWaypointOverlay.this, Component.empty(), icon, c);
203195
}
204196

common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/LargeMapScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public boolean mousePressed(MouseButton button) {
270270
}
271271
}).atMousePosition();
272272
overlay.setWidth(150);
273-
overlay.setX(Math.min(overlay.getX(), getScreen().getGuiScaledWidth() - 155));
273+
overlay.setX(Math.min(overlay.getX(), getWindow().getGuiScaledWidth() - 155));
274274
getGui().pushModalPanel(overlay);
275275
}));
276276
openContextMenu(list);

common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/PointerIcon.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import dev.ftb.mods.ftblibrary.icon.Icon;
1111
import net.minecraft.client.Minecraft;
1212
import net.minecraft.client.gui.GuiGraphics;
13+
import net.minecraft.util.Mth;
1314
import net.minecraft.world.entity.player.Player;
1415
import net.minecraft.world.phys.Vec3;
1516

1617
public class PointerIcon implements MapIcon {
17-
18-
private static final Icon<?> POINTER = Icon.getIcon(FTBChunksAPI.id("textures/player.png"));
18+
public static final Icon<?> POINTER = Icon.getIcon(FTBChunksAPI.id("textures/player.png"));
1919

2020
@Override
2121
public Vec3 getPos(float partialTick) {
@@ -40,9 +40,7 @@ public void draw(MapType mapType, GuiGraphics graphics, int x, int y, int w, int
4040
graphics.pose().translate(x + w / 2f, y + h / 2f);
4141
float scale = mapType == MapType.LARGE_MAP ? 2.5F : 2F;
4242
graphics.pose().scale(scale, scale);
43-
// TODO: [21.8] Validate this still works
44-
graphics.pose().rotate(player.getYRot() + 180F);
45-
// graphics.pose().mulPose(Axis.ZP.rotationDegrees(player.getYRot() + 180F));
43+
graphics.pose().rotate((player.getYRot() + 180F) * Mth.DEG_TO_RAD);
4644
IconHelper.renderIcon(POINTER, graphics, - w / 2, -h / 2, w, h);
4745
graphics.pose().popMatrix();
4846
}

common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ protected void doAccept() {
8888

8989
@Override
9090
public boolean onInit() {
91-
setWidth(Mth.clamp(widestWaypoint + 80, 220, getScreen().getGuiScaledWidth() * 4 / 5));
92-
setHeight(getScreen().getGuiScaledHeight() * 4 / 5);
91+
setWidth(Mth.clamp(widestWaypoint + 80, 220, getWindow().getGuiScaledWidth() * 4 / 5));
92+
setHeight(getWindow().getGuiScaledHeight() * 4 / 5);
9393

9494
for (Map.Entry<ResourceKey<Level>, List<WaypointImpl>> resourceKeyListEntry : collectWaypoints().entrySet()) {
9595
collapsed.put(resourceKeyListEntry.getKey(), false);

common/src/main/java/dev/ftb/mods/ftbchunks/client/map/WaypointType.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class WaypointType {
1414
= WaypointType.builder().build("death");
1515

1616
private final String id;
17-
private final Icon icon;
18-
private final Icon outsideIcon;
17+
private final Icon<?> icon;
18+
private final Icon<?> outsideIcon;
1919
private final boolean canChangeColor;
2020

2121
public static Builder builder() {
@@ -38,28 +38,28 @@ public String getId() {
3838
return id;
3939
}
4040

41-
public Icon getOutsideIcon() {
41+
public Icon<?> getOutsideIcon() {
4242
return outsideIcon;
4343
}
4444

4545
public boolean canChangeColor() {
4646
return canChangeColor;
4747
}
4848

49-
public Icon getIcon() {
49+
public Icon<?> getIcon() {
5050
return icon;
5151
}
5252

5353
public static class Builder {
54-
private Icon outsideIcon = null;
54+
private Icon<?> outsideIcon = null;
5555
private boolean canChangeColor = false;
5656

5757
public Builder withOutsideIcon(String icon) {
5858
outsideIcon = Icon.getIcon(icon);
5959
return this;
6060
}
6161

62-
public Builder withOutsideIcon(Icon icon) {
62+
public Builder withOutsideIcon(Icon<?> icon) {
6363
outsideIcon = icon;
6464
return this;
6565
}

common/src/main/java/dev/ftb/mods/ftbchunks/client/mapicon/EntityMapIcon.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public class EntityMapIcon implements MapIcon {
2323
private final Icon<?> icon;
2424
private final EntityIconLoader.WidthHeight widthHeight;
2525

26-
public EntityMapIcon(Entity entity, Icon icon) {
26+
public EntityMapIcon(Entity entity, Icon<?> icon) {
2727
this.entity = entity;
2828
this.icon = icon;
2929
this.widthHeight = new EntityIconLoader.WidthHeight(16, 16);
3030
}
3131

32-
public EntityMapIcon(Entity entity, Icon icon, EntityIconLoader.WidthHeight widthHeight) {
32+
public EntityMapIcon(Entity entity, Icon<?> icon, EntityIconLoader.WidthHeight widthHeight) {
3333
this.entity = entity;
3434
this.icon = icon;
3535
this.widthHeight = widthHeight;

common/src/main/java/dev/ftb/mods/ftbchunks/client/mapicon/WaypointMapIcon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
public class WaypointMapIcon extends StaticMapIcon implements WaypointIcon {
3636
private final WaypointImpl waypoint;
37-
private Icon outsideIcon;
37+
private Icon<?> outsideIcon;
3838
private int alpha;
3939

4040
public WaypointMapIcon(WaypointImpl waypoint) {

0 commit comments

Comments
 (0)