Skip to content

Commit

Permalink
Add README.md
Browse files Browse the repository at this point in the history
Some Fixes
  • Loading branch information
FirstMegaGame4 committed Dec 29, 2023
1 parent 96e0794 commit 589fef8
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 25 deletions.
129 changes: 129 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# env.json

## Supports

[<img src="https://github.com/JR1811/Boatism/blob/5bdbea79b11428101353c4a67ccd4b3821200a76/extrernal/promo/badges/supported_on_fabric_loader.png?raw=true" width="256" alt="ModFest 1.20">](https://fabricmc.net)
[<img src="https://github.com/JR1811/Boatism/blob/5bdbea79b11428101353c4a67ccd4b3821200a76/extrernal/promo/badges/supported_on_quilt_loader.png?raw=true" width="256" alt="ModFest 1.20">](https://quiltmc.org)

## Requirements

[<img src="https://github.com/JR1811/Boatism/blob/5bdbea79b11428101353c4a67ccd4b3821200a76/extrernal/promo/badges/requires_fabric_api.png?raw=true" width="256" alt="ModFest 1.20">](https://modrinth.com/mod/fabric-api)

## Concept

env.json is a Minecraft Library introducing a new sub json file extension format, with the goal of
redirecting minecraft resources to other ones based on the environment context.

## Implementations

env.json doesn't provide these redirections directly, but only the operations around env.json files
and their resource reload management.

There is currently two official implementations of env.json:

- Environment Driven Assets (EDA)

Mod Identifier: env-driven-assets.

Environments: Client

Applies env.json operations to Minecraft Vanilla asset types.

- Environment Driven Data (EDD)

Mod Identifier: env-driven-data.

Environments: Common & Server

Applies env.json operations to Minecraft Vanilla data types.

## The env.json Format

```json
[
{
"rules": [ // the primary set of rules, is an "any" type
{
"type": "sequence", // all rules in the sequence must pass
"rule": [] // the rules
},
{
"type": "any", // passes if at least one rule passes
"rule": [] // the rules
},
{
"type": "dimension", // passes if the current dimension matches this one
"rule": "minecraft:overworld" // the dimension, can also be a tag
},
{
"type": "biome", // passes if the current biome matches this one
"rule": "minecraft:plains" // the biome, can also be a tag
},
{
"type": "x_coord", // passes if the following operations on the x-axis are valid
"rule": {
"comparator": "==", // must be <, >, ==, <=, >=, =< or =>
"value": "100" // must be an integer
}
},
{
"type": "y_coord", // passes if the following operations on the y-axis are valid
"rule": {
"comparator": "==", // must be <, >, ==, <=, >=, =< or =>
"value": "100" // must be an integer
}
},
{
"type": "z_coord", // passes if the following operations on the z-axis are valid
"rule": {
"comparator": "==", // must be <, >, ==, <=, >=, =< or =>
"value": "100" // must be an integer
}
},
{
"type": "submerged", // passes if the current context is surrounded by water or not
"rule": true // true for "if it is submerged" and false for "if it is not submerged"
},
{
"type": "sky", // passes if the context is above the sky limit or below
"rule": "above" // must be "above" or "below"
},
{
"type": "water", // passes if the context is above the water level or below
"rule": "above" // must be "above" or "below"
},
{
"type": "void", // passes if the context is above the void limit or below
"rule": "above" // must be "above" or "below"
}
],
"result": "minecraft:block/stone" // the redirected resource
}
]
```

The file must be registered under this format: `redirected_resource_name-redirected_resource_extension.env.json`.

## Usage For Developers

In your `build.gradle`
```groovy
repositories {
// ...
maven { url 'https://jitpack.io' }
}
// ...
dependencies {
// ...
modImplementation "com.github.FirstMegaGame4:env.json:${theMostBeautifulVersionYouCanFind}"
}
```

You can now get your `EnvJson` object from a `Resource` object thanks to `ExtendedResource#of(Resource)#getEnvJson`
or parse it with `EnvJson#parse(Path)` or `EnvJson#parse(InputStream)`.

## Promotion

[<img src="https://raw.githubusercontent.com/ModFest/art/3bf66556e674d670e30f647d6a48c4e1798c21d4/badge/128h/ModFest%201.20%20Badge%20Cozy.png" alt="ModFest 1.20">](https://modfest.net/1.20)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.4+build.3
loader_version=0.15.2

# Mod Properties
mod_version=1.0.0
mod_version=0.1.0
maven_group=fr.firstmegagame4.env.json
archives_base_name=env_json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class EnvJsonInitializer implements ModInitializer {

@Override
public void onInitialize() {
LOGGER.info("EnvJson Library Loaded");
LOGGER.info("hello-world.env.json");
}
}
44 changes: 23 additions & 21 deletions src/main/java/fr/firstmegagame4/env/json/impl/EnvJsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

@ApiStatus.Internal
public class EnvJsonParser {
Expand All @@ -43,12 +43,12 @@ public EnvJsonParser(InputStream stream) {
this.content = JsonHelper.deserializeArray(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)));
}

private static SequenceEnvJsonRule parseSequenceRule(JsonObject json) {
return new SequenceEnvJsonRuleImpl(EnvJsonParser.parseRules(json.getAsJsonObject()));
private static SequenceEnvJsonRule parseSequenceRule(JsonArray list) {
return new SequenceEnvJsonRuleImpl(EnvJsonParser.parseRules(list));
}

private static AnyEnvJsonRule parseAnyRule(JsonObject json) {
return new AnyEnvJsonRuleImpl(EnvJsonParser.parseRules(json.getAsJsonObject()));
private static AnyEnvJsonRule parseAnyRule(JsonArray list) {
return new AnyEnvJsonRuleImpl(EnvJsonParser.parseRules(list));
}

private static DimensionEnvJsonRule parseDimensionRule(String string) {
Expand All @@ -70,7 +70,7 @@ private static BiomeEnvJsonRule parseBiomeRule(String string) {
}

private static CoordEnvJsonRule parseCoordRule(CoordEnvJsonRule.Coord coord, JsonObject json) {
CoordEnvJsonRule.Comparator comparator = CoordEnvJsonRule.Comparator.fromString(json.get("operator").getAsString());
CoordEnvJsonRule.Comparator comparator = CoordEnvJsonRule.Comparator.fromString(json.get("comparator").getAsString());
int value = json.get("value").getAsInt();
return new CoordEnvJsonRuleImpl(coord, comparator, value);
}
Expand All @@ -91,23 +91,25 @@ private static VoidEnvJsonRule parseVoidRule(String string) {
return new VoidEnvJsonRuleImpl(VoidEnvJsonRule.Localization.valueOf(string.toUpperCase()));
}

private static List<EnvJsonRule> parseRules(JsonObject json) {
private static List<EnvJsonRule> parseRules(JsonArray array) {
List<EnvJsonRule> rules = new ArrayList<>();
for (Map.Entry<String, JsonElement> entry : json.entrySet()) {
EnvJsonRule.Type type = EnvJsonRule.Type.valueOf(entry.getKey().toUpperCase());
for (JsonElement element : array) {
JsonObject rule = element.getAsJsonObject();
EnvJsonRule.Type type = EnvJsonRule.Type.valueOf(rule.get("type").getAsString().toUpperCase());
Supplier<JsonElement> supplier = () -> rule.get("rule");
rules.add(
switch (type) {
case SEQUENCE -> EnvJsonParser.parseSequenceRule(entry.getValue().getAsJsonObject());
case ANY -> EnvJsonParser.parseAnyRule(entry.getValue().getAsJsonObject());
case DIMENSION -> EnvJsonParser.parseDimensionRule(entry.getValue().getAsString());
case BIOME -> EnvJsonParser.parseBiomeRule(entry.getValue().getAsString());
case X_COORD -> EnvJsonParser.parseCoordRule(CoordEnvJsonRule.Coord.X, entry.getValue().getAsJsonObject());
case Y_COORD -> EnvJsonParser.parseCoordRule(CoordEnvJsonRule.Coord.Y, entry.getValue().getAsJsonObject());
case Z_COORD -> EnvJsonParser.parseCoordRule(CoordEnvJsonRule.Coord.Z, entry.getValue().getAsJsonObject());
case SUBMERGED -> EnvJsonParser.parseSubmergedRule(entry.getValue().getAsBoolean());
case SKY -> EnvJsonParser.parseSkyRule(entry.getValue().getAsString());
case WATER -> EnvJsonParser.parseWaterRule(entry.getValue().getAsString());
case VOID -> EnvJsonParser.parseVoidRule(entry.getValue().getAsString());
case SEQUENCE -> EnvJsonParser.parseSequenceRule(supplier.get().getAsJsonArray());
case ANY -> EnvJsonParser.parseAnyRule(supplier.get().getAsJsonArray());
case DIMENSION -> EnvJsonParser.parseDimensionRule(supplier.get().getAsString());
case BIOME -> EnvJsonParser.parseBiomeRule(supplier.get().getAsString());
case X_COORD -> EnvJsonParser.parseCoordRule(CoordEnvJsonRule.Coord.X, supplier.get().getAsJsonObject());
case Y_COORD -> EnvJsonParser.parseCoordRule(CoordEnvJsonRule.Coord.Y, supplier.get().getAsJsonObject());
case Z_COORD -> EnvJsonParser.parseCoordRule(CoordEnvJsonRule.Coord.Z, supplier.get().getAsJsonObject());
case SUBMERGED -> EnvJsonParser.parseSubmergedRule(supplier.get().getAsBoolean());
case SKY -> EnvJsonParser.parseSkyRule(supplier.get().getAsString());
case WATER -> EnvJsonParser.parseWaterRule(supplier.get().getAsString());
case VOID -> EnvJsonParser.parseVoidRule(supplier.get().getAsString());
}
);
}
Expand All @@ -116,7 +118,7 @@ private static List<EnvJsonRule> parseRules(JsonObject json) {

private static EnvJsonMember parseMember(JsonObject json) {
return new EnvJsonMemberImpl(
EnvJsonParser.parseRules(json.getAsJsonObject("rule")),
EnvJsonParser.parseRules(json.getAsJsonArray("rules")),
Identifier.tryParse(json.get("result").getAsString())
);
}
Expand Down
Binary file modified src/main/resources/assets/env_json/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "env_json",
"version": "${version}",
"name": "env.json",
"description": "This is an example description! Tell everyone what your mod is about!",
"description": "env.json is a Minecraft Library introducing a new sub json file extension format, with the goal of redirecting minecraft resources to other ones based on the environment context.",
"authors": [
"FirstMegaGame4"
],
Expand All @@ -30,6 +30,7 @@
"fabric-api": "*"
},
"suggests": {
"another-mod": "*"
"env_driven_assets": "*",
"env_driven_data": "*"
}
}

0 comments on commit 589fef8

Please sign in to comment.