Giter Club home page Giter Club logo

gdpc's Introduction

GDPC

GDPC (Generative Design Python Client) is a Python framework for use in conjunction with the GDMC-HTTP mod for Minecraft Java edition. It is designed for the Generative Design in Minecraft Competition (GDMC).

You need to be playing in a Minecraft world with the mod installed to use the framework.

The latest version of GDPC is compatible with GDMC-HTTP versions >=1.0.0, <2.0.0 and Minecraft 1.20.2 (see note).

Quick example

from gdpc import Editor, Block, geometry

editor = Editor(buffering=True)

# Get a block
block = editor.getBlock((0,48,0))

# Place a block
editor.placeBlock((0,80,0), Block("stone"))

# Build a cube
geometry.placeCuboid(editor, (0,80,2), (2,82,4), Block("oak_planks"))

What's the difference between GDMC, GDMC-HTTP and GDPC?

These abbreviations are all very similar, but refer to different things.

GDMC: Short for the Generative Design in Minecraft Competition, a yearly competition for generative AI systems in Minecraft. The challenge is to write an algorithm that creates a settlement while adapting to the pre-existing terrain. The competition also has a Discord server.

GDMC-HTTP: A Minecraft Forge mod that provides a HTTP interface to edit the world. It allows you to modify the world live, while you're playing in it. This makes it possible to iterate quickly on generator algorithms. The mod is an official submission method for the competition.

GDPC: This repository (notice the "P"). A Python framework for interacting with the GDMC-HTTP interface. It provides many high-level tools that make working with the interface much simpler.

Installation

GDPC requires Python 3.7 or above. It is available on PyPI; to install, run:

python3 -m pip install gdpc

To update, run:

python3 -m pip install --upgrade gdpc

On Windows, you may need to replace python3 with py.

If you would like to install the latest cutting-edge development version directly from GitHub, replace gdpc with
git+https://github.com/avdstaaij/gdpc
For more information on installing from GitHub (such as getting old versions), see the pip documentation.

Tutorials and examples

There are various tutorial scripts that will help to get you started:

Tutorial Description
Hello block Place and retrieve a single block in the world.
Vectors Use vector math and some of GDPC's various vector utilities.
Build area Get the specified build area and use it to place a block inside the bounds.
World slice Load and use a world slice for faster read access.
Geometry Use the geometry module to place geometrical regions of blocks.
Advanced blocks Place blocks with block states and block entity data, and use block palettes.
Editor performance Use the Editor class's various optional performance features.
Transformation Use GDPC's powerful transformation system.

Some practical examples are also available, though they're slightly older and may not reflect the latest features:

Example Description
Visualize map Displays a map of the Minecraft world using OpenCV.
Emerald city Demonstrates basic GDPC functionality by building a simple model of the Emerald City.

Note: the links above always point to tutorials/examples for the latest release of GDPC. To view the examples for an older version, switch to the tag for that version (using the dropdown box at the top left of the file list, where it probably says "master"), and manually navigate to the examples.

Note on supported Minecraft version

We list a specific compatible version of Minecraft, but most of GDPC actually supports a wide range of Minecraft versions. In particular, basic block getting and setting should work with any Minecraft version for which there is a compatible version of GDMC-HTTP. The parts of GDPC that may not be compatible with Minecraft versions other than the listed one are those that interact with "Minecraft data". These include:

  • Rotation and flipping of individual blocks.
  • Utility functions from the minecraft_tools and editor_tools modules that generate Minecraft data, such as bookData and placeSign.
  • The WorldSlice class and associated functions like Editor.loadWorldSlice().

We are working on fully supporting multiple versions of Minecraft simultaneously (#99), but this probably won't be done soon.

Contributing

See CONTRIBUTING.md for information about how to contribute.

Acknowledgements

GDPC was progressively developed with the help of various members of the GDMC community. Of special note are Niki Gawlik, who started both GDMC-HTTP and GDPC, and Blinkenlights, who previously maintained the project.

gdpc's People

Contributors

avdstaaij avatar boerdereinar avatar caranha avatar cmoyates avatar eman1can avatar flashing-blinkenlights avatar mayankjainllrl avatar mttvdn avatar niels-ntg avatar nikigawlik avatar phobos97 avatar xlenstra avatar zaneleo111 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

gdpc's Issues

Issue in worldLoader.py: unable to read file buffer

Moved from nikigawlik/gdmc_http_client_python#73, by @HSTEHSTEHSTE:
See nikigawlik/gdmc_http_client_python#73 for more discussion.


Line 57 in worldLoader.py is unable to read file buffer:

Error: Internal server error: java.util.ConcurrentModificationException Traceback (most recent call last): File "c:\Users\HSTE\GMDC_2022\examples\simple_village.py", line 64, in <module> WORLDSLICE = WL.WorldSlice(STARTX, STARTZ, File "C:\Users\HSTE\AppData\Local\Programs\Python\Python39\lib\site-packages\gdpc\worldLoader.py", line 58, in __init__ self.nbtfile = nbt.nbt.NBTFile(buffer=file_like) File "C:\Users\HSTE\AppData\Local\Programs\Python\Python39\lib\site-packages\nbt\nbt.py", line 641, in __init__ self.parse_file() File "C:\Users\HSTE\AppData\Local\Programs\Python\Python39\lib\site-packages\nbt\nbt.py", line 675, in parse_file raise MalformedFileError( nbt.nbt.MalformedFileError: First record is not a Compound Tag

Adding a print statement just before the NBT file load solves the issue (albeit in unsatisfactory manner).

Could some shed some light on what might be causing the issue? Thanks!

Advanced Tutorial Master Issue

Feature branch: 5.1

This issue attempts to outline and organise the goals for the GDPC 5.x advanced tutorial.

Goals

  1. The generator demonstrates all major and most minor features of GDPC (see Features)
  2. The generator fulfils the minimum viable product requirements (see MVP)
  3. The generator contains code and systems that may be easily modified for use in other projects
  4. The generator is creative and unique and can provide inspiration for other participants
  5. The generator fulfils the technical requirements for GDPC 2022 (see Requirements)
  6. The generator is submitted to GDPC 2022 and achieves an above-average score

Roadmap

See Projects -> Advanced Tutorial

Requirements

  • Runtime <= 10 minutes
  • RAM usage <= 2GB
  • Can handle a build area of 1000x255x1000
  • Player is positioned in the centre of the build area (and directed towards generated settlement)
  • Can handle generated and player-made structures

MVP

1.Fulfils competition requirements
2. Places settlement in sensible location
3. Uses template structures
4. Uniform paths connect structures to spawn point
5. Pre-existing structures are avoided and ignored

Features

World analysis:

  • Global slices
  • Biomes
  • Obtrusiveness and optimal direction
  • Versions
  • Block categories

World manipulation:

  • Interfaces
  • Running commands
  • Manipulating build area
  • Placing blocks (advanced)
  • Placing geometric shapes (advanced)
  • Placing lecterns, signs, blocks with inventory

Utility:

  • 2D/3D loops
  • Book writing
  • Speeding up ticks for tree growth

Optimisation:

  • Keeping time
  • Caching
  • Buffering
  • Hint: LRU Cache

Generator Architecture

4-phase process:

  1. World analysis
  2. Settlement setup/essentials/plot reservation
  3. Settlement expansion and improvement (variable, finite length of time)
  4. Settlement cleanup and beautification (remaining time)

Circular imports

Feature branch: 5.1

The current module structure makes circular imports fairly easy. The package should be restructured to improve the architecture and minimize the risk of creating circular imports while still allowing for flexibilities.

Treecutting function

Moved issue from nikigawlik/gdmc_http_client_python#24, by @Flashing-Blinkenlights (edited):


Currently, dealing with trees in forested areas can be difficult and improper execution can result in floating trees or leaves that won't decay due to nearby logs. It would be very convenient to have a function that, when called on a particular coordinate, detects and cleanly removes the tree.
Caution may be taken not to remove e.g. wooden support pillars (from mineshafts etc.).
Depending on the type of tree (e.g. Acacia), further steps may need to be taken to effectively remove the tree.


Some more discussion can be found in nikigawlik/gdmc_http_client_python#24.

Importing the library without a world open should behave more clearly

Moved from nikigawlik/gdmc_http_client_python#69, by @caranha:


If you import sub-modules from the library (for example, GEO) without a minecraft world open, a large scary error message shows.

Either you should be amble to import sub-modules without a world running, or if that is impossible, a better error message (i.e "Don't forget to open the minecraft world before loading this module!") should be displayed (or maybe an appropriate error should be thrown?)

Support for Minecraft 1.19.2

Niels-NTG/gdmc_http_interface#5 adds support for Minecraft 1.19.2 to the HTTP interface mod. Quoting that PR:

Code behind the /chunks endpoint didn't change. Clients using this endpoint do however need to be changed to account for different data structure due to 3D biomes.

Support for 3D biomes should be added to GDPC so that the HTTP interface can be updated.

Criterion: Chronicle

Feature branch: None

One of the criteria for GDPC 2022 is 'Chronicle
It may include:

  • Intricate books and signage
  • Documentation of past events which shaped the settlements
  • Documentation of additional context (beliefs, rituals etc.)
  • Biographies of individual people
  • High uniqueness compared to other maps (same generator)

Ideas

  • Story of girl who became victim to illager invasion
  • Fragments of story dispersed throughout world to encourage exploration
  • Describing points of interest using landmark positions (e.g. 'north of the mines', 'centre of the lake')

Complete and improve `lookup` blocks

Feature branch: 5.1

The sets of blocks in lookup is fairly messy, with some blocks missing and a lot of repetition. Steps should be taken to clean up this information and tests made to make sure no blocks are overlooked.

  • Use set comprehensions for block variations
  • Eliminate redundancy where possibly
  • Highlight redundancies
  • If possible, cross-reference with client's assets

Structure detection

Feature branch: None

Since structures are an important factor in adaptability, various features may be useful, such as:

  • (essential) Detection of blocks occupied by artificial structures
  • Connection to pre-existing road networks
  • Identification of unique structures (e.g. temples)
  • Modification of existing structures

Enhance testing suite

Moved from nikigawlik/gdmc_http_client_python#61, by @Flashing-Blinkenlights:


Currently testing is done by a single script and the tests cover very little functionality. Ideally we should make use of better-suited tools and extend the range of tests to encompass the entire codebase.

It might be sensible to do this sooner rather than later

Pro:

  • Will significantly improve project stability
  • Will speed up testing and debugging time

Con:

  • Will take a lot of time to implement

Geometric fill/outline tools

Moved issue from nikigawlik/gdmc_http_client_python#39, by @Flashing-Blinkenlights:


It would be nice to have a selection of functions to draw a variety of geometric shapes efficiently, both filled and hollow.
Some ideas for useful shapes:

  • Cuboids
  • Point-to-point shapes / polygons
  • Circles, ellipses and cylinders
  • Ellipsoids
  • Arches
  • Repeated shapes
  • Transformed shapes
  • Rotated shapes

Suggested implementation:

Using various combinations of Bresenham's algorithms

Narrative text generation

Feature branch: None

For criteria #3 #4 and #6 the ability to turn data into immersive, human-readable text would be useful.
This might include:

  • Creating directional signage from start and end coordinates and location name
  • Creating location descriptions/directions from various parameters
  • Creating structure descriptions based on structure attributes

Add a Discord link to the readme

There should be a link to the GDMC Discord in the readme, especially since it contains channels for discussing frameworks and reporting bugs.

Should GDPC include pre-made generation?

See also: #9 (comment)

Should GDPC (eventually) include pre-made generation of structures, settlements, chronicle text, etc.? Where should the line be drawn?

Positives:

  • It avoids re-inventing the wheel for some common structures.
  • It may make it easier for new users (generator developers) to get started.
  • It makes it possible for developers to focus on higher-level settlement design, instead of specific buildings.

Negatives:

  • It will likely reduce generator diversity and creativity, as users will be more likely to base their generator on the provided generation algorithms, and they will be less likely to create their own versions of the provided structures.
  • It may give users the false idea that the overall style of the included generation is the "official" one.

This question should probably be answered by means of community polls and discussions with the GDMC organizers.
In any case, pre-made generation is a very low-priority feature.

Settlement location determination

Feature branch: None

Determine starting location to place settlement

To do

  • (essential) Determine flat areas
  • Determine places near water (#11)
  • Determine defensible places
  • Determine places with high traffic (#8)
  • Determine places rich in resources
  • Determine beautiful places
  • (essential) Determine starting chunk

Type hints

The entire library should be properly type hinted.

Artificial feature generation

Feature branch: None

For the sake of this issue, artificial features are objects that are continuous in nature and directly adapt to the surrounding topology.
For finite objects, see #9
Many of these objects may be part of an area, see #10

Transport

  • Stepping stones: crossing shallow water
  • (essential) Paths: connecting points of interest (inspiration)
  • Canals: connecting bodies of water
  • Bridges: crossing ravines or deep water
  • Tunnels: connecting through mountains
  • Railways: transport of heavy goods for short distances
  • Secret tunnels between points of interest

Food, drink and health

  • Irrigation: channels connected to freshwater source (in rows spaced by 8 blocks)
  • Sewage: channels connecting houses to freshwater source
  • Crop field: monoculture farmland
  • Pasture: grassy plains for keeping livestock on farmland
  • Fencing: surrounding areas and dangers
  • Hot springs: on top of lava lakes?

Defence

  • Berms: under paths along steep terrain
  • Trenches/moats: surrounding fortified settlement
  • Flood wall: along riverbank for settlements prone to flooding
  • (essential) Palisades: surrounding settlement
  • Defensive wall: surrounding settlement

Industry

  • Mineshaft: Strip-mine or cave supports
  • Quarry: By exposed rock
  • Scaffolding: On quarries and buildings under construction

Culture

  • Climbing site: on steep mountainsides
  • Ice skating rink: on frozen water

Decoration

  • Fences / walls along paths

Area/district generation

Feature branch: None

Since the inhabited area will likely contain specialised regions, these will need to be defined.
They may make use of various objects, see #9 and #14

Geographic

  • Ocean
  • River
  • Lake: larger than a chunk
  • Pond: smaller than a chunk
  • Lava lake

Residence

  • (essential) Gathering place
  • (essential) Campsite
  • (essential) Housing
  • Labour camp: near natural resource
  • Refugee camp: far from illager structures

Transport

  • Docks: by the ocean in a large settlement

Food, drink and health

  • (essential) Farmland: flat, fertile soil; large, irregularly shaped surfaces

Defence

  • Military encampment
  • Training grounds: in settlement or military encampment

Industry

  • (essential) Workshops
  • Logging site: in forest
  • Quarry / surface mine: near cliff exposed stone
  • Shipyard: adjoining docks by the ocean

Culture

  • Marketplace: on busy intersections
  • Ruins: in isolated locations
  • (essential) Burial grounds: flat terrain on outskirts of settlement
  • Hermitage: in almost inaccessible location

Implementation suggestion

class Area():
  parent = None  # optionally contains Area instance
  surface = []  # list of (x, y, z) tuples
  access_points = [] # list of (x, y, z) points for pathfinding
  
  
  populate():
    # place stuff, maybe terraform

  fitness(x, y, z):
    """"Determine the suitability of a given block to be in the area.""

`setBuffering(false, notify=false)` does not flush the buffer

Using Interface.setBuffering(false, notify=false) while buffering is enabled does not flush the Interface's block buffer, because self.__buffering is not checked if notify == false.

Since some geometry functions automatically enable and disable buffering with notify=false, those geometry placements will be buffered even if buffering is turned off.

This is trivial to fix, but should perhaps wait until the library has been refactored.

Criterion: Visual Aesthetics

Feature branch: None

One of the criteria for GDPC 2022 is 'Visual Aesthetics'
It may include:

  • Variations/parametrisation of structures
  • Usage of sight lines (uninterrupted view of landmarks from between buildings)
  • Usage of a limited and tasteful palette
  • Usage of textures and interesting geometry
  • Unique decoration
  • Choice of materials, architecture and decoration reflect narrative

Ideas

  • Early medieval, viking-inspired architecture (adaptation to desert?)

Chronicle treasure-hunt

Feature branch: None

For the chronicle challenge (see #6) it would be fun to turn write a story that is spread across points of interest of the map.

Story Fragment Suggestions

  1. Troglo is a villager living in a vanilla village (may be outside of build area)
  2. Vanilla village is attacked and
  3. Troglo is forced to flee to a cave

Locations with Story Fragment

  • Troglo's burial mound (essential)
  • Troglo's cave (essential)
  • Bottom of a lake
  • Illager historian's house

Better integration of Interface and WorldSlice

The integration of Interface and WorldSlice is currently rather convoluted: there is a single global WorldSlice that is used when caching is enabled, but it needs to be initialized and updated explicitly with functions that do not appear in any example. Furthermore, some functions interact with it in unexpected ways. For example, requestBuildArea marks all blocks in the global WorldSlice as up-to-date, which is not well documented and may be incorrect.
Going on, Interface.setCaching behaves differently for the global interface than for other interfaces, and the implementation for the global interface appears to be incorrect (it looks like it might lead to indexing globalDecay which has been set to None in Interface.getBlock). At the very least, its behavior difficult to follow.

All this should be cleaned up and improved, preferably without the use of globals.

Waterway detection and naming

Feature branch: None

Waterways will likely serve an integral part in the narrative and functional aspects of the settlement, which is why they should be identified and given names.

To do

  • Detect bodies of water
  • Connect detected bodies and make inspecting connectivity accessible
  • Name connected bodies for use in narration
  • Mark points of interest (waterfalls, deltas etc.)

Criterion: Believable and Evocative Narrative

Feature branch: None

One of the criteria for GDPC 2022 is 'Believable and Evocative Narrative', which should be implemented in an implicit way
It may include:

  • History of the settlement (visible)
  • History of the people inhabiting the settlement
  • Culture and beliefs of the people inhabiting the settlement
  • Distinct visual/architectural identity (see #5)

Ideas

  • Settlers are illagers that have migrated from across the ocean (Viking-inspired)
  • Settlers are illagers who wish to reclaim their lands (native American-inspired)
  • Ship burials under earthen mounds
  • Belief in a pantheon (Mojang?)

Fix tests

After #51, the semi-automatic tests are broken (or perhaps they were before).
The tests should be fixed.

Criterion: Functionality from an Embodied Perspective

Feature branch: None

One of the criteria for GDPC 2022 is 'Adaption to Environment and Terrain'
It may include:

  • Accessibility and mobility between structures
  • Accessibility and mobility between points of interest
  • Protection from mob spawning
  • Protection from external forces
  • Implementation of traps and other defensive measures
  • Access to food
  • Access to water
  • Access to manufactured goods
  • Access to exotic goods/trade
  • Access to other dimensions
  • Protection against realistic, but unimplemented effects (e.g. heavy rain/snowfall, flooding)

Ideas

  • Paths of differing quality (occasional coarse dirt for wild trail, wide, paved streets for main streets)
  • Signposting direction of points of interest at crossings
  • Looting and pillaging of local structures
  • Usage of ferries to cross rivers
  • Walled settlement (wooden pikes at first, masonry when most advanced)
  • Moats and embankments
  • Wells where sensible, irrigation systems in arid regions
  • Special nether portal location (fortified against zombie pigmen)
  • Excavated and activated end portal if within build area (/locate to check)
  • Avalanche protection (snowy mountains)

Pathfinding and navigation

Feature branch: None

To create sensible navigational networks pathfinding will be essential.
This might include:

  • (essential) Pathfinding from point-to-point
  • Identifying crossroads
  • Classifying connection traffic volume
  • Taking terrain steepness into account
  • Determining where staircases should be built
  • Determining where bridges or tunnels should be built
  • Determining where piers for waterways should be built
  • Determining where stables for horses should be built
  • Determining where minecart railways should be built
  • Determining where Nether portals should be built

Criterion: Adaption to Environment and Terrain

Feature branch: None

One of the criteria for GDPC 2022 is 'Adaption to Environment and Terrain'
It may include:

  • Sensible choice for settlement location
  • Awareness of potential and hazards of natural features
  • Respects pre-existing topology
  • Usage of local resources
  • Adaption of buildings to climate (see #5)
  • Adaption of environment to overcome problems (see #3)
  • Distinction of housing quality based on land value

Ideas

  • Settlement seed near water on largest region of flat terrain (for easy expansion)
  • Transformation of lava lakes into hot springs (magma blocks under water)
  • Marking waterfalls as points of interest (secret cave behind waterfall?)
  • Marking cliff-faces for mines and quarries, forests for forestry

Cave detection

Feature branch: None

Since caving is an effective, but dangerous, place to find ores, caves might be blocked off or exploited as mines.
To achieve that they must first be detected

To do

  • Detect surface cave entrance
  • Detect cave entrance in mountain faces
  • Explore extent of caves
  • Detect ore veins
  • Detect pre-existing underground structures

Event generation

Feature branch: None

Historic events shape settlements and the people within them and can provide a more detailed story and impose changes on a settlement.

Events

  • Fire: causes burnt wooden houses and modern rebuilding
  • Flood: happens near rivers; causes damaged infrastructure and economy, can lead to famine
  • Famine: happens as a result of other events; causes abandoned structures, can lead to conflict
  • Plague: happens more when dense and unhygienic; causes abandoned structures, mass graves
  • Conflict: causes destroyed / abandoned structures, new defenses, can lead to famine

Structure generation

Feature branch: None

Various individual structures will need to be generated to populate areas: the more adaptive, the better.
Structures are defined as finite objects that may be placed in an environment with little regard to topology.
See #14 for generating continuous objects

Residence

  • Inhabited cave
  • (essential) Tent
  • (essential) Hut
  • House
  • Captain's longhouse

Transport

  • Signpost
  • Street lamp
  • Raft
  • Boat
  • Ship
  • Cart
  • Stable
  • Speed beacons
  • Railway stops
  • Nether gateway

Food, drink and health

  • (essential) Well
  • Cistern
  • Trough / manger
  • Apiary
  • Barn
  • Coop
  • Fishing pier
  • Hunting lodge
  • Snare trap
  • Granary
  • Hunting lodge
  • Communal oven
  • (essential) Campfire
  • Field kitchen
  • Butcher's
  • Brewery
  • Public house / tavern
  • Inn
  • Public bath
  • Infirmary
  • Wisewoman's hut with herbal garden
  • Regeneration beacon (in large temple?)
  • Mortuary

Defence

  • (essential) Village bell
  • Barricade
  • Gatehouse
  • Lookout tower
  • Garrison's barracks
  • Armory
  • Weapon smithy
  • Fletcher
  • Strategy room with cartographer
  • Iron golem cage
  • Target range
  • Practice dummies

Industry

  • Market stall
  • Shop
  • Trading post
  • Warehouse
  • Manual crane
  • Horse mill
  • Tool smithy
  • Ore mill
  • Felled tree
  • (essential) Wood pile
  • Sawmill
  • Dry dock
  • Masonry workshop
  • Tannery
  • Laundry
  • (essential) General workshop

Culture

  • Shrine
  • Temple
  • Stone circle
  • Monument
  • Historian's house with library
  • Stage
  • Wrestling area
  • Gambling den
  • Festive bonfire
  • Burial mound

Decoration

  • Ruins
  • Stone chunks / shards
  • (essential) Log bench

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.