-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Replace the rest of config data with its own class
- Loading branch information
Showing
12 changed files
with
243 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/io/github/null2264/cobblegen/data/config/FluidInteractionMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.github.null2264.cobblegen.data.config; | ||
|
||
import blue.endless.jankson.JsonObject; | ||
import blue.endless.jankson.annotation.Deserializer; | ||
import blue.endless.jankson.annotation.Serializer; | ||
import io.github.null2264.cobblegen.data.JanksonSerializable; | ||
|
||
import java.util.HashMap; | ||
|
||
public class FluidInteractionMap extends HashMap<String, HashMap<String, AdvancedGen>> implements JanksonSerializable { | ||
@Override | ||
@Serializer | ||
public JsonObject toJson() { | ||
JsonObject root = new JsonObject(); | ||
this.forEach((fluid1, fluidMap) -> { | ||
JsonObject subroot = new JsonObject(); | ||
fluidMap.forEach((fluid2, advancedGen) -> subroot.put(fluid2, advancedGen.toJson())); | ||
root.put(fluid1, subroot); | ||
}); | ||
return root; | ||
} | ||
|
||
@Deserializer | ||
public static FluidInteractionMap fromJson(JsonObject json) { | ||
if (json == null) return null; | ||
|
||
FluidInteractionMap result = new FluidInteractionMap(); | ||
json.forEach((fluid1, fluidMap) -> { | ||
if (!(fluidMap instanceof JsonObject subroot)) return; | ||
|
||
HashMap<String, AdvancedGen> root = new HashMap<>(); | ||
subroot.forEach((fluid2, jsonElement) -> root.put(fluid2, AdvancedGen.fromJson((JsonObject) jsonElement))); | ||
result.put(fluid1, root); | ||
}); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/io/github/null2264/cobblegen/data/config/ResultList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.github.null2264.cobblegen.data.config; | ||
|
||
import blue.endless.jankson.JsonArray; | ||
import blue.endless.jankson.JsonElement; | ||
import blue.endless.jankson.JsonObject; | ||
import blue.endless.jankson.annotation.Deserializer; | ||
import blue.endless.jankson.annotation.Serializer; | ||
import io.github.null2264.cobblegen.data.JanksonSerializable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class ResultList extends ArrayList<WeightedBlock> implements JanksonSerializable { | ||
public ResultList() {} | ||
|
||
public ResultList(List<WeightedBlock> weightedBlocks) { | ||
this.addAll(weightedBlocks); | ||
} | ||
|
||
public static ResultList of(WeightedBlock... weightedBlocks) { | ||
return new ResultList(Arrays.asList(weightedBlocks)); | ||
} | ||
|
||
@Override | ||
@Serializer | ||
public JsonElement toJson() { | ||
JsonArray array = new JsonArray(); | ||
this.forEach((block) -> array.add(block.toJson())); | ||
return array; | ||
} | ||
|
||
@Deserializer | ||
public static ResultList fromJson(JsonElement json) { | ||
if (json == null) return null; | ||
|
||
ResultList result = new ResultList(); | ||
((JsonArray) json).stream() | ||
.filter((e) -> e instanceof JsonObject) | ||
.forEach((e) -> { | ||
WeightedBlock block = WeightedBlock.fromJson((JsonObject) e); | ||
if (block != null) result.add(block); | ||
}); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.