objd_dungeon 0.1.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 47

objD Dungeon #

The objd_dungeon package is a set of widgets that allow you to build a dungeon generator as a datapack easily by just defining some arguments in objD. The Dungeon Widget will change your output files, the load function and the behavior of the game. Nonetheless this is just an extension for my framework objD, so you are able to change the way it generates a Minecraft Datapack and add content to it.

Getting started #

Let's get started by taking a look at this dungeon that it generated with this package: https://streamable.com/s/vaq26/wnests

We can divide this into several 'Structurepools' the pieces that make up the dungeon. enter image description here We notice it is actually just 6 different types here. Some have a connection to another room, some don't. In objd this setup looks like this:

	"straight":  StructurePool(["straight/straight"], front: true),
	"curve":  StructurePool(["curve/curve"], mirror: true),
	"split":  StructurePool(["split/split"], left: true, right: true),
	"t":  StructurePool(["t/t"], mirror: true, front: true),
	"x":  StructurePool(["x/x"], right: true, left: true, front: true),
	"end":  StructurePool(["end/end"])

Structure Pools #

So in the first argument, we can define our room types and assign a StructurePool to each type. This StructurePool is a group of structures, that get randomly chosen in the game, and a definition for the next room(s):

List of StringsA list of structures(without the namespace, this can be done with the pack property)
frontshould the structure generate a new room in front?(optional)
leftshould the structure generate a new room on the left side?(optional)
rightshould the structure generate a new room on the right side?(optional)
mirrorshould the structure choose randomly between right and left and mirror the structure(you just have to build turns for example just once)
biasThere is a certain chance to get a StructurePool that is usually divided between all pools. With this double you can force the percentage(0.05 ⇒ 5%)
patha String that is added in front of all structures as a folder path(optional)
packthe namespace where the structure files lay(default = current pack)

That's a lot of properties, but if you consider the complexity this becomes really simple.

You can also say what size your structures are with a list of integers representing coordinates:

size: [21,9,21]

Although there is an option for the z-coordinate this generator just supports squared rooms.

The position handling and the structure loading is done by entities. So you have to define what kind of entity you want to summon and from where to execute functions.

In the dungeon Widget this can be done with: summon - A summon Widget, Armorstand or Areaeffectcloud that should be created as new room(I encourage to use the tags dungeon_room as well as dungeon_new here) entity - The entity from where to generate a room: same tags, etc. as summon but as Entity.

In code this could look like this:

summon: Armorstand(Location.here(),tags:["dungeon_room","dungeon_new"],gravity:false),
entity: Entity(type: Entities.armor_stand,tags:["dungeon_room","dungeon_new"])

To make the Dungeon Widget functional we also need to define a pack, where it should generate. This pack has to have a load file to generate all the scoreboards properly:

pack: Pack(name:"dungeon",load:File(path:"load")),

Our entire code looks like this:

   "straight": StructurePool(["straight/straight"], front: true),
   "curve": StructurePool(["curve/curve"], mirror: true),
   "split": StructurePool(["split/split"],left: true, right: true),
   "t": StructurePool(["t/t"], mirror: true, front: true),
   "x": StructurePool(["x/x"], bias: 0.05, right: true, left: true, front: true),
   "end": StructurePool(["end/end"], bias: 0.05),
  pack: Pack(name: "dungeon", load: File(path: "load")),
  summon: ArmorStand(
   tags: ["dungeon_room", "dungeon_new"],
   basePlate: false,
  entity: Entity(
   type: Entities.armor_stand,
   tags: ["dungeon_room","dungeon_new"],

which is actually not that much. When you build the project you get a fully functioning datapack with many functions. The most important function for you is the generate function.

If you run this function from an entity ingame, a random structure would appear at the entities position.

Generate Function #

The generate function can be split into 4 parts:

  • setstructure - This part randomly chooses a StructurePool with the specified percentages depending of the open area and a random structure from that pool and sets a structureblock
  • addtags - The entity gets some tags here defining the directions of the doors etc. (e.g. dungeon_end, dungeon_door_left...)
  • rotatestructure - The structure is rotated and mirrored in this part to match the entities rotation and local coordinates. That way all the entrances and exists of the rooms align perfectly. The structure is also loaded.
  • summonnew - This step summons new entities in the specified directions(front,left,right,mirror) to generate a new room.

Start and End Pools #

But this generate function is not everything. If you don't want to code the generation yourself or do it manually there is a start option and a timer that generates all new rooms every defined ticks:

start:  StructurePool(["start","start2"]),
startAndTimer:  5, 			// 5 ticks delay

Of course this is not infinite because the amount of entities is growing exponentially. So you can set a limit here with the iterations(default = 5).

iterations: 8,

And if the timer reaches this limit, you can also define an end structure pool to pick a random dead end structure:

end:  StructurePool(["end/end"]),

Dungeon Widget #

So to recap here are all potential properties of the Dungeon Widget:

Map of StructurePoolsname-value pairs that specify the different room types and tell the widget where to generate new rooms(required)
sizeList of integers defining the size in each direction(default = 15x8x15)
packa Pack to generate the files into(need load file!) |required
summonan Armorstand, Areaeffectcloud or Summon Widget to create a new entity that generates a room |required
entityan Entity that should generate a room(by tag ...) |required
starta StructurePool defining the structures generated with the start function
startAndTimeramount of ticks between each generation of the specified entity, set to -1 to disable the timer(default = 10)
iterationshow many iterations the timer passes(default = 5)
enda StructurePool defining the structures that generate if the iteration limit is reached(dead end)
clearEntityif specified generates a clear function that let's you clear the generated dungeon based on an Entity
afterGenerationanother Widget to execute after each generate function finished, good for removing tags etc.

I hope this article gave you a good overview over my Dungeon extension. If you have questions or suggestions though feel free to contact me via discord: https://discord.gg/WVDFXUv or take a look at my youtube video: here

0.1.4 #

  • updated objD to 0.3.3
  • Refactoring Code

0.1.3 #

  • Updated objD and applied new best practises
  • Refactoring Code

1.0.0 #

  • Initial version, created by Stevertus


// import the core of the framework:
import 'package:objd/core.dart';
// import the generator:
import 'package:objd_dungeon/generator.dart';

void main() {
      name: 'Dungeon Pack',
      target: './', // path for where to generate the project
      generate: Dungeon(
        // defining the structure pools:
          'straight': StructurePool(['straight/straight'], front: true),
          'curve': StructurePool(['curve/curve'], mirror: true),
          'split': StructurePool(['split/split'], left: true, right: true),
          't': StructurePool(['t/t'], mirror: true, front: true),
          'x': StructurePool(['x/x'],
              bias: 0.05, right: true, left: true, front: true),
          'end': StructurePool(['end/end'], bias: 0.05),
        end: StructurePool(['end/end']),
        start: StructurePool(['start']),
        // delay between generations:
        startAndTimer: 5,
        // how often to repeat:
        iterations: 8,
        // the underlying pack:
        pack: Pack(name: 'dungeon', load: File('load')),
        summon: ArmorStand(
          tags: ['dungeon_room', 'dungeon_new'],
          basePlate: false,
        entity: Entity(
          type: Entities.armor_stand,
          tags: ['dungeon_room', 'dungeon_new'],
        afterGeneration: Tag('dungeon_new', entity: Entity.Self()).remove(),

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  objd_dungeon: ^0.1.4

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:objd_dungeon/generator.dart';
import 'package:objd_dungeon/generator/addTags.dart';
import 'package:objd_dungeon/generator/createNew.dart';
import 'package:objd_dungeon/generator/dungeon.dart';
import 'package:objd_dungeon/generator/rotateStructure.dart';
import 'package:objd_dungeon/generator/setStructure.dart';
import 'package:objd_dungeon/utils/changeRot.dart';
import 'package:objd_dungeon/utils/matchRange.dart';
import 'package:objd_dungeon/utils/randomStructure.dart';
import 'package:objd_dungeon/utils/structurePool.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health issues and suggestions

Document public APIs. (-1 points)

117 out of 117 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

The package description is too short. (-16 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
meta ^1.1.8 1.2.1
objd ^0.3.3-1 0.3.3
Transitive dependencies
archive 2.0.13
args 1.6.0
charcode 1.1.3
collection 1.14.13 1.15.0-nnbd
colorize 2.0.0
convert 2.1.1
crypto 2.1.5
gson 0.1.4
path 1.7.0
typed_data 1.2.0 1.3.0-nnbd
Dev dependencies
pedantic ^1.9.0