Skip to content

Commit

Permalink
Update to 1.20.1.
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <[email protected]>
  • Loading branch information
qyl27 committed Jul 27, 2023
1 parent 1788914 commit 367776e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bin/
eclipse/
run_client/
run_server/
run_test/
logs/
remappedSrc/

Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.jvmargs=-Xmx5G
org.gradle.daemon=false
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pluginManagement.repositories {
gradlePluginPortal()
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = 'https://maven.parchmentmc.org' }
}

rootProject.name = 'SignMeUp'
81 changes: 37 additions & 44 deletions src/main/java/org/teacon/signin/client/GuideMapScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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) {
Expand All @@ -252,17 +253,17 @@ 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/
// However it at least get things work for now. So it is the status quo.
List<FormattedCharSequence> 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<Component> tooltipTexts = new ArrayList<>(this.queuedTips.size() * 2 + 1);
for (Pair<Component, Component> pair = this.queuedTips.poll(); pair != null; pair = this.queuedTips.poll()) {
Expand All @@ -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<? extends Player> players = mc.level == null ? List.of() : mc.level.players();

Expand All @@ -300,26 +301,24 @@ 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;
int wpY = Math.round((float) outputY / this.map.radius * 64) + 64;
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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/teacon/signin/command/CommandImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public static int trigger(CommandContext<CommandSourceStack> context) throws Com
public static int listMaps(CommandContext<CommandSourceStack> 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 {
Expand Down Expand Up @@ -109,7 +109,7 @@ public static int openNearestMap(CommandContext<CommandSourceStack> 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();
Expand Down Expand Up @@ -141,13 +141,13 @@ public static int listWaypoints(CommandContext<CommandSourceStack> 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())) + " ")
Expand All @@ -165,9 +165,9 @@ public static int listWaypoints(CommandContext<CommandSourceStack> context) thro
public static int listWaypointPos(CommandContext<CommandSourceStack> 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"))
Expand All @@ -192,7 +192,7 @@ public static int getWaypointPos(CommandContext<CommandSourceStack> 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"))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/teacon/signin/data/GuideMapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void sync(EntityJoinLevelEvent event) {
if (event.getEntity() instanceof ServerPlayer p) {
final SortedMap<ResourceLocation, GuideMap> 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);
}
});
Expand Down

0 comments on commit 367776e

Please sign in to comment.