LevelEdit


LevelEdit

A minecraft plugin library that allows the easy creation of level editor like environments.

This plugin is a library and does notion by itself, instead, it allows other plugins to register building areas and sets of schematics for players to be able to place down. As a quick start:

Registering a schematic

First we need to create a template or prototype for the level object, all spawned level objects will be clones of this schematic.

LevelObjectTemplate[] templates = new LevelObjectTemplate[] {
                new LevelObjectTemplate("Display Name", 
                        LevelObjectSchematic.loadTemplate(new File("Template.dat")), 
                        RotationAxis.ALL)
};

Many templates could be provided here or just one, then we register those templates with our level editor.

Location cent = Bukkit.getWorlds().get(0).getSpawnLocation();
Level mainLevel = new Level(cent,
                new Rectangle(cent.getBlockX()-10, 
                        cent.getBlockX()+10, 
                        cent.getBlockY()-10, 
                        cent.getBlockY()+10),
                templates);

This creates a 20 by 20 rectangle around the world spawn where the player can place level objects given by templates.

Now lets register some listeners for events on these objects:

  • LevelObjectCollisionEvent Is fired when a player hits a level object, the event passes the player and the level object instance (along with its template) .
  • LevelObjectPickupEvent Is fired when a player picks up a level object that was previously placed down, NOT when the object is initially spawned from the template selector.
  • LevelObjectPlaceDownEvent Is fired when the player places down a level object.

The level object template is easily extensible if additional data is needed:

 public static class CustomLevelObjectTemplate extends LevelObjectTemplate{

        @Getter @Setter
        private int myCustomData;

        public CustomLevelObjectTemplate(LevelObjectSchematic s, RotationAxis rt, int data) {
            super("Static Display Name", s, rt);
            this.myCustomData = data;
        }
}

The level object class itself has many configuration options however. A material can be given which will be used as the templates item in the template selector (you could retexture an item and its 3d texture would render in the chest interface for example). In addition, a larger hitbox can be given that allow the collision event to fire if the player hits the hitbox rather than if the player hits the object itself. Lastly, The avalible planes of rotation can be changed. By default, left clicking with the level object selected will rotate through north->east->south->west->top->bottom, however you can lock these to only a single plane or rotation. Similarly, the user can rotate the face of the schematic by switching hands (r).

To lock the planes of ration, the RotationAxis enum can be passed with ALL, XY_PLANE, YZ_PLANE, or ZX_PLANE.