band-aid fix for json door rift destinations

This commit is contained in:
CreepyCre 2021-06-14 01:34:32 +02:00
parent e4bd7e00e4
commit 2d8f9f0255
2 changed files with 17 additions and 15 deletions

View file

@ -49,7 +49,7 @@ public class DoorDataReader {
new DoorData.UnbakedBlockSettings( new DoorData.UnbakedBlockSettings(
"minecraft:iron_door", "minecraft:iron_door",
OptionalInt.of(10) OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PublicPocketTarget()), Optional.empty()), AlwaysTrueCondition.INSTANCE))) ), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PublicPocketTarget()), Optional.empty()).toJson(new JsonObject()), AlwaysTrueCondition.INSTANCE)))
)); ));
public static final DoorData DEFAULT_GOLD_DIMENSIONAL_DOOR = new DoorData( public static final DoorData DEFAULT_GOLD_DIMENSIONAL_DOOR = new DoorData(
"dimdoors:gold_dimensional_door", "dimdoors:gold_dimensional_door",
@ -63,7 +63,7 @@ public class DoorDataReader {
new DoorData.UnbakedBlockSettings( new DoorData.UnbakedBlockSettings(
"dimdoors:gold_door", "dimdoors:gold_door",
OptionalInt.of(10) OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(DefaultDungeonDestinations.getDeeperDungeonDestination()), Optional.of(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES)), AlwaysTrueCondition.INSTANCE))) ), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(DefaultDungeonDestinations.getDeeperDungeonDestination()), Optional.of(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES)).toJson(new JsonObject()), AlwaysTrueCondition.INSTANCE)))
)); ));
public static final DoorData DEFAULT_OAK_DIMENSIONAL_DOOR = new DoorData( public static final DoorData DEFAULT_OAK_DIMENSIONAL_DOOR = new DoorData(
"dimdoors:oak_dimensional_door", "dimdoors:oak_dimensional_door",
@ -77,7 +77,7 @@ public class DoorDataReader {
new DoorData.UnbakedBlockSettings( new DoorData.UnbakedBlockSettings(
"minecraft:oak_door", "minecraft:oak_door",
OptionalInt.of(10) OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(DefaultDungeonDestinations.getShallowerDungeonDestination()), Optional.of(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES)), AlwaysTrueCondition.INSTANCE))) ), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(DefaultDungeonDestinations.getShallowerDungeonDestination()), Optional.of(DefaultDungeonDestinations.POCKET_LINK_PROPERTIES)).toJson(new JsonObject()), AlwaysTrueCondition.INSTANCE)))
)); ));
public static final DoorData DEFAULT_QUARTZ_DIMENSIONAL_DOOR = new DoorData( public static final DoorData DEFAULT_QUARTZ_DIMENSIONAL_DOOR = new DoorData(
"dimdoors:quartz_dimensional_door", "dimdoors:quartz_dimensional_door",
@ -93,8 +93,8 @@ public class DoorDataReader {
OptionalInt.of(10) OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> { ), new RiftDataList(Util.make(new LinkedList<>(), list -> {
WorldMatchCondition condition = new WorldMatchCondition(ModDimensions.PERSONAL); WorldMatchCondition condition = new WorldMatchCondition(ModDimensions.PERSONAL);
list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PrivatePocketExitTarget()), Optional.empty()), condition)); list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PrivatePocketExitTarget()), Optional.empty()).toJson(new JsonObject()), condition));
list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PrivatePocketTarget()), Optional.empty()), new InverseCondition(condition))); list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new PrivatePocketTarget()), Optional.empty()).toJson(new JsonObject()), new InverseCondition(condition)));
}) })
)); ));
public static final DoorData DEFAULT_UNSTABLE_DIMENSIONAL_DOOR = new DoorData( public static final DoorData DEFAULT_UNSTABLE_DIMENSIONAL_DOOR = new DoorData(
@ -109,7 +109,7 @@ public class DoorDataReader {
new DoorData.UnbakedBlockSettings( new DoorData.UnbakedBlockSettings(
"minecraft:iron_door", "minecraft:iron_door",
OptionalInt.of(10) OptionalInt.of(10)
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new UnstableTarget()), Optional.of(LinkProperties.builder().linksRemaining(1).groups(IntStream.of(0, 1).boxed().collect(Collectors.toSet())).build())), AlwaysTrueCondition.INSTANCE))) ), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(new UnstableTarget()), Optional.of(LinkProperties.builder().linksRemaining(1).groups(IntStream.of(0, 1).boxed().collect(Collectors.toSet())).build())).toJson(new JsonObject()), AlwaysTrueCondition.INSTANCE)))
)); ));
public static void read() { public static void read() {

View file

@ -18,34 +18,36 @@ import net.minecraft.nbt.NbtOps;
import net.minecraft.util.Pair; import net.minecraft.util.Pair;
public class RiftDataList { public class RiftDataList {
private final LinkedList<Pair<OptRiftData, Condition>> riftDataConditions; private final LinkedList<Pair<JsonObject, Condition>> riftDataConditions;
public static RiftDataList fromJson(JsonArray jsonArray) { public static RiftDataList fromJson(JsonArray jsonArray) {
LinkedList<Pair<OptRiftData, Condition>> riftDataConditions = new LinkedList<>(); LinkedList<Pair<JsonObject, Condition>> riftDataConditions = new LinkedList<>();
for (JsonElement json : jsonArray) { for (JsonElement json : jsonArray) {
JsonObject jsonObject = json.getAsJsonObject(); JsonObject jsonObject = json.getAsJsonObject();
OptRiftData riftData = OptRiftData.fromJson(jsonObject.getAsJsonObject("data")); //OptRiftData riftData = OptRiftData.fromJson(jsonObject.getAsJsonObject("data"));
JsonObject unbakedRiftData = jsonObject.getAsJsonObject("data");
Condition condition = Condition.fromJson(jsonObject.getAsJsonObject("condition")); Condition condition = Condition.fromJson(jsonObject.getAsJsonObject("condition"));
riftDataConditions.add(new Pair<>(riftData, condition)); riftDataConditions.add(new Pair<>(unbakedRiftData, condition));
} }
return new RiftDataList(riftDataConditions); return new RiftDataList(riftDataConditions);
} }
public RiftDataList(LinkedList<Pair<OptRiftData, Condition>> riftDataConditions) { public RiftDataList(LinkedList<Pair<JsonObject, Condition>> riftDataConditions) {
this.riftDataConditions = riftDataConditions; this.riftDataConditions = riftDataConditions;
} }
public OptRiftData getRiftData(EntranceRiftBlockEntity rift) { public OptRiftData getRiftData(EntranceRiftBlockEntity rift) {
return riftDataConditions.stream().filter(pair -> pair.getRight().matches(rift)).findFirst().orElseThrow(() -> new RuntimeException("Could not find any matching rift data")).getLeft(); JsonObject unbakedRiftData = riftDataConditions.stream().filter(pair -> pair.getRight().matches(rift)).findFirst().orElseThrow(() -> new RuntimeException("Could not find any matching rift data")).getLeft();
return OptRiftData.fromJson(unbakedRiftData);
} }
public JsonArray toJson() { public JsonArray toJson() {
JsonArray jsonArray = new JsonArray(); JsonArray jsonArray = new JsonArray();
for (Map.Entry<OptRiftData, Condition> entry : this.riftDataConditions.stream().collect(Collectors.toMap(Pair::getLeft, Pair::getRight)).entrySet()) { for (Map.Entry<JsonObject, Condition> entry : this.riftDataConditions.stream().collect(Collectors.toMap(Pair::getLeft, Pair::getRight)).entrySet()) {
OptRiftData riftData = entry.getKey(); JsonObject unbakedRiftData = entry.getKey();
Condition condition = entry.getValue(); Condition condition = entry.getValue();
JsonObject jsonInner = new JsonObject(); JsonObject jsonInner = new JsonObject();
jsonInner.add("data", riftData.toJson(new JsonObject())); jsonInner.add("data", unbakedRiftData);
jsonInner.add("condition", condition.toJson(new JsonObject())); jsonInner.add("condition", condition.toJson(new JsonObject()));
jsonArray.add(jsonInner); jsonArray.add(jsonInner);
} }