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/SignMeUp.java b/src/main/java/org/teacon/signin/SignMeUp.java index 00aa7da..03e3352 100644 --- a/src/main/java/org/teacon/signin/SignMeUp.java +++ b/src/main/java/org/teacon/signin/SignMeUp.java @@ -27,16 +27,18 @@ import org.teacon.signin.command.CommandImpl; import org.teacon.signin.data.DynamicLocationStorage; import org.teacon.signin.data.GuideMapManager; -import org.teacon.signin.data.Trigger; +import org.teacon.signin.data.entity.Trigger; import org.teacon.signin.network.*; -@Mod("sign_up") -@Mod.EventBusSubscriber(modid = "sign_up", bus = Mod.EventBusSubscriber.Bus.FORGE) +@Mod(SignMeUp.MODID) +@Mod.EventBusSubscriber(modid = SignMeUp.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public final class SignMeUp { + public static final String MODID = "sign_up"; + public static final GuideMapManager MANAGER = new GuideMapManager(); - public static SimpleChannel channel = NetworkRegistry.ChannelBuilder.named(new ResourceLocation("sign_up", "data")) + public static SimpleChannel channel = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(SignMeUp.MODID, "data")) .networkProtocolVersion(() -> "0.0") .clientAcceptedVersions("0.0"::equals) .serverAcceptedVersions("0.0"::equals) diff --git a/src/main/java/org/teacon/signin/client/ClientGuideMapManager.java b/src/main/java/org/teacon/signin/client/ClientGuideMapManager.java index 9974f08..d6b60d3 100644 --- a/src/main/java/org/teacon/signin/client/ClientGuideMapManager.java +++ b/src/main/java/org/teacon/signin/client/ClientGuideMapManager.java @@ -4,9 +4,10 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.Vec3; -import org.teacon.signin.data.GuideMap; -import org.teacon.signin.data.Trigger; -import org.teacon.signin.data.Waypoint; +import org.teacon.signin.client.gui.MapScreen; +import org.teacon.signin.data.entity.GuideMap; +import org.teacon.signin.data.entity.Trigger; +import org.teacon.signin.data.entity.Waypoint; import org.teacon.signin.network.MapScreenPacket; import java.util.*; @@ -23,10 +24,9 @@ public void openMapByPacket(MapScreenPacket.Action action, ResourceLocation mapI if (action == MapScreenPacket.Action.OPEN_SPECIFIC) { Objects.requireNonNull(mapId); GuideMap map = SignMeUpClient.MANAGER.findMap(mapId); - mc.setScreen(new GuideMapScreen(mapId, map, position)); - } else if (mc.screen instanceof GuideMapScreen) { - final GuideMapScreen screen = (GuideMapScreen) mc.screen; - if (action != MapScreenPacket.Action.CLOSE_SPECIFIC || screen.mapId.equals(mapId)) { + mc.setScreen(new MapScreen(mapId, map, position)); + } else if (mc.screen instanceof MapScreen screen) { + if (action != MapScreenPacket.Action.CLOSE_SPECIFIC || screen.getMapId().equals(mapId)) { mc.setScreen(null); } } @@ -46,7 +46,7 @@ public Map.Entry nearestTo(Vec3 pos) { final GuideMap guideMap = entry.getValue(); final double dx = pos.x() - guideMap.center.getX(); final double dz = pos.z() - guideMap.center.getZ(); - if (Math.min(Math.abs(dx), Math.abs(dz)) <= guideMap.radius) { + if (Math.min(Math.abs(dx), Math.abs(dz)) <= guideMap.range) { final double distanceSq = dx * dx + dz * dz; if (distanceSq < minDistanceSq) { minDistanceSq = distanceSq; diff --git a/src/main/java/org/teacon/signin/client/GuideMapScreen.java b/src/main/java/org/teacon/signin/client/GuideMapScreen.java deleted file mode 100644 index 417a4be..0000000 --- a/src/main/java/org/teacon/signin/client/GuideMapScreen.java +++ /dev/null @@ -1,457 +0,0 @@ -package org.teacon.signin.client; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Queues; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.datafixers.util.Pair; -import net.minecraft.MethodsReturnNonnullByDefault; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.ImageButton; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.entity.LivingEntityRenderer; -import net.minecraft.client.resources.DefaultPlayerSkin; -import net.minecraft.core.Vec3i; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.FormattedCharSequence; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.phys.Vec3; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.MarkerManager; -import org.teacon.signin.SignMeUp; -import org.teacon.signin.data.GuideMap; -import org.teacon.signin.data.Trigger; -import org.teacon.signin.data.Waypoint; -import org.teacon.signin.network.TriggerFromMapPacket; -import org.teacon.signin.network.TriggerFromWaypointPacket; - -import javax.annotation.ParametersAreNonnullByDefault; -import java.util.*; - -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -public final class GuideMapScreen extends Screen { - - private static final Logger LOGGER = LogManager.getLogger("SignMeUp"); - private static final Marker MARKER = MarkerManager.getMarker("GuideMapScreen"); - - private static final int X_SIZE = 385; - private static final int Y_SIZE = 161; - - public final ResourceLocation mapId; - - private static final ResourceLocation MAP_ICONS = new ResourceLocation("minecraft", "textures/map/map_icons.png"); - private static final ResourceLocation GUIDE_MAP_LEFT = new ResourceLocation("sign_up", "textures/gui/guide_map_left.png"); - private static final ResourceLocation GUIDE_MAP_RIGHT = new ResourceLocation("sign_up", "textures/gui/guide_map_right.png"); - - private int mapTriggerPage = 0; - private int mapTriggerPageSize = 0; - private ResourceLocation selectedWaypoint; - - private int ticksAfterWaypointTextureChanged = 0; - private final Deque lastWaypointTextures = Queues.newArrayDeque(); - - private boolean hasWaypointTrigger = false; - - private final GuideMap map; - private final Vec3 playerLocation; - private final List waypointIds; - - private PolynomialMapping mapping; - - private ImageButton leftFlip, rightFlip; - private ImageButton mapTriggerPrev, mapTriggerNext; - - private final List mapTriggers = Lists.newArrayList(); - private final ListMultimap waypointTriggers = ArrayListMultimap.create(); - - private final Queue> queuedTips = Queues.newArrayDeque(); - - private boolean needRefresh = false; - - public GuideMapScreen(ResourceLocation mapId, GuideMap map, Vec3 location) { - super(map.getTitle()); - this.map = map; - this.mapId = mapId; - this.playerLocation = location; - this.waypointIds = map.getWaypointIds(); - } - - public void refresh() { - // Set refresh state - this.needRefresh = true; - } - - @Override - protected void init() { - super.init(); - int x0 = (this.width - X_SIZE) / 2, y0 = (this.height - Y_SIZE) / 2, x1 = x0 + 206; - - // Left and Right Image Flip Button - this.leftFlip = this.addRenderableWidget(new ImageButton(x1 + 7, y0 + 20, 10, 54, 155, 163, 0, GUIDE_MAP_RIGHT, new FlipHandler(1))); - this.rightFlip = this.addRenderableWidget(new ImageButton(x1 + 93, y0 + 20, 10, 54, 167, 163, 0, GUIDE_MAP_RIGHT, new FlipHandler(-1))); - - // Prev and next page for map triggers - this.mapTriggerPrev = this.addRenderableWidget(new ImageButton(x0 + 6, y0 + 138, 33, 17, 66, 163, 19, GUIDE_MAP_LEFT, (btn) -> --this.mapTriggerPage)); - this.mapTriggerNext = this.addRenderableWidget(new ImageButton(x0 + 39, y0 + 138, 33, 17, 99, 163, 19, GUIDE_MAP_LEFT, (btn) -> ++this.mapTriggerPage)); - - // Setup trigger buttons from GuideMap - this.mapTriggers.clear(); - List mapTriggerIds = this.map.getTriggerIds(); - for (int i = 0, j = 0; i < mapTriggerIds.size(); ++i) { - ResourceLocation triggerId = mapTriggerIds.get(i); - final Trigger trigger = SignMeUpClient.MANAGER.findTrigger(triggerId); - if (trigger == null) { - continue; - } - this.mapTriggerPageSize = Math.max(this.mapTriggerPageSize, 1 + j / 6); - final TriggerButton btn = this.addRenderableWidget(new TriggerButton(x0 + 8, y0 + 21 + (j % 6) * 19, 62, 18, - 2, trigger.disabled ? 203 : 163, trigger.disabled ? 0 : 20, GUIDE_MAP_LEFT, trigger, - (b) -> SignMeUp.channel.sendToServer(new TriggerFromMapPacket(this.mapId, triggerId)))); - this.mapTriggers.add(btn); - btn.visible = false; - ++j; - } - - // Collect Waypoints - this.waypointTriggers.clear(); - int mapCanvasX = x0 + 78, mapCanvasY = y0 + 23; - final List waypoints = new ArrayList<>(this.waypointIds.size()); - final List waypointIds = new ArrayList<>(this.waypointIds.size()); - for (ResourceLocation wpId : this.waypointIds) { - Waypoint wp = SignMeUpClient.MANAGER.findWaypoint(wpId); - if (wp != null) { - waypoints.add(wp); - waypointIds.add(wpId); - } - } - - // Setup Mapping - final int waypointSize = waypoints.size(); - final double[] inputX = new double[waypointSize], inputY = new double[waypointSize]; - final double[] outputX = new double[waypointSize], outputY = new double[waypointSize]; - final Vec3i center = this.map.center; - for (int i = 0; i < waypointSize; ++i) { - final Waypoint wp = waypoints.get(i); - final Vec3i actualLocation = wp.getActualLocation(); - final Vec3i renderLocation = wp.getRenderLocation(); - inputX[i] = actualLocation.getX() - center.getX(); - inputY[i] = actualLocation.getZ() - center.getZ(); - outputX[i] = renderLocation.getX() - center.getX(); - outputY[i] = renderLocation.getZ() - center.getZ(); - } - try { - this.mapping = new PolynomialMapping(inputX, inputY, outputX, outputY); - LOGGER.info(MARKER, "Generated the mapping for {} waypoint(s).", waypointSize); - LOGGER.debug(MARKER, "The mapping is: {}", this.mapping); - } catch (IllegalArgumentException e) { - this.mapping = new PolynomialMapping(new double[0], new double[0], new double[0], new double[0]); - LOGGER.warn(MARKER, "Unable to generate mapping for the map.", e); - } - - // Setup Waypoints - for (int i = 0; i < waypointSize; ++i) { - final Waypoint wp = waypoints.get(i); - final ResourceLocation wpId = waypointIds.get(i); - final int wpX = Math.round((float) outputX[i] / this.map.radius * 64) + 64; - final int wpY = Math.round((float) outputY[i] / this.map.radius * 64) + 64; - if (wpX >= 1 && wpX <= 127 && wpY >= 1 && wpY <= 127) { - // Setup Waypoints as ImageButtons - this.addRenderableWidget(new ImageButton( - 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); - 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))); - } - } - }); - // Setup trigger buttons from Waypoints - List wpTriggerIds = wp.getTriggerIds(); - for (int j = 0, k = 0; k < wpTriggerIds.size() && j < 7; ++k) { - ResourceLocation triggerId = wpTriggerIds.get(k); - final Trigger trigger = SignMeUpClient.MANAGER.findTrigger(triggerId); - if (trigger == null) { - continue; - } - TriggerButton btn = this.addRenderableWidget(new TriggerButton(x1 + 109, y0 + 21 + j * 19, 62, 18, - 2, trigger.disabled ? 203 : 163, trigger.disabled ? 0 : 20, GUIDE_MAP_RIGHT, trigger, - (b) -> SignMeUp.channel.sendToServer(new TriggerFromWaypointPacket(wpId, triggerId)))); - this.waypointTriggers.put(wpId, btn); - btn.visible = false; - ++j; - } - } - } - } - - @Override - public void tick() { - if (this.needRefresh) { - this.init(Minecraft.getInstance(), this.width, this.height); - this.needRefresh = false; - } - - ++this.ticksAfterWaypointTextureChanged; - - this.mapTriggerPrev.visible = this.mapTriggerPage >= 1; - this.mapTriggerNext.visible = this.mapTriggerPage < this.mapTriggerPageSize - 1; - - Waypoint wp = this.selectedWaypoint == null ? null : SignMeUp.MANAGER.findWaypoint(this.selectedWaypoint); - this.leftFlip.visible = this.rightFlip.visible = wp != null ? wp.hasMoreThanOneImage() : this.map.hasMoreThanOneImage(); - - this.hasWaypointTrigger = false; - for (Map.Entry entry : this.waypointTriggers.entries()) { - final boolean visible = Objects.equals(entry.getKey(), this.selectedWaypoint); - this.hasWaypointTrigger = this.hasWaypointTrigger || visible; - entry.getValue().visible = visible; - } - - for (int i = 0, size = this.mapTriggers.size(); i < size; ++i) { - this.mapTriggers.get(i).visible = i / 6 == this.mapTriggerPage; - } - } - - private Component toDistanceText(double distance) { - return Component.translatable("sign_up.waypoint.distance", "%.1f".formatted(distance)); - } - - @Override - public void render(PoseStack transforms, int mouseX, int mouseY, float partialTicks) { - 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); - - super.render(transforms, mouseX, mouseY, partialTicks); - - this.renderPlayerHeads(transforms, mouseX, mouseY, x0, y0, x1); - this.renderTextCollection(transforms, mouseX, mouseY, x0, y0, x1); - } - - private void renderTextCollection(PoseStack transforms, 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) { - Waypoint wp = SignMeUpClient.MANAGER.findWaypoint(this.selectedWaypoint); - if (wp != null) { - subtitle = wp.getTitle(); - desc = wp.getDesc(); - } - } - // 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); - final int xSubtitle = x1 + 56 - font.width(subtitle) / 2; - font.draw(transforms, subtitle, xSubtitle, y0 + 7F, 0x404040); - // 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 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); - } - List tooltipTexts = new ArrayList<>(this.queuedTips.size() * 2 + 1); - for (Pair pair = this.queuedTips.poll(); pair != null; pair = this.queuedTips.poll()) { - if (!tooltipTexts.isEmpty()) { - tooltipTexts.add(Component.empty()); - } - tooltipTexts.add(pair.getFirst()); - tooltipTexts.add(pair.getSecond()); - } - if (!tooltipTexts.isEmpty()) { - this.renderComponentTooltip(transforms, tooltipTexts, mouseX, mouseY); - } - } - - private void renderPlayerHeads(PoseStack transforms, 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(); - - int size = players.size(); - double[] inputX = new double[size], inputY = new double[size]; - double[] outputX = new double[size], outputY = new double[size]; - - int currentIndex = size; - Vec3i center = this.map.center; - UUID current = mc.player == null ? null : mc.player.getUUID(); - for (int i = 0; i < size; ++i) { - Player player = players.get(i); - if (player.getUUID().equals(current)) { - currentIndex = i; - } - inputX[i] = player.getX() - center.getX(); - inputY[i] = player.getZ() - center.getY(); - } - this.mapping.interpolate(inputX, inputY, outputX, outputY); - - // 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]); - } - for (int i = size - 1; i >= currentIndex; --i) { - this.renderPlayerHead(transforms, mouseX, mouseY, x0, y0, players.get(i), outputX[i], outputY[i]); - } - } - - private void renderPlayerHead(PoseStack transforms, - 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); - } else { - RenderSystem.setShaderTexture(0, DefaultPlayerSkin.getDefaultSkin(player.getUUID())); - blit(transforms, 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) { - double distance = player.position().distanceTo(this.playerLocation); - this.queuedTips.offer(Pair.of(player.getDisplayName(), this.toDistanceText(distance))); - } - } - } - } - - private void renderMapTexture(PoseStack transforms, 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); - } - - private void renderWaypointTexture(PoseStack transforms, int x0, int y0, int x1, float partialTicks) { - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - ResourceLocation image = this.map.getDisplayingImageId(); - if (this.selectedWaypoint != null) { - Waypoint wp = SignMeUpClient.MANAGER.findWaypoint(this.selectedWaypoint); - if (wp != null) { - image = wp.getDisplayingImageId(); - } - } - // Drop images that will not be used in the future - float alpha = (this.ticksAfterWaypointTextureChanged + partialTicks) / 4F; - while (alpha >= 1) { - this.ticksAfterWaypointTextureChanged -= 4; - this.lastWaypointTextures.pollFirst(); - --alpha; - } - // Ensure that the last image is current image - final ResourceLocation tail = this.lastWaypointTextures.peekLast(); - if (!image.equals(tail)) { - this.lastWaypointTextures.addLast(image); - } - // If there are more than one images, render both of them, otherwise set the timer to zero - final ResourceLocation head = this.lastWaypointTextures.removeFirst(); - if (this.lastWaypointTextures.isEmpty()) { - this.ticksAfterWaypointTextureChanged = 0; - } else { - RenderSystem.setShaderTexture(0, head); - blit(transforms, 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); - image = this.lastWaypointTextures.getFirst(); - } - this.lastWaypointTextures.addFirst(head); - RenderSystem.setShaderTexture(0, image); - blit(transforms, x1 + 7, y0 + 20, 0, 0, 96, 54, 96, 54); - } - - private void renderBackgroundTexture(PoseStack transforms, 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); - if (!this.hasWaypointTrigger) { - blit(transforms, x1 + 108, y0 + 20, 181, 20, 64, 134); - } - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (!super.mouseClicked(mouseX, mouseY, button)) { - int x0 = (this.width - X_SIZE) / 2, y0 = (this.height - Y_SIZE) / 2; - // Reset selected Wp when clicking everywhere on the map - if (mouseX >= x0 + 78 && mouseX < x0 + 206 && mouseY >= y0 + 23 && mouseY < y0 + 151) { - if (this.selectedWaypoint != null) { - this.selectedWaypoint = null; - return true; - } - } - return false; - } - return true; - } - - @Override - public boolean isPauseScreen() { - return false; - } - - private final class FlipHandler implements Button.OnPress { - private final int diff; - - private FlipHandler(int diff) { - this.diff = diff; - } - - @Override - public void onPress(Button p_onPress_1_) { - if (selectedWaypoint != null) { - Waypoint wp = SignMeUpClient.MANAGER.findWaypoint(selectedWaypoint); - if (wp != null) { - wp.modifyDisplayingImageIndex(this.diff); - return; - } - } - map.modifyDisplayingImageIndex(this.diff); - } - } - - private final class TriggerButton extends ImageButton { - private final Trigger trigger; - - private TriggerButton(int x, int y, int width, int height, int uOffset, int vOffset, int vDiff, - ResourceLocation image, Trigger trigger, OnPress pressable) { - super(x, y, width, height, uOffset, vOffset, vDiff, image, pressable); - this.trigger = trigger; - } - - @Override - public void renderWidget(PoseStack transforms, int mouseX, int mouseY, float partialTicks) { - super.renderWidget(transforms, mouseX, mouseY, partialTicks); - //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); - if (this.isHovered) { - GuideMapScreen.this.renderTooltip(transforms, this.trigger.getDesc(), mouseX, mouseY); - } - } - } -} diff --git a/src/main/java/org/teacon/signin/client/Hotkey.java b/src/main/java/org/teacon/signin/client/Hotkey.java index dcdc011..0623c49 100644 --- a/src/main/java/org/teacon/signin/client/Hotkey.java +++ b/src/main/java/org/teacon/signin/client/Hotkey.java @@ -8,7 +8,8 @@ import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import org.teacon.signin.data.GuideMap; +import org.teacon.signin.client.gui.MapScreen; +import org.teacon.signin.data.entity.GuideMap; import java.util.Map; @@ -23,7 +24,7 @@ public static void keyTyped(InputEvent.Key event) { final Vec3 position = mc.player.position(); final Map.Entry entry = SignMeUpClient.MANAGER.nearestTo(position); if (entry != null) { - mc.setScreen(new GuideMapScreen(entry.getKey(), entry.getValue(), position)); + mc.setScreen(new MapScreen(entry.getKey(), entry.getValue(), position)); } else { mc.player.displayClientMessage(Component.translatable("sign_up.status.no_map_available"), true); } diff --git a/src/main/java/org/teacon/signin/client/gui/GuideMapScreenBase.java b/src/main/java/org/teacon/signin/client/gui/GuideMapScreenBase.java new file mode 100644 index 0000000..228a1bc --- /dev/null +++ b/src/main/java/org/teacon/signin/client/gui/GuideMapScreenBase.java @@ -0,0 +1,71 @@ +package org.teacon.signin.client.gui; + +import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner; +import net.minecraft.resources.ResourceLocation; +import org.teacon.signin.SignMeUp; +import org.teacon.signin.client.gui.component.TooltipText; +import org.teacon.signin.data.entity.GuideMap; + +public abstract class GuideMapScreenBase extends Screen { + public static final ResourceLocation TEXTURE = new ResourceLocation(SignMeUp.MODID, "textures/gui/gui.png"); + + public static final int GUI_WIDTH = 360; + public static final int GUI_HEIGHT = 271; + + protected final ResourceLocation mapId; + protected final GuideMap map; + + public GuideMapScreenBase(ResourceLocation mapId, GuideMap map) { + super(map.getTitle()); + + this.mapId = mapId; + this.map = map; + } + + public ResourceLocation getMapId() { + return mapId; + } + + protected TooltipText title; + + @Override + protected void init() { + super.init(); + + var x0 = (this.width - GUI_WIDTH) / 2; + var y0 = (this.height - GUI_HEIGHT) / 2; + + title = new TooltipText(x0 + 17, y0 + 12, map.getTitle(), Tooltip.create(map.getDesc())); + + addRenderableWidget(title); + } + + protected boolean needRefresh = false; + + public void refresh() { + this.needRefresh = true; + } + + protected abstract void doRender(GuiGraphics graphics, int mouseX, int mouseY, int x0, int y0, float partialTick); + + @Override + public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) { + super.render(graphics, mouseX, mouseY, partialTick); + + var x0 = (this.width - GUI_WIDTH) / 2; + var y0 = (this.height - GUI_HEIGHT) / 2; + + renderBackground(graphics); + + doRender(graphics, mouseX, mouseY, x0, y0, partialTick); + } + + protected void renderBackgroundTexture(GuiGraphics graphics, int x, int y, int id) { + graphics.blit(TEXTURE, x, y, GUI_WIDTH, GUI_HEIGHT, id * GUI_WIDTH, 0, GUI_WIDTH, GUI_HEIGHT, 1080, 552); + } +} diff --git a/src/main/java/org/teacon/signin/client/gui/MapScreen.java b/src/main/java/org/teacon/signin/client/gui/MapScreen.java new file mode 100644 index 0000000..e4fa18f --- /dev/null +++ b/src/main/java/org/teacon/signin/client/gui/MapScreen.java @@ -0,0 +1,24 @@ +package org.teacon.signin.client.gui; + +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.phys.Vec3; +import org.teacon.signin.data.entity.GuideMap; + +public class MapScreen extends GuideMapScreenBase { + + protected Vec3 location; + + public MapScreen(ResourceLocation mapId, GuideMap map, Vec3 location) { + super(mapId, map); + + this.location = location; + } + + @Override + protected void doRender(GuiGraphics graphics, int mouseX, int mouseY, int x0, int y0, float partialTick) { + renderBackgroundTexture(graphics, x0, y0, 0); + +// graphics.blit(map.texture, x0 + 97, y0 + 7, 0, 0, ); + } +} diff --git a/src/main/java/org/teacon/signin/client/gui/component/TooltipText.java b/src/main/java/org/teacon/signin/client/gui/component/TooltipText.java new file mode 100644 index 0000000..5f83dce --- /dev/null +++ b/src/main/java/org/teacon/signin/client/gui/component/TooltipText.java @@ -0,0 +1,33 @@ +package org.teacon.signin.client.gui.component; + +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; + +public class TooltipText extends AbstractWidget { + protected Minecraft mc; + + public TooltipText(int x, int y, Component message, Tooltip tooltip) { + super(x, y, Minecraft.getInstance().font.width(message), Minecraft.getInstance().font.lineHeight, message); + setTooltip(tooltip); + + mc = Minecraft.getInstance(); + } + + @Override + protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) { + graphics.enableScissor(getX(), getY(), getX() + 67, getY() + getHeight()); + graphics.drawString(mc.font, getMessage().copy().withStyle(ChatFormatting.WHITE, ChatFormatting.BOLD), + getX(), getY(), 0x404040); + graphics.disableScissor(); + } + + @Override + protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) { + // Todo: narrator support. + } +} diff --git a/src/main/java/org/teacon/signin/command/CommandImpl.java b/src/main/java/org/teacon/signin/command/CommandImpl.java index c2f6b52..66e1a75 100644 --- a/src/main/java/org/teacon/signin/command/CommandImpl.java +++ b/src/main/java/org/teacon/signin/command/CommandImpl.java @@ -16,8 +16,8 @@ import net.minecraftforge.network.NetworkDirection; import org.teacon.signin.SignMeUp; import org.teacon.signin.data.DynamicLocationStorage; -import org.teacon.signin.data.GuideMap; -import org.teacon.signin.data.Waypoint; +import org.teacon.signin.data.entity.GuideMap; +import org.teacon.signin.data.entity.Waypoint; import org.teacon.signin.network.MapScreenPacket; import java.math.RoundingMode; @@ -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,12 +109,12 @@ 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(); final double dz = src.getPosition().z() - guideMap.center.getZ(); - if (Math.min(Math.abs(dx), Math.abs(dz)) <= guideMap.radius) { + if (Math.min(Math.abs(dx), Math.abs(dz)) <= guideMap.range) { final double distanceSq = dx * dx + dz * dz; if (distanceSq < minDistanceSq) { minDistanceSq = distanceSq; @@ -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..71d4660 100644 --- a/src/main/java/org/teacon/signin/data/GuideMapManager.java +++ b/src/main/java/org/teacon/signin/data/GuideMapManager.java @@ -23,6 +23,9 @@ import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.MarkerManager; import org.teacon.signin.SignMeUp; +import org.teacon.signin.data.entity.GuideMap; +import org.teacon.signin.data.entity.Trigger; +import org.teacon.signin.data.entity.Waypoint; import org.teacon.signin.network.SyncGuideMapPacket; import java.util.*; @@ -69,7 +72,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); } }); diff --git a/src/main/java/org/teacon/signin/data/GuideMap.java b/src/main/java/org/teacon/signin/data/entity/GuideMap.java similarity index 64% rename from src/main/java/org/teacon/signin/data/GuideMap.java rename to src/main/java/org/teacon/signin/data/entity/GuideMap.java index 2263502..a36f314 100644 --- a/src/main/java/org/teacon/signin/data/GuideMap.java +++ b/src/main/java/org/teacon/signin/data/entity/GuideMap.java @@ -1,5 +1,7 @@ -package org.teacon.signin.data; +package org.teacon.signin.data.entity; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import com.google.gson.*; import net.minecraft.core.Vec3i; import net.minecraft.network.chat.Component; @@ -11,55 +13,49 @@ import java.lang.reflect.Type; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.StreamSupport; public final class GuideMap { public static final ResourceLocation DEFAULT_IMAGE = new ResourceLocation("sign_up:textures/map_default.png"); + public static final ResourceLocation MISSING_TEXTURE = new ResourceLocation("minecraft", "missing"); Component title; - Component subtitle; Component desc; public Vec3i center; - public float radius = 128F; + public float range = 128F; public ResourceLocation dim = null; // TODO Actually ensure the missing texture exists - public ResourceLocation texture = new ResourceLocation("minecraft", "missing"); + private final BiMap zooms = HashBiMap.create(new HashMap<>()); + private final Map textures = new HashMap<>(); - private List imageIds = Collections.emptyList(); - - private int displayingImageIndex; - - List waypointIds = Collections.emptyList(); - List triggerIds = Collections.emptyList(); + private List waypointIds = Collections.emptyList(); + private List triggerIds = Collections.emptyList(); public Component getTitle() { return this.title != null ? this.title : Component.translatable("sign_up.map.unnamed"); } - public Component getSubtitle() { - return this.subtitle != null ? this.subtitle : this.getTitle(); - } - public Component getDesc() { return this.desc != null ? this.desc : Component.empty(); } - public boolean hasMoreThanOneImage() { - return this.imageIds.size() > 1; + public BiMap getZooms() { + return zooms; } - public void modifyDisplayingImageIndex(int diff) { - if (!this.imageIds.isEmpty()) { - this.displayingImageIndex = Math.floorMod(this.displayingImageIndex + diff, this.imageIds.size()); - } + public Map getTextures() { + return textures; } - public ResourceLocation getDisplayingImageId() { - return this.imageIds.isEmpty() ? DEFAULT_IMAGE : this.imageIds.get(this.displayingImageIndex); + public ResourceLocation getTexture(double zoom) { + var name = zooms.inverse().get(zoom); + return textures.getOrDefault(name, MISSING_TEXTURE); } public List getWaypointIds() { @@ -85,9 +81,6 @@ public GuideMap deserialize(JsonElement src, Type type, JsonDeserializationConte if (json.has("title")) { map.title = context.deserialize(json.get("title"), Component.class); } - if (json.has("subtitle")) { - map.subtitle = context.deserialize(json.get("subtitle"), Component.class); - } if (json.has("description")) { map.desc = context.deserialize(json.get("description"), Component.class); } @@ -99,7 +92,7 @@ public GuideMap deserialize(JsonElement src, Type type, JsonDeserializationConte if (json.has("range")) { final float range = json.get("range").getAsFloat(); if (range > 0) { - map.radius = range / 2F; + map.range = range / 2F; } else { LOGGER.warn(MARKER, "Positive range missing, falling back to 256 (blocks)"); } @@ -109,9 +102,29 @@ public GuideMap deserialize(JsonElement src, Type type, JsonDeserializationConte if (json.has("world")) { map.dim = new ResourceLocation(json.get("world").getAsString()); } + if (json.has("texture")) { - map.texture = new ResourceLocation(json.get("texture").getAsString()); + var texture = json.get("texture"); + if (texture instanceof JsonObject jsonObject) { + jsonObject.asMap().forEach((k, v) -> map.textures.put(k, new ResourceLocation(v.getAsString()))); + } else { + map.textures.put("default", new ResourceLocation(texture.getAsString())); + } + } else { + map.textures.put("default", MISSING_TEXTURE); + } + + if (json.has("zoom")) { + var zoom = json.get("zoom"); + if (zoom instanceof JsonObject jsonObject) { + jsonObject.asMap().forEach((k, v) -> map.zooms.put(k, v.getAsDouble())); + } else { + map.zooms.put("default", 1.0); + } + } else { + map.zooms.put("default", 1.0); } + if (json.has("points")) { map.waypointIds = StreamSupport.stream(json.getAsJsonArray("points").spliterator(), false) .map(JsonElement::getAsString) @@ -124,12 +137,6 @@ public GuideMap deserialize(JsonElement src, Type type, JsonDeserializationConte .map(ResourceLocation::new) .collect(Collectors.toList()); } - if (json.has("images")) { - map.imageIds = StreamSupport.stream(json.getAsJsonArray("images").spliterator(), false) - .map(JsonElement::getAsString) - .map(ResourceLocation::new) - .collect(Collectors.toList()); - } return map; } @@ -139,22 +146,38 @@ public JsonElement serialize(GuideMap src, Type type, JsonSerializationContext c if (src.title != null) { json.add("title", context.serialize(src.title)); } - if (src.subtitle != null) { - json.add("subtitle", context.serialize(src.subtitle)); - } if (src.desc != null) { json.add("description", context.serialize(src.desc)); } if (src.center != null) { json.add("center", context.serialize(src.center)); } - json.add("range", new JsonPrimitive(src.radius * 2)); + json.add("range", new JsonPrimitive(src.range * 2)); if (src.dim != null) { json.add("world", new JsonPrimitive(src.dim.toString())); } - if (src.texture != null) { - json.add("texture", new JsonPrimitive(src.texture.toString())); + + if (!src.textures.isEmpty()) { + if (src.textures.size() != 1) { + var jsonObject = new JsonObject(); + for (var texture : src.textures.entrySet()) { + jsonObject.add(texture.getKey(), new JsonPrimitive(texture.getValue().toString())); + } + json.add("texture", jsonObject); + } else { + var jsonPrimitive = new JsonPrimitive(src.textures.get("default").toString()); + json.add("texture", jsonPrimitive); + } } + + if (!src.zooms.isEmpty()) { + var jsonObject = new JsonObject(); + for (var zoom : src.zooms.entrySet()) { + jsonObject.add(zoom.getKey(), new JsonPrimitive(zoom.getValue().toString())); + } + json.add("zoom", jsonObject); + } + if (src.waypointIds != null && !src.waypointIds.isEmpty()) { json.add("points", src.waypointIds.stream() .map(ResourceLocation::toString) @@ -165,11 +188,6 @@ public JsonElement serialize(GuideMap src, Type type, JsonSerializationContext c .map(ResourceLocation::toString) .collect(JsonArray::new, JsonArray::add, JsonArray::addAll)); } - if (!src.imageIds.isEmpty()) { - json.add("images", src.imageIds.stream() - .map(ResourceLocation::toString) - .collect(JsonArray::new, JsonArray::add, JsonArray::addAll)); - } return json; } } diff --git a/src/main/java/org/teacon/signin/data/Trigger.java b/src/main/java/org/teacon/signin/data/entity/Trigger.java similarity index 98% rename from src/main/java/org/teacon/signin/data/Trigger.java rename to src/main/java/org/teacon/signin/data/entity/Trigger.java index b3b0bca..3b31492 100644 --- a/src/main/java/org/teacon/signin/data/Trigger.java +++ b/src/main/java/org/teacon/signin/data/entity/Trigger.java @@ -1,4 +1,4 @@ -package org.teacon.signin.data; +package org.teacon.signin.data.entity; import com.google.common.collect.ImmutableList; import com.google.gson.*; @@ -12,6 +12,7 @@ import net.minecraft.server.level.ServerPlayer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.teacon.signin.data.PlayerTracker; import org.teacon.signin.network.PartialUpdatePacket; import java.lang.reflect.Type; diff --git a/src/main/java/org/teacon/signin/data/Waypoint.java b/src/main/java/org/teacon/signin/data/entity/Waypoint.java similarity index 99% rename from src/main/java/org/teacon/signin/data/Waypoint.java rename to src/main/java/org/teacon/signin/data/entity/Waypoint.java index 4b160e1..1120f9e 100644 --- a/src/main/java/org/teacon/signin/data/Waypoint.java +++ b/src/main/java/org/teacon/signin/data/entity/Waypoint.java @@ -1,4 +1,4 @@ -package org.teacon.signin.data; +package org.teacon.signin.data.entity; import com.google.gson.*; import com.mojang.brigadier.StringReader; @@ -11,6 +11,7 @@ import net.minecraft.server.level.ServerPlayer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.teacon.signin.data.PlayerTracker; import org.teacon.signin.network.PartialUpdatePacket; import java.lang.reflect.Type; diff --git a/src/main/java/org/teacon/signin/network/PartialUpdatePacket.java b/src/main/java/org/teacon/signin/network/PartialUpdatePacket.java index d9d78ce..0d4445e 100644 --- a/src/main/java/org/teacon/signin/network/PartialUpdatePacket.java +++ b/src/main/java/org/teacon/signin/network/PartialUpdatePacket.java @@ -8,9 +8,11 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkEvent; -import org.teacon.signin.client.GuideMapScreen; import org.teacon.signin.client.SignMeUpClient; +import org.teacon.signin.client.gui.MapScreen; import org.teacon.signin.data.*; +import org.teacon.signin.data.entity.Trigger; +import org.teacon.signin.data.entity.Waypoint; import java.util.function.Supplier; @@ -101,8 +103,8 @@ public void handle(Supplier contextGetter) { break; } final Minecraft mc = Minecraft.getInstance(); - if (mc.screen instanceof GuideMapScreen) { - ((GuideMapScreen) mc.screen).refresh(); + if (mc.screen instanceof MapScreen screen) { + screen.refresh(); } }); contextGetter.get().setPacketHandled(true); diff --git a/src/main/java/org/teacon/signin/network/SyncGuideMapPacket.java b/src/main/java/org/teacon/signin/network/SyncGuideMapPacket.java index 4887334..f3aeb86 100644 --- a/src/main/java/org/teacon/signin/network/SyncGuideMapPacket.java +++ b/src/main/java/org/teacon/signin/network/SyncGuideMapPacket.java @@ -10,7 +10,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkEvent; import org.teacon.signin.client.SignMeUpClient; -import org.teacon.signin.data.GuideMap; +import org.teacon.signin.data.entity.GuideMap; import java.nio.charset.StandardCharsets; import java.util.Map; diff --git a/src/main/java/org/teacon/signin/network/TriggerFromMapPacket.java b/src/main/java/org/teacon/signin/network/TriggerFromMapPacket.java index 8f35976..da34b0c 100644 --- a/src/main/java/org/teacon/signin/network/TriggerFromMapPacket.java +++ b/src/main/java/org/teacon/signin/network/TriggerFromMapPacket.java @@ -4,7 +4,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkEvent; import org.teacon.signin.SignMeUp; -import org.teacon.signin.data.GuideMap; +import org.teacon.signin.data.entity.GuideMap; import java.util.function.Supplier; diff --git a/src/main/java/org/teacon/signin/network/TriggerFromWaypointPacket.java b/src/main/java/org/teacon/signin/network/TriggerFromWaypointPacket.java index b357479..8eb97e2 100644 --- a/src/main/java/org/teacon/signin/network/TriggerFromWaypointPacket.java +++ b/src/main/java/org/teacon/signin/network/TriggerFromWaypointPacket.java @@ -4,7 +4,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkEvent; import org.teacon.signin.SignMeUp; -import org.teacon.signin.data.Waypoint; +import org.teacon.signin.data.entity.Waypoint; import java.util.function.Supplier; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 34db690..d795a5c 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[45,)" +loaderVersion="[47,)" license="BSD-3-Clause" [[mods]] @@ -12,14 +12,13 @@ description="Sign up, sign in, in-game guide map and more." [[dependencies.sign_up]] modId="forge" mandatory=true -versionRange="[45,)" +versionRange="[47,)" ordering="NONE" side="BOTH" [[dependencies.sign_up]] modId="minecraft" mandatory=true -versionRange="[1.19.4,)" +versionRange="[1.20.1,)" ordering="NONE" side="BOTH" - diff --git a/src/main/resources/assets/sign_up/textures/gui/gui.png b/src/main/resources/assets/sign_up/textures/gui/gui.png new file mode 100644 index 0000000..1ada3f4 Binary files /dev/null and b/src/main/resources/assets/sign_up/textures/gui/gui.png differ diff --git a/src/test/resources/data/sign_up_test/signup_guides/demo.json b/src/test/resources/data/sign_up_test/signup_guides/demo.json index 3191cfe..563507f 100644 --- a/src/test/resources/data/sign_up_test/signup_guides/demo.json +++ b/src/test/resources/data/sign_up_test/signup_guides/demo.json @@ -1,36 +1,30 @@ { "type": "map", - "title": { "text": "Example Map" }, - "subtitle": { "text": "A demo guide map"}, + + "title": { "text": "Example TeaCon Map" }, + "description": "If you see this, it means that you have successfully created a guide map. Refer to documents for more tricks on how to customize this. Notice that this part also supports mouse scrolling! Try scrolling up and down to see the effect on its long text handling.", + "range": 64, + + "zoom": { + "default": 1.0, + "larger": 2.0, + "magnifier": 4.0, + "microscope": 16.0 + }, + "center": [ 0, 0 ], + "world": "minecraft:overworld", + "texture": "sign_up_test:textures/map.png", - "images": [ - "sign_up:textures/map_default.png", - "sign_up_test:textures/map_image.png" - ], + "points": [ - "sign_up_test:points/point_1", - "sign_up_test:points/point_2", - "sign_up_test:points/point_3", - "sign_up_test:points/point_4" + "sign_up_test:points/point_foo" ], + "triggers": [ - "sign_up_test:triggers/time_set_day", - "sign_up_test:triggers/time_set_night", - "sign_up_test:triggers/greeting", - "sign_up_test:triggers/greeting_disabled", - "sign_up_test:triggers/greeting", - "sign_up_test:triggers/greeting_disabled", - "sign_up_test:triggers/creative", - "sign_up_test:triggers/survival", - "sign_up_test:triggers/greeting_disabled", - "sign_up_test:triggers/greeting", - "sign_up_test:triggers/greeting_disabled", - "sign_up_test:triggers/greeting", - "sign_up_test:triggers/time_set_day", - "sign_up_test:triggers/time_set_night" + "sign_up_test:triggers/teleport" ] } \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/gensokyo.json b/src/test/resources/data/sign_up_test/signup_guides/gensokyo.json deleted file mode 100644 index a2fa793..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/gensokyo.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "type": "map", - "title": { "text": "Gensokyo Map" }, - "subtitle": { "text": "Hi, Earthlings..."}, - "description": "If you see this, it means that you have successfully created a guide map. Refer to documents for more tricks on how to customize this. Notice that this part also supports mouse scrolling! Try scrolling up and down to see the effect on its long text handling.", - "range": 64, - "center": [ 96, 0 ], - "world": "minecraft:overworld", - "texture": "sign_up_test:textures/map.png", - "points": [ - "sign_up_test:points/point_5" - ], - "triggers": [ "sign_up_test:triggers/greeting" ] -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/points/point_1.json b/src/test/resources/data/sign_up_test/signup_guides/points/point_1.json deleted file mode 100644 index 1707945..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/points/point_1.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "type": "point", - "title": "Test Point 1", - "selector": "@e[gamemode=creative]", - "location": { - "actual": [ 10, 70, 10 ], - "render": [ 0, 70, 0 ] - }, - "triggers": [ - "sign_up_test:triggers/teleport", - "sign_up_test:triggers/time_set_day", - "sign_up_test:triggers/time_set_night" - ], - "images": [ - "sign_up_test:textures/point_1a.png", - "sign_up_test:textures/point_1b.png" - ] -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/points/point_2.json b/src/test/resources/data/sign_up_test/signup_guides/points/point_2.json deleted file mode 100644 index aebab99..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/points/point_2.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "type": "point", - "title": "Test Point 2", - "selector": "@e[gamemode=creative]", - "location": { - "actual": [ 20, 0, -20 ] - }, - "triggers": [], - "images": [ - "sign_up_test:textures/point_1a.png", - "sign_up_test:textures/point_1b.png" - ] -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/points/point_3.json b/src/test/resources/data/sign_up_test/signup_guides/points/point_3.json deleted file mode 100644 index 26b9e4f..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/points/point_3.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "point", - "title": "Test Point 3", - "location": { - "actual": [ -30, 0, -30 ] - } -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/points/point_4.json b/src/test/resources/data/sign_up_test/signup_guides/points/point_4.json deleted file mode 100644 index 5fe303c..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/points/point_4.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "point", - "title": "Test Point 4", - "location": { - "actual": [ -40, 0, 40 ] - } -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/points/point_5.json b/src/test/resources/data/sign_up_test/signup_guides/points/point_5.json deleted file mode 100644 index c1b1403..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/points/point_5.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "point", - "title": "Test Point 5", - "location": { - "actual": [ 50, 0, 0 ] - } -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/points/point_foo.json b/src/test/resources/data/sign_up_test/signup_guides/points/point_foo.json new file mode 100644 index 0000000..11cdfde --- /dev/null +++ b/src/test/resources/data/sign_up_test/signup_guides/points/point_foo.json @@ -0,0 +1,21 @@ +{ + "type": "point", + + "title": { "text": "Foo Point" }, + + "description": { "text": "Foo Bar" }, + + "selector": "@e[gamemode=adventure]", + + "location": { + "actual": [42, 84, 0], + "render": [42, 84, 0] + }, + + "images": [ + "sign_up_test:textures/point_1a" + ], + + "triggers": [ + ] +} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/triggers/creative.json b/src/test/resources/data/sign_up_test/signup_guides/triggers/creative.json deleted file mode 100644 index 63cbc31..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/triggers/creative.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "trigger", - "title": "Creative Mode", - "selector": "@e[gamemode=!creative]", - "description": "Set creative mode", - "executes": [ - "/gamemode creative" - ] -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/triggers/greeting.json b/src/test/resources/data/sign_up_test/signup_guides/triggers/greeting.json deleted file mode 100644 index dfad895..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/triggers/greeting.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "type": "trigger", - "title": "Greeting", - "description": "Send salutation to everyone", - "executes": [ - "/me greets everyone" - ] -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/triggers/greeting_disabled.json b/src/test/resources/data/sign_up_test/signup_guides/triggers/greeting_disabled.json deleted file mode 100644 index 869353a..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/triggers/greeting_disabled.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "trigger", - "disabled": true, - "title": "Greeting", - "description": "Send salutation to everyone" -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/triggers/survival.json b/src/test/resources/data/sign_up_test/signup_guides/triggers/survival.json deleted file mode 100644 index adf3d37..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/triggers/survival.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "trigger", - "title": "Survival Mode", - "selector": "@e[gamemode=!survival]", - "description": "Set survival mode", - "executes": [ - "/gamemode survival" - ] -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/triggers/teleport.json b/src/test/resources/data/sign_up_test/signup_guides/triggers/teleport.json index 8826041..ae15140 100644 --- a/src/test/resources/data/sign_up_test/signup_guides/triggers/teleport.json +++ b/src/test/resources/data/sign_up_test/signup_guides/triggers/teleport.json @@ -1,9 +1,16 @@ { - "type": "trigger", - "title": "Teleport", - "description": "Teleport to location", - "executes": [ - "/teleport @s ~ ~ ~", - "/signmeup map close" - ] + "type": "trigger", + + "title": { "text": "Test Trigger" }, + + "description": { "text": "Foo Bar" }, + + "disabled": false, + + "selector": "@e[gamemode=creative]", + + "executes": [ + "/teleport ~ ~ ~", + "/signmeup map close" + ] } \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/triggers/time_set_day.json b/src/test/resources/data/sign_up_test/signup_guides/triggers/time_set_day.json deleted file mode 100644 index 12e0b89..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/triggers/time_set_day.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "trigger", - "title": "Day", - "description": "Set time to day", - "executes": [ - "/time set day", - "/signmeup map close" - ] -} \ No newline at end of file diff --git a/src/test/resources/data/sign_up_test/signup_guides/triggers/time_set_night.json b/src/test/resources/data/sign_up_test/signup_guides/triggers/time_set_night.json deleted file mode 100644 index 3d4bbd6..0000000 --- a/src/test/resources/data/sign_up_test/signup_guides/triggers/time_set_night.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "trigger", - "title": "Night", - "description": "Set time to night", - "executes": [ - "/time set night", - "/signmeup map close" - ] -} \ No newline at end of file