Skip to content

Commit 22dee92

Browse files
committed
Make player icon toggleable + add arrow indicating player direction
1 parent 46ca919 commit 22dee92

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

src/main/java/dev/xpple/seedmapper/command/commands/SeedMapCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private static int seedMap(CustomClientCommandSource source) throws CommandSynta
2020
long seed = source.getSeed().getSecond();
2121
int dimension = source.getDimension();
2222
int version = source.getVersion();
23-
source.getClient().schedule(() -> source.getClient().setScreen(new SeedMapScreen(seed, dimension, version, BlockPos.containing(source.getPosition()))));
23+
source.getClient().schedule(() -> source.getClient().setScreen(new SeedMapScreen(seed, dimension, version, BlockPos.containing(source.getPosition()), source.getRotation())));
2424
return Command.SINGLE_SUCCESS;
2525
}
2626
}

src/main/java/dev/xpple/seedmapper/seedmap/MapFeature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public Texture getVariantTexture(WorldIdentifier identifier, int posX, int posZ,
106106
SLIME_CHUNK("slime_chunk", -1, Cubiomes.DIM_OVERWORLD(), Cubiomes.MC_B1_7(), "feature_icons", 20, 20),
107107
WORLD_SPAWN("world_spawn", -1, Cubiomes.DIM_OVERWORLD(), Cubiomes.MC_B1_7(), "cubiomes_viewer_icons", 20, 20),
108108
WAYPOINT("waypoint", -1, Cubiomes.DIM_UNDEF(), Cubiomes.MC_B1_7(), "feature_icons", 20, 20),
109+
PLAYER_ICON("player_icon", -1, Cubiomes.DIM_UNDEF(), Cubiomes.MC_B1_7(), "feature_icons", 20, 20),
109110
;
110111

111112
public static final Map<String, MapFeature> BY_NAME = Arrays.stream(values())

src/main/java/dev/xpple/seedmapper/seedmap/SeedMapScreen.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import net.minecraft.world.level.levelgen.PositionalRandomFactory;
7979
import net.minecraft.world.level.levelgen.WorldgenRandom;
8080
import net.minecraft.world.level.levelgen.XoroshiroRandomSource;
81+
import net.minecraft.world.phys.Vec2;
8182
import org.jetbrains.annotations.Nullable;
8283
import org.joml.Matrix3x2f;
8384

@@ -194,6 +195,7 @@ public class SeedMapScreen extends Screen {
194195
private final SeedMapCache<TilePos, BitSet> slimeChunkCache;
195196

196197
private final BlockPos playerPos;
198+
private final Vec2 playerRotation;
197199

198200
private QuartPos2f centerQuart;
199201

@@ -219,9 +221,11 @@ public class SeedMapScreen extends Screen {
219221
private @Nullable FeatureWidget markerWidget = null;
220222
private @Nullable ChestLootWidget chestLootWidget = null;
221223

224+
private static final ResourceLocation DIRECTION_ARROW_TEXTURE = ResourceLocation.fromNamespaceAndPath(SeedMapper.MOD_ID, "textures/gui/arrow.png");
225+
222226
private Registry<Enchantment> enchantmentsRegistry;
223227

224-
public SeedMapScreen(long seed, int dimension, int version, BlockPos playerPos) {
228+
public SeedMapScreen(long seed, int dimension, int version, BlockPos playerPos, Vec2 playerRotation) {
225229
super(Component.empty());
226230
this.seed = seed;
227231
this.dimension = dimension;
@@ -292,6 +296,7 @@ public SeedMapScreen(long seed, int dimension, int version, BlockPos playerPos)
292296
.orElseThrow();
293297

294298
this.playerPos = playerPos;
299+
this.playerRotation = playerRotation;
295300

296301
this.centerQuart = QuartPos2f.fromQuartPos(QuartPos2.fromBlockPos(this.playerPos));
297302
this.mouseQuart = QuartPos2.fromQuartPos2f(this.centerQuart);
@@ -453,13 +458,27 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
453458
}
454459

455460
// draw player position
456-
QuartPos2f relPlayerQuart = QuartPos2f.fromQuartPos(QuartPos2.fromBlockPos(this.playerPos)).subtract(this.centerQuart);
457-
int playerMinX = this.centerX + Mth.floor(Configs.PixelsPerBiome * relPlayerQuart.x()) - 10;
458-
int playerMinY = this.centerY + Mth.floor(Configs.PixelsPerBiome * relPlayerQuart.z()) - 10;
459-
int playerMaxX = playerMinX + 20;
460-
int playerMaxY = playerMinY + 20;
461-
if (playerMinX >= HORIZONTAL_PADDING && playerMaxX <= HORIZONTAL_PADDING + this.seedMapWidth && playerMinY >= VERTICAL_PADDING && playerMaxY <= VERTICAL_PADDING + this.seedMapHeight) {
462-
PlayerFaceRenderer.draw(guiGraphics, this.minecraft.player.getSkin(), playerMinX, playerMinY, 20);
461+
if (this.toggleableFeatures.contains(MapFeature.PLAYER_ICON) && Configs.ToggledFeatures.contains(MapFeature.PLAYER_ICON)) {
462+
QuartPos2f relPlayerQuart = QuartPos2f.fromQuartPos(QuartPos2.fromBlockPos(this.playerPos)).subtract(this.centerQuart);
463+
int playerMinX = this.centerX + Mth.floor(Configs.PixelsPerBiome * relPlayerQuart.x()) - 10;
464+
int playerMinY = this.centerY + Mth.floor(Configs.PixelsPerBiome * relPlayerQuart.z()) - 10;
465+
int playerMaxX = playerMinX + 20;
466+
int playerMaxY = playerMinY + 20;
467+
if (playerMinX >= HORIZONTAL_PADDING && playerMaxX <= HORIZONTAL_PADDING + this.seedMapWidth && playerMinY >= VERTICAL_PADDING && playerMaxY <= VERTICAL_PADDING + this.seedMapHeight) {
468+
PlayerFaceRenderer.draw(guiGraphics, this.minecraft.player.getSkin(), playerMinX, playerMinY, 20);
469+
}
470+
471+
// draw player direction arrow
472+
guiGraphics.pose().pushMatrix();
473+
guiGraphics.pose() // transformations are applied in reverse order
474+
.translate(10, 10)
475+
.translate(playerMinX, playerMinY)
476+
.rotate((float) (Math.toRadians(this.playerRotation.y) + Math.PI))
477+
.translate(-10, -10)
478+
.translate(0, -30)
479+
;
480+
drawIcon(guiGraphics, DIRECTION_ARROW_TEXTURE, 0, 0, 20, 20, 0xFF_FFFFFF);
481+
guiGraphics.pose().popMatrix();
463482
}
464483

465484
// calculate spawn point
@@ -1125,15 +1144,19 @@ static void drawFeatureIcon(GuiGraphics guiGraphics, MapFeature.Texture texture,
11251144
int iconWidth = texture.width();
11261145
int iconHeight = texture.height();
11271146

1128-
// Skip intersection checks (GuiRenderState.hasIntersection) you would otherwise get when calling
1129-
// GuiGraphics.blit(RenderPipeline, ResourceLocation, int, int, float, float, int, int, int, int, int)
1130-
// as these checks incur a significant performance hit
1131-
GpuTextureView gpuTextureView = Minecraft.getInstance().getTextureManager().getTexture(texture.resourceLocation()).getTextureView();
1132-
BlitRenderState renderState = new BlitRenderState(RenderPipelines.GUI_TEXTURED, TextureSetup.singleTexture(gpuTextureView), new Matrix3x2f(guiGraphics.pose()), minX, minY, minX + iconWidth, minY + iconHeight, 0, 1, 0, 1, colour, guiGraphics.scissorStack.peek());
1133-
guiGraphics.guiRenderState.submitBlitToCurrentLayer(renderState);
1147+
drawIcon(guiGraphics, texture.resourceLocation(), minX, minY, iconWidth, iconHeight, colour);
11341148
}
11351149
}
11361150

1151+
private static void drawIcon(GuiGraphics guiGraphics, ResourceLocation resourceLocation, int minX, int minY, int iconWidth, int iconHeight, int colour) {
1152+
// Skip intersection checks (GuiRenderState.hasIntersection) you would otherwise get when calling
1153+
// GuiGraphics.blit(RenderPipeline, ResourceLocation, int, int, float, float, int, int, int, int, int)
1154+
// as these checks incur a significant performance hit
1155+
GpuTextureView gpuTextureView = Minecraft.getInstance().getTextureManager().getTexture(resourceLocation).getTextureView();
1156+
BlitRenderState renderState = new BlitRenderState(RenderPipelines.GUI_TEXTURED, TextureSetup.singleTexture(gpuTextureView), new Matrix3x2f(guiGraphics.pose()), minX, minY, minX + iconWidth, minY + iconHeight, 0, 1, 0, 1, colour, guiGraphics.scissorStack.peek());
1157+
guiGraphics.guiRenderState.submitBlitToCurrentLayer(renderState);
1158+
}
1159+
11371160
private static final BiMap<Integer, ResourceKey<Level>> DIM_ID_TO_MC = ImmutableBiMap.of(
11381161
Cubiomes.DIM_OVERWORLD(), Level.OVERWORLD,
11391162
Cubiomes.DIM_NETHER(), Level.NETHER,
420 Bytes
Loading
736 Bytes
Loading

0 commit comments

Comments
 (0)