Giter VIP home page Giter VIP logo

maps's Introduction

Minecraft map item

maps

maps is a simple Spigot plugin and api for creating clientside maps and map screens. It is the successor of packet-maps.


Made with ♥ by Cerus


Navigation

Features
Quick start for developers
Building
FAQ
Contributing
Sources


Features

Please note: This is not a standalone plugin, it is a toolkit for other plugins. You will only be able to create and manage map screens with this plugin.

• Clientside maps
• Map screens (arrangement of clientside maps)
• Simple and reasonably lightweight
• Easy to use developer api
• Advanced engine features like alpha compositing (Image)
• Efficient click handling
• Supports 1.16.5 - 1.20.6

What is the point of the plugin module?
See FAQ


Quick start for developers

Please take a look at the wiki for an in-depth explanation of the api.

Maven setup

<dependencies>
    <dependency>
        <groupId>dev.cerus.maps</groupId>
        <artifactId>common</artifactId>
        <version>3.8.5</version>
        <scope>provided</scope> <!-- "provided" if the maps plugin is on the server, "compile" if not -->
    </dependency>

    <!-- You need the plugin module to access the map screen registry of the plugin. -->
    <!-- Don't add this dependency if you have your own storage solution. -->
    <dependency>
        <groupId>dev.cerus.maps</groupId>
        <artifactId>plugin</artifactId>
        <version>3.8.5</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Quickstart

import dev.cerus.maps.api.ClientsideMap;
import dev.cerus.maps.api.MapScreen;
import dev.cerus.maps.api.graphics.ClientsideMapGraphics;
import dev.cerus.maps.api.graphics.ColorCache;
import dev.cerus.maps.api.graphics.MapGraphics;
import dev.cerus.maps.plugin.map.MapScreenRegistry;
import dev.cerus.maps.version.VersionAdapterFactory;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.map.MinecraftFont;
import org.bukkit.plugin.java.JavaPlugin;

public class MyPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        // This example depends on the "common" and "plugin" dependency.

        for (final MapScreen screen : MapScreenRegistry.getScreens()) {
            final MapGraphics<?, ?> graphics = screen.getGraphics();
            graphics.fillComplete(ColorCache.rgbToMap(255, 255, 255)); // Convert rgb(255, 255, 255) to map color and fill the screen
            graphics.drawText(5, 5, "There are " + Bukkit.getOnlinePlayers().size() + " players on the server", ColorCache.rgbToMap(0, 0, 0), 2);
            screen.spawnFrames(Bukkit.getOnlinePlayers().toArray(new Player[0])); // Send the screen frames to all online players
            screen.sendMaps(true); // Send map data to all online players
        }
        getCommand("mapstest").setExecutor(this);
    }

    @Override
    public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
        // It's been ages since I've used the normal Bukkit command system 
        // so please forgive me if I use any bad practices here
        if (!(sender instanceof Player player)) {
            return true;
        }
        if (!command.getName().equals("mapstest")) {
            return true;
        }

        // This is really unsafe. Always do proper checks before casting 
        // things, but this will do for the sake of this quick start.
        final ItemStack item = player.getInventory().getItemInMainHand();
        final MapMeta mapMeta = (MapMeta) item.getItemMeta();
        final int mapId = mapMeta.getMapView().getId();

        final ClientsideMap clientsideMap = new ClientsideMap(mapId); // Create clientside map with given id
        final ClientsideMapGraphics graphics = new ClientsideMapGraphics(); // Create graphics buffer

        graphics.fillComplete(ColorCache.rgbToMap(0, 0, 0)); // Fill with rgb(0, 0, 0)
        graphics.drawText(5, 5, "Hello,", ColorCache.rgbToMap(255, 255, 255), 1); // Draw text
        graphics.drawText(5, 5 + MinecraftFont.Font.getHeight() + 5, player.getName(), ColorCache.rgbToMap(255, 255, 255), 2);

        clientsideMap.draw(graphics); // Draw the buffer onto the map
        clientsideMap.sendTo(new VersionAdapterFactory().makeAdapter(), player); // Send the map to the player
        return true;
    }

}

Building

Requirements: Java 21, Git, Maven, CraftBukkit 1.16.5, 1.17.1, 1.18.1, 1.18.2, 1.19.1, 1.19.3, 1.19.4, 1.20, 1.20.2, 1.20.4 and 1.20.6 installed in local Maven repo

Simply clone the repository, navigate into the directory and run mvn clean package. The plugin will be in plugin/target and the api in common/target.


FAQ

Why is there a plugin module if maps is not a standalone plugin?
The plugin handles the creation, management and storage of map screens. You do not need the plugin if you make your own creation, management and storage solution.

Please feel free to open an issue or contact me if you have any questions that were not answered here.


Contributing

Thank you for your interest in contributing to this project! Before you do anything though please read the contribution guidelines thoroughly. Contributions that do not conform to the guidelines might be rejected.


Sources

Lots of graphics features were implemented with the help of the following resources:

maps's People

Contributors

cerus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

maps's Issues

Map resolution

Feature description

Currently I cannot find any way to resize a map using your API, it looks like there's currently a set size of 128 with the final WIDTH variable in the ClientSideMap and ClientsideMapGraphics classes.

It would be nice if you could expose a way to change the map resolution.

Relevant issues

Why constants :(

Improve MapGraphics.java documentation

Feature description

The MapGraphics class is probably the most important class of this whole project. Thus it is very important to properly document everything. Some methods are not well documented (the description of drawText for example is literally just "Draws text") and need to be improved.

Relevant issues

No response

MapScreen.java Broken

Issue description

I can never get my MapScreens to create due to issues in the console, and under some investigation, it seems out of my control.

To reproduce

		session.updateScreen(); //Update the screen.
		session.screen.spawnFrames(player); //Spawn the frames.
		session.screen.sendMaps(true, player); //Send the maps to the player.

This is my code, the session.updateScreen() handles the screen update and spawnFrames(player) SHOULD spawn the frames- but it doesn't, instead it throws a null pointer saying this.frames is not set. I looked into your Map Screen class and it attempts to get this.frames[x][y] but the this.frames variable was never setup within the class whatsoever, so therefore it just keeps throwing errors upon attempting to create it.

Expected behaviour

For map screens to actually show and not throw a null pointer.

Screenshots / videos

Look into MapScreen.java to see what I mean, it's pretty self-explanatory, but here's the log as well I keep getting.
java.lang.NullPointerException: Cannot load from object array because "this.frames" is null at com.legacymc.legacyrp.libraries.maps.api.MapScreen.spawnFrames(MapScreen.java:191) ~[LegacyRP-0.0.1.jar:?]

Additional information

No response

Non-standard fonts get cut off

Issue description

Cursive / italic / non-standard fonts will be cut off at the sides.

To reproduce

Draw text with a cursive font, such as Bluetea.

Expected behaviour

Normal text drawing without any cut off characters.

Screenshots / videos

Img

Additional information

No response

Add documentation

The code is lacking some documentation. This is a nice starter issue if you're kind of new to Open Source or Spigot or just want to work on something simple. (You don't have to comment everything if you don't want to, but it would be nice if you document at least one module.)

Comment if you want to work on this. If you have any questions or need some help feel free to contact me.

Optimizing raycasting operations

Feature description

Hey,

I've been experimenting with making my own map rendering engine, and I'd like to leave some tips for just better overall performance:

There are 3 ways you can approach raycasting, it seems like you're doing method 1:

Method 1:

  • Grab the start location, and add a very tiny miniscule offset, increment by that offset until you reach a frame. (It takes about 5 * 1/offset * distance operations, if your offset is 1/128, you're doing 640 iterations, measures at about 3ms / cast on my machine

Method 2 (1+):

  • Grab the start location, and increment by the normalized offset, until there's a frame at the current block. Then, do a finer cast through method one (1-5 + (1/offset iterations, if there is a frame)) - About 5x better, measures at about 0.1ms / cast on my machine

Method 3:

  • Grab the start location, and increment by the normalized offset. If there is a frame at the current block, estimate the frame's bounding box by grabbing the frame's center location, and shifting in the opposite direction of where the frame is looking at, you'll always end up with ceil(distance) iterations, instead of <DISTANCE * STEPS_PER_BLOCK>, measures at about 0.015ms / cast on my machine

Further optimizations:

  • Cache the converted colors of your ColorMap, from what I've measured, mapping colors takes about 90 microseconds per color, but marginally less if cached.

Relevant issues

No response

Support for Minecraft 1.20.2

Feature description

Minecraft 1.20.2 has been officially released today. You may need to update the NMS Adapter to version 1.20.2 in order to use it properly.

Relevant issues

No response

Push 3.8.3 to Maven

Feature description

Hi, lovely API, but can you release 3.8.3 to Maven? It would never download, and after a quick look, I saw that no maven site is showing 3.8.3 released. I would love 1.20.4 support :)

Relevant issues

No response

ClientsideMap questions

Feature description

I found that in the Quickstart example, it is necessary to have a valid MapID in order to create a ClientsideMap. Is it possible to create a ClientsideMap without using a valid MapID? I don't want to require players to first create any files in the "./world/data" directory using the original method. Can alternative methods, such as custom NBTTag or other approaches, be provided to determine the ClientsideMap?

Relevant issues

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.