diff --git a/.gitignore b/.gitignore index 0a19299..3914a4a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ bin/ eclipse/ run_client/ run_server/ +run_test/ logs/ remappedSrc/ diff --git a/build.gradle b/build.gradle index 35c5207..cc1672d 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'eclipse' id 'maven-publish' id 'net.minecraftforge.gradle' version '5.1.+' + id 'org.parchmentmc.librarian.forgegradle' version '1.+' } apply from: 'gradle/teacon-forge.gradle' @@ -17,8 +18,8 @@ teacon { modAuthors = ['3TUSK', 'yuesha-yc (YueSha)', 'Hookan', 'ustc-zzzz'] modDescription = 'Sign up, sign in, in-game guide map and more.' - platform = 'forge-1.19.4-45.0.9' - // parchment = '2022.01.23' + platform = 'forge-1.20.1-47.1.0' + parchment = '2023.07.23' // uncomment these lines if you need modName = 'Sign Me Up' // default to repo name diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e6de80b --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +org.gradle.jvmargs=-Xmx5G +org.gradle.daemon=false diff --git a/settings.gradle b/settings.gradle index d38dd75..8731d47 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,7 @@ pluginManagement.repositories { gradlePluginPortal() maven { url = 'https://maven.minecraftforge.net/' } + maven { url = 'https://maven.parchmentmc.org' } } rootProject.name = 'SignMeUp' diff --git a/src/main/java/org/teacon/signin/client/GuideMapScreen.java b/src/main/java/org/teacon/signin/client/GuideMapScreen.java index 417a4be..09d94e5 100644 --- a/src/main/java/org/teacon/signin/client/GuideMapScreen.java +++ b/src/main/java/org/teacon/signin/client/GuideMapScreen.java @@ -9,6 +9,7 @@ import com.mojang.datafixers.util.Pair; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.ImageButton; import net.minecraft.client.gui.screens.Screen; @@ -167,8 +168,8 @@ protected void init() { mapCanvasX + wpX - 2, mapCanvasY + wpY - 2, 4, 4, 58, 2, 0, MAP_ICONS, 128, 128, (btn) -> this.selectedWaypoint = wpId, wp.getTitle()) { @Override - public void renderWidget(PoseStack transforms, int mouseX, int mouseY, float partialTicks) { - super.renderWidget(transforms, mouseX, mouseY, partialTicks); + public void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) { + super.renderWidget(pGuiGraphics, pMouseX, pMouseY, pPartialTick); if (this.isHovered()) { double distance = Math.sqrt(wp.getActualLocation().distToCenterSqr(GuideMapScreen.this.playerLocation)); GuideMapScreen.this.queuedTips.offer(Pair.of(wp.getTitle(), GuideMapScreen.this.toDistanceText(distance))); @@ -226,21 +227,21 @@ private Component toDistanceText(double distance) { } @Override - public void render(PoseStack transforms, int mouseX, int mouseY, float partialTicks) { + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { int x0 = (this.width - X_SIZE) / 2, y0 = (this.height - Y_SIZE) / 2, x1 = x0 + 206; - this.renderBackground(transforms); - this.renderBackgroundTexture(transforms, x0, y0, x1); - this.renderWaypointTexture(transforms, x0, y0, x1, partialTicks); - this.renderMapTexture(transforms, x0, y0, x1); + this.renderBackground(guiGraphics); + this.renderBackgroundTexture(guiGraphics, x0, y0, x1); + this.renderWaypointTexture(guiGraphics, x0, y0, x1, partialTick); + this.renderMapTexture(guiGraphics, x0, y0, x1); - super.render(transforms, mouseX, mouseY, partialTicks); + super.render(guiGraphics, mouseX, mouseY, partialTick); - this.renderPlayerHeads(transforms, mouseX, mouseY, x0, y0, x1); - this.renderTextCollection(transforms, mouseX, mouseY, x0, y0, x1); + this.renderPlayerHeads(guiGraphics, mouseX, mouseY, x0, y0, x1); + this.renderTextCollection(guiGraphics, mouseX, mouseY, x0, y0, x1); } - private void renderTextCollection(PoseStack transforms, int mouseX, int mouseY, int x0, int y0, int x1) { + private void renderTextCollection(GuiGraphics guiGraphics, int mouseX, int mouseY, int x0, int y0, int x1) { // Display the subtitle/desc of the map if no waypoint is selected Component title = this.map.getTitle(), subtitle = this.map.getSubtitle(), desc = this.map.getDesc(); if (this.selectedWaypoint != null) { @@ -252,9 +253,9 @@ private void renderTextCollection(PoseStack transforms, int mouseX, int mouseY, } // Draw title and subtitle depending on whether a waypoint is selected final int xTitle = x0 + 142 - font.width(title) / 2; - font.draw(transforms, title, xTitle, y0 + 7F, 0x404040); + guiGraphics.drawString(font, title, xTitle, y0 + 7, 0x404040, false); final int xSubtitle = x1 + 56 - font.width(subtitle) / 2; - font.draw(transforms, subtitle, xSubtitle, y0 + 7F, 0x404040); + guiGraphics.drawString(font, subtitle, xSubtitle, y0 + 7, 0x404040, false); // I DISLIKE THIS METHOD BECAUSE IT FAILS TO HANDLE LINE BREAKING // A proper line breaking algorithm should comply with UAX #14, link below: // http://www.unicode.org/reports/tr14/ @@ -262,7 +263,7 @@ private void renderTextCollection(PoseStack transforms, int mouseX, int mouseY, List displayedDescList = font.split(desc, 90); // Draw desc text for (int i = 0, size = Math.min(8, displayedDescList.size()); i < size; ++i) { - font.draw(transforms, displayedDescList.get(i), x1 + 10F, y0 + 81F + 9 * i, 0x404040); + guiGraphics.drawString(font, displayedDescList.get(i), x1 + 10, y0 + 81 + 9 * i, 0x404040, false); } List tooltipTexts = new ArrayList<>(this.queuedTips.size() * 2 + 1); for (Pair pair = this.queuedTips.poll(); pair != null; pair = this.queuedTips.poll()) { @@ -273,11 +274,11 @@ private void renderTextCollection(PoseStack transforms, int mouseX, int mouseY, tooltipTexts.add(pair.getSecond()); } if (!tooltipTexts.isEmpty()) { - this.renderComponentTooltip(transforms, tooltipTexts, mouseX, mouseY); + guiGraphics.renderComponentTooltip(font, tooltipTexts, mouseX, mouseY); } } - private void renderPlayerHeads(PoseStack transforms, int mouseX, int mouseY, int x0, int y0, int x1) { + private void renderPlayerHeads(GuiGraphics guiGraphics, int mouseX, int mouseY, int x0, int y0, int x1) { Minecraft mc = Objects.requireNonNull(this.minecraft); List players = mc.level == null ? List.of() : mc.level.players(); @@ -300,14 +301,14 @@ private void renderPlayerHeads(PoseStack transforms, int mouseX, int mouseY, int // make sure that current player is rendered at last for (int i = currentIndex - 1; i >= 0; --i) { - this.renderPlayerHead(transforms, mouseX, mouseY, x0, y0, players.get(i), outputX[i], outputY[i]); + this.renderPlayerHead(guiGraphics, mouseX, mouseY, x0, y0, players.get(i), outputX[i], outputY[i]); } for (int i = size - 1; i >= currentIndex; --i) { - this.renderPlayerHead(transforms, mouseX, mouseY, x0, y0, players.get(i), outputX[i], outputY[i]); + this.renderPlayerHead(guiGraphics, mouseX, mouseY, x0, y0, players.get(i), outputX[i], outputY[i]); } } - private void renderPlayerHead(PoseStack transforms, + private void renderPlayerHead(GuiGraphics guiGraphics, int mouseX, int mouseY, int x0, int y0, Player player, double outputX, double outputY) { int wpX = Math.round((float) outputX / this.map.radius * 64) + 64; @@ -315,11 +316,9 @@ private void renderPlayerHead(PoseStack transforms, if (wpX >= 1 && wpX <= 127 && wpY >= 1 && wpY <= 127) { // could we have dinnerbone or grumm joined our server? if (LivingEntityRenderer.isEntityUpsideDown(player)) { - RenderSystem.setShaderTexture(0, DefaultPlayerSkin.getDefaultSkin(player.getUUID())); - blit(transforms, x0 + 76 + wpX, y0 + 21 + wpY, 4, 4, 8, 16, 8, -8, 64, 64); + guiGraphics.blit(DefaultPlayerSkin.getDefaultSkin(player.getUUID()), x0 + 76 + wpX, y0 + 21 + wpY, 4, 4, 8, 16, 8, -8, 64, 64); } else { - RenderSystem.setShaderTexture(0, DefaultPlayerSkin.getDefaultSkin(player.getUUID())); - blit(transforms, x0 + 76 + wpX, y0 + 21 + wpY, 4, 4, 8, 8, 8, 8, 64, 64); + guiGraphics.blit(DefaultPlayerSkin.getDefaultSkin(player.getUUID()), x0 + 76 + wpX, y0 + 21 + wpY, 4, 4, 8, 8, 8, 8, 64, 64); } if (mouseX >= x0 + 76 + wpX && mouseX < x0 + 80 + wpX) { if (mouseY >= y0 + 21 + wpY && mouseY < y0 + 25 + wpY) { @@ -330,17 +329,16 @@ private void renderPlayerHead(PoseStack transforms, } } - private void renderMapTexture(PoseStack transforms, int x0, int y0, int x1) { + private void renderMapTexture(GuiGraphics guiGraphics, int x0, int y0, int x1) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); // corner of the in-game window - RenderSystem.setShaderTexture(0, this.map.texture); // Who said we have to use 128 * 128 texture? - blit(transforms, x0 + 78, y0 + 23, 0, 0, 128, 128, 128, 128); + guiGraphics.blit(this.map.texture, x0 + 78, y0 + 23, 0, 0, 128, 128, 128, 128); } - private void renderWaypointTexture(PoseStack transforms, int x0, int y0, int x1, float partialTicks) { + private void renderWaypointTexture(GuiGraphics guiGraphics, int x0, int y0, int x1, float partialTicks) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); @@ -368,27 +366,22 @@ private void renderWaypointTexture(PoseStack transforms, int x0, int y0, int x1, if (this.lastWaypointTextures.isEmpty()) { this.ticksAfterWaypointTextureChanged = 0; } else { - RenderSystem.setShaderTexture(0, head); - blit(transforms, x1 + 7, y0 + 20, 0, 0, 96, 54, 96, 54); + guiGraphics.blit(head, x1 + 7, y0 + 20, 0, 0, 96, 54, 96, 54); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha); - RenderSystem.setShaderTexture(0, GUIDE_MAP_RIGHT); - blit(transforms, x1 + 7, y0 + 20, 7, 20, 96, 54); + guiGraphics.blit(GUIDE_MAP_RIGHT, x1 + 7, y0 + 20, 7, 20, 96, 54); image = this.lastWaypointTextures.getFirst(); } this.lastWaypointTextures.addFirst(head); - RenderSystem.setShaderTexture(0, image); - blit(transforms, x1 + 7, y0 + 20, 0, 0, 96, 54, 96, 54); + guiGraphics.blit(image, x1 + 7, y0 + 20, 0, 0, 96, 54, 96, 54); } - private void renderBackgroundTexture(PoseStack transforms, int x0, int y0, int x1) { + private void renderBackgroundTexture(GuiGraphics guiGraphics, int x0, int y0, int x1) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, GUIDE_MAP_LEFT); - blit(transforms, x0, y0, 0, 0, 211, 161); - blit(transforms, x0 + 6, y0 + 138, 66, 201, 66, 17); - RenderSystem.setShaderTexture(0, GUIDE_MAP_RIGHT); - blit(transforms, x1 + 5, y0, 5, 0, 174, 161); + guiGraphics.blit(GUIDE_MAP_LEFT, x0, y0, 0, 0, 211, 161); + guiGraphics.blit(GUIDE_MAP_LEFT, x0 + 6, y0 + 138, 66, 201, 66, 17); + guiGraphics.blit(GUIDE_MAP_RIGHT, x1 + 5, y0, 5, 0, 174, 161); if (!this.hasWaypointTrigger) { - blit(transforms, x1 + 108, y0 + 20, 181, 20, 64, 134); + guiGraphics.blit(GUIDE_MAP_RIGHT, x1 + 108, y0 + 20, 181, 20, 64, 134); } } @@ -443,14 +436,14 @@ private TriggerButton(int x, int y, int width, int height, int uOffset, int vOff } @Override - public void renderWidget(PoseStack transforms, int mouseX, int mouseY, float partialTicks) { - super.renderWidget(transforms, mouseX, mouseY, partialTicks); + public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + super.renderWidget(guiGraphics, mouseX, mouseY, partialTick); //final Font font = Minecraft.getInstance().font; final int stringWidth = font.width(this.trigger.getTitle()); final int x0 = this.getX() + this.width / 2 - stringWidth / 2, y0 = this.getY() + (this.height - 8) / 2; - font.draw(transforms, this.trigger.getTitle(), x0, y0, this.trigger.disabled ? 0xFFFFFF : 0x404040); + guiGraphics.drawString(font, this.trigger.getTitle(), x0, y0, this.trigger.disabled ? 0xFFFFFF : 0x404040, false); if (this.isHovered) { - GuideMapScreen.this.renderTooltip(transforms, this.trigger.getDesc(), mouseX, mouseY); + guiGraphics.renderTooltip(font, this.trigger.getDesc(), mouseX, mouseY); } } } diff --git a/src/main/java/org/teacon/signin/command/CommandImpl.java b/src/main/java/org/teacon/signin/command/CommandImpl.java index c2f6b52..1868a95 100644 --- a/src/main/java/org/teacon/signin/command/CommandImpl.java +++ b/src/main/java/org/teacon/signin/command/CommandImpl.java @@ -38,9 +38,9 @@ public static int trigger(CommandContext context) throws Com public static int listMaps(CommandContext context) { CommandSourceStack src = context.getSource(); if (SignMeUp.MANAGER.getAllMaps().size() != 0) { - src.sendSuccess(Component.translatable("sign_up.text.list_maps").append(": "), false); + src.sendSuccess(() -> Component.translatable("sign_up.text.list_maps").append(": "), false); for (GuideMap map : SignMeUp.MANAGER.getAllMaps()) { - src.sendSuccess(map.getTitle(), false); + src.sendSuccess(map::getTitle, false); } return Command.SINGLE_SUCCESS; } else { @@ -109,7 +109,7 @@ public static int openNearestMap(CommandContext context) thr double minDistanceSq = Double.MAX_VALUE; // We first check the dimension - if (src.getPlayerOrException().getLevel().dimension() == worldKey) { + if (src.getPlayerOrException().level().dimension() == worldKey) { // Then we look for the nearest in-range map for (GuideMap guideMap : SignMeUp.MANAGER.getAllMaps()) { final double dx = src.getPosition().x() - guideMap.center.getX(); @@ -141,13 +141,13 @@ public static int listWaypoints(CommandContext context) thro CommandSourceStack src = context.getSource(); ServerPlayer player = src.getPlayerOrException(); if (SignMeUp.MANAGER.getAllWaypoints().size() != 0) { - src.sendSuccess(Component.translatable("sign_up.text.list_points") + src.sendSuccess(() -> Component.translatable("sign_up.text.list_points") .append(": ") , false); for (Waypoint waypoint : SignMeUp.MANAGER.getAllWaypoints()) { DecimalFormat df = new DecimalFormat("0.00"); df.setRoundingMode(RoundingMode.HALF_UP); - src.sendSuccess(Component.literal(" - ") + src.sendSuccess(() -> Component.literal(" - ") .append(waypoint.getTitle()).append("\n ") .append(Component.translatable("sign_up.text.distance")) .append(": " + df.format(Vec3.atLowerCornerOf(waypoint.getActualLocation()).distanceTo(src.getPosition())) + " ") @@ -165,9 +165,9 @@ public static int listWaypoints(CommandContext context) thro public static int listWaypointPos(CommandContext context) { CommandSourceStack src = context.getSource(); if (SignMeUp.MANAGER.getAllWaypoints().size() != 0) { - src.sendSuccess(Component.translatable("sign_up.text.list_points"), false); + src.sendSuccess(() -> Component.translatable("sign_up.text.list_points"), false); for (Waypoint waypoint : SignMeUp.MANAGER.getAllWaypoints()) { - src.sendSuccess(Component.literal(" - ") + src.sendSuccess(() -> Component.literal(" - ") .append(waypoint.getTitle()) .append("\n ") .append(Component.translatable("sign_up.text.render_location")) @@ -192,7 +192,7 @@ public static int getWaypointPos(CommandContext context) { final ResourceLocation id = context.getArgument("id", ResourceLocation.class); Waypoint waypoint = SignMeUp.MANAGER.findWaypoint(id); if (waypoint != null) { - src.sendSuccess(Component.literal(" - ") + src.sendSuccess(() -> Component.literal(" - ") .append(waypoint.getTitle()) .append("\n ") .append(Component.translatable("sign_up.text.render_location")) diff --git a/src/main/java/org/teacon/signin/data/GuideMapManager.java b/src/main/java/org/teacon/signin/data/GuideMapManager.java index 552eba0..1067db3 100644 --- a/src/main/java/org/teacon/signin/data/GuideMapManager.java +++ b/src/main/java/org/teacon/signin/data/GuideMapManager.java @@ -69,7 +69,7 @@ public void sync(EntityJoinLevelEvent event) { if (event.getEntity() instanceof ServerPlayer p) { final SortedMap mapsToSend = new TreeMap<>(); this.maps.forEach((id, map) -> { - if (p.level.dimension().location().equals(map.dim)) { + if (p.level().dimension().location().equals(map.dim)) { mapsToSend.put(id, map); } });