Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.20.4] Data maps #519

Merged
merged 42 commits into from
Jan 28, 2024
Merged

Conversation

Matyrobbrt
Copy link
Member

@Matyrobbrt Matyrobbrt commented Jan 15, 2024

Adds a data-driven system used to attach arbitrary objects to registry entries. Unlike tags, which are an object->boolean map, this system is an object->? map, that supports lists or maps through the use of mergers and removers.
This system will be used by neo to replace vanilla maps such as the COMPOSTABLES (see bcc540a as an example implementation of that).

Lookups are two IdentityHashMap lookups and should be decently fast.

You can register a data map using a static DataMapType (created through DataMapType#builder), and registered in RegisterDataMapTypesEvent.
A more “advanced” version of simple data map types is provided through AdvancedDataMapType (and its builder). This version has a third generic, and supports merging values from conflicting data packs and selective removals.

Using DataMapType$Builder#synced, a data map can become synced to clients. If mandatory, clients that don't support the data map (and vanilla clients, by extension) will be disconnected and not allowed to connect. The use of non-mandatory synced data map types is mainly for replacement of vanilla features with this data-driven system. To use the compostables example, while compostables are only used on the server, Neo can mark the data map as optionally synced, to allow recipe viewers to display the values.

Example JSON structure:

{
  // Optional list of registry object IDs / tag keys that should have their attached values removed
  // Runs after the values in the JSON file 'in progress' are attached, allowing the use of this feature as a pseudo-holderset
  "remove": [
    "minecraft:birch_log"
  ],
  "values": {
    // Attach a value to all elements in the tag
    "#minecraft:logs": {
      "intValue": 156,
      "stringValue": "some other string"
    },
   // Attach a value to a single object
    "minecraft:carrot": {
      "intValue": 14,
      "stringValue": "some_string"
    }
  }
}

In the case of values that are merged through a merger (available for the AdvancedDataMapType), you can completely override the value as follows:

{
  "values": {
    "minecraft:dandelion": {
      "replace": true, // Replace all previous values, bypassing mergers
      "value": [
        {
          "intValue": 99,
          "stringValue": "override"
        }
      ]
    }
  }
}

A remover may also be provided by AdvancedDataMapTypes. When a remover is provided, the remove list can become a map, mapping a registry object ID / tag key to a remover object, or an object list with key and remover entries.
For example, a remover for a map may accept a list of keys to remove (see the tests class for an example implementation):

{
  "remove": [
    {
      "key": "minecraft:potato",
      // Remove just the map entry with key `value2` from potatoes
      "remover": [
        "value2"
      ]
    },
    {
      // As a remover isn't provided, remove the entire entry attached to shears
      "key": "minecraft:shears"
    }
  ]
}

When not using the object list, but the map variant, you cannot combine removals without a remover and with a remover:

{
  "remove": {
    // Remove the entry with the key `value2` from potatoes
    "minecraft:potato": ["value2"]
  }
}

Supersedes #96.

@Matyrobbrt Matyrobbrt added enhancement New (or improvement to existing) feature or request 1.20 Targeted at Minecraft 1.20 labels Jan 15, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Jan 15, 2024

  • Publish PR to GitHub Packages

Last commit published: 9bbcd096226119b5c67735f130bd4435673ac138.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #519' // https://github.com/neoforged/NeoForge/pull/519
        url 'https://prmaven.neoforged.net/NeoForge/pr519'
        content {
            includeModule('net.neoforged', 'neoforge')
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr519.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr519
cd NeoForge-pr519
curl -L https://prmaven.neoforged.net/NeoForge/pr519/net/neoforged/neoforge/20.4.177-beta-pr-519-204-reg-attachments/mdk-pr519.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip

To test a production environment, you can download the installer from here.

pupnewfster
pupnewfster previously approved these changes Jan 25, 2024
Copy link
Member

@pupnewfster pupnewfster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not done any testing of this PR, but from a code standpoint (and the fact the automated tests pass) it looks good.

Copy link
Member

@XFactHD XFactHD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing further, I found a few issues and also found that a client without this PR (tested with vanilla 1.20.4, NF 20.4.108 and NF 20.4.130) cannot connect to a LAN world or dedicated server with this PR

pupnewfster
pupnewfster previously approved these changes Jan 26, 2024
Copy link
Member

@XFactHD XFactHD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and connections work (or not) as expected with NF clients with the PR, NF clients without the PR and vanilla clients

@Matyrobbrt Matyrobbrt merged commit 5e03a6e into neoforged:1.20.x Jan 28, 2024
4 checks passed
@Matyrobbrt Matyrobbrt deleted the 204-reg-attachments branch January 28, 2024 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.20 Targeted at Minecraft 1.20 enhancement New (or improvement to existing) feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants