commit
This commit is contained in:
parent
dac3a2a60b
commit
9f9813ec8c
8 changed files with 93 additions and 44 deletions
|
@ -1,10 +1,12 @@
|
||||||
package org.dimdev.dimdoors;
|
package org.dimdev.dimdoors;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||||
import me.sargunvohra.mcmods.autoconfig1u.ConfigHolder;
|
import me.sargunvohra.mcmods.autoconfig1u.ConfigHolder;
|
||||||
import org.dimdev.dimdoors.block.ModBlocks;
|
import org.dimdev.dimdoors.block.ModBlocks;
|
||||||
|
import org.dimdev.dimdoors.block.door.DoorDataReader;
|
||||||
import org.dimdev.dimdoors.block.door.condition.Condition;
|
import org.dimdev.dimdoors.block.door.condition.Condition;
|
||||||
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
||||||
import org.dimdev.dimdoors.command.ModCommands;
|
import org.dimdev.dimdoors.command.ModCommands;
|
||||||
|
@ -58,10 +60,10 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
|
|
||||||
public class DimensionalDoorsInitializer implements ModInitializer {
|
public class DimensionalDoorsInitializer implements ModInitializer {
|
||||||
|
private static final Supplier<Path> CONFIG_ROOT = () -> FabricLoader.getInstance().getConfigDir().resolve("dimdoors").toAbsolutePath();
|
||||||
public static final ConfigHolder<ModConfig> CONFIG_MANAGER = AutoConfig.register(ModConfig.class, SubRootJanksonConfigSerializer::new);
|
public static final ConfigHolder<ModConfig> CONFIG_MANAGER = AutoConfig.register(ModConfig.class, SubRootJanksonConfigSerializer::new);
|
||||||
private static MinecraftServer server;
|
private static MinecraftServer server;
|
||||||
private static ModContainer dimDoorsMod;
|
private static ModContainer dimDoorsMod;
|
||||||
private static Path configRoot;
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static MinecraftServer getServer() {
|
public static MinecraftServer getServer() {
|
||||||
|
@ -84,13 +86,12 @@ public class DimensionalDoorsInitializer implements ModInitializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Path getConfigRoot() {
|
public static Path getConfigRoot() {
|
||||||
return configRoot;
|
return CONFIG_ROOT.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
dimDoorsMod = FabricLoader.getInstance().getModContainer("dimdoors").orElseThrow(RuntimeException::new);
|
dimDoorsMod = FabricLoader.getInstance().getModContainer("dimdoors").orElseThrow(RuntimeException::new);
|
||||||
configRoot = FabricLoader.getInstance().getConfigDir().resolve("dimdoors");
|
|
||||||
ServerLifecycleEvents.SERVER_STARTING.register((minecraftServer) -> {
|
ServerLifecycleEvents.SERVER_STARTING.register((minecraftServer) -> {
|
||||||
server = minecraftServer;
|
server = minecraftServer;
|
||||||
});
|
});
|
||||||
|
@ -117,6 +118,8 @@ public class DimensionalDoorsInitializer implements ModInitializer {
|
||||||
PocketAddon.PocketAddonType.register();
|
PocketAddon.PocketAddonType.register();
|
||||||
Condition.ConditionType.register();
|
Condition.ConditionType.register();
|
||||||
|
|
||||||
|
DoorDataReader.read();
|
||||||
|
|
||||||
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(PocketLoader.getInstance());
|
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(PocketLoader.getInstance());
|
||||||
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("dimdoors", "default_pockets"), dimDoorsMod, ResourcePackActivationType.DEFAULT_ENABLED);
|
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("dimdoors", "default_pockets"), dimDoorsMod, ResourcePackActivationType.DEFAULT_ENABLED);
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,10 @@ public final class ModBlocks {
|
||||||
|
|
||||||
public static final Block GOLD_DOOR = register("dimdoors:gold_door", new DoorBlock(FabricBlockSettings.of(Material.METAL, MapColor.GOLD).strength(5.0F).breakByHand(false).breakByTool(FabricToolTags.PICKAXES).nonOpaque()));
|
public static final Block GOLD_DOOR = register("dimdoors:gold_door", new DoorBlock(FabricBlockSettings.of(Material.METAL, MapColor.GOLD).strength(5.0F).breakByHand(false).breakByTool(FabricToolTags.PICKAXES).nonOpaque()));
|
||||||
public static final Block QUARTZ_DOOR = register("dimdoors:quartz_door", new DoorBlock(FabricBlockSettings.of(Material.STONE, MapColor.OFF_WHITE).strength(5.0F).breakByHand(false).breakByTool(FabricToolTags.PICKAXES).nonOpaque()));
|
public static final Block QUARTZ_DOOR = register("dimdoors:quartz_door", new DoorBlock(FabricBlockSettings.of(Material.STONE, MapColor.OFF_WHITE).strength(5.0F).breakByHand(false).breakByTool(FabricToolTags.PICKAXES).nonOpaque()));
|
||||||
public static final Block OAK_DIMENSIONAL_DOOR = register("dimdoors:oak_dimensional_door", new DimensionalDoorBlock(FabricBlockSettings.copyOf(Blocks.OAK_DOOR).luminance(state -> 10)));
|
// public static final Block OAK_DIMENSIONAL_DOOR = register("dimdoors:oak_dimensional_door", new DimensionalDoorBlock(FabricBlockSettings.copyOf(Blocks.OAK_DOOR).luminance(state -> 10)));
|
||||||
public static final Block IRON_DIMENSIONAL_DOOR = register("dimdoors:iron_dimensional_door", new DimensionalDoorBlock(FabricBlockSettings.copyOf(Blocks.IRON_DOOR).luminance(state -> 10)));
|
// public static final Block IRON_DIMENSIONAL_DOOR = register("dimdoors:iron_dimensional_door", new DimensionalDoorBlock(FabricBlockSettings.copyOf(Blocks.IRON_DOOR).luminance(state -> 10)));
|
||||||
public static final Block GOLD_DIMENSIONAL_DOOR = register("dimdoors:gold_dimensional_door", new DimensionalDoorBlock(FabricBlockSettings.copyOf(GOLD_DOOR).luminance(state -> 10)));
|
// public static final Block GOLD_DIMENSIONAL_DOOR = register("dimdoors:gold_dimensional_door", new DimensionalDoorBlock(FabricBlockSettings.copyOf(GOLD_DOOR).luminance(state -> 10)));
|
||||||
public static final Block QUARTZ_DIMENSIONAL_DOOR = register("dimdoors:quartz_dimensional_door", new DimensionalDoorBlock(FabricBlockSettings.copy(QUARTZ_DOOR).luminance(state -> 10)));
|
// public static final Block QUARTZ_DIMENSIONAL_DOOR = register("dimdoors:quartz_dimensional_door", new DimensionalDoorBlock(FabricBlockSettings.copy(QUARTZ_DOOR).luminance(state -> 10)));
|
||||||
public static final Block OAK_DIMENSIONAL_TRAPDOOR = register("dimdoors:wood_dimensional_trapdoor", new DimensionalTrapdoorBlock(FabricBlockSettings.copyOf(Blocks.OAK_TRAPDOOR).luminance(state -> 10)));
|
public static final Block OAK_DIMENSIONAL_TRAPDOOR = register("dimdoors:wood_dimensional_trapdoor", new DimensionalTrapdoorBlock(FabricBlockSettings.copyOf(Blocks.OAK_TRAPDOOR).luminance(state -> 10)));
|
||||||
|
|
||||||
public static final Block DIMENSIONAL_PORTAL = register("dimdoors:dimensional_portal", new DimensionalPortalBlock(FabricBlockSettings.of(Material.AIR).collidable(false).strength(-1.0F, 3600000.0F).nonOpaque().dropsNothing().luminance(10)));
|
public static final Block DIMENSIONAL_PORTAL = register("dimdoors:dimensional_portal", new DimensionalPortalBlock(FabricBlockSettings.of(Material.AIR).collidable(false).strength(-1.0F, 3600000.0F).nonOpaque().dropsNothing().luminance(10)));
|
||||||
|
@ -99,7 +99,6 @@ public final class ModBlocks {
|
||||||
BLOCKS.forEach((str, block) -> {
|
BLOCKS.forEach((str, block) -> {
|
||||||
Registry.register(Registry.BLOCK, str, block);
|
Registry.register(Registry.BLOCK, str, block);
|
||||||
});
|
});
|
||||||
DoorDataReader.read();
|
|
||||||
BLOCKS.clear();
|
BLOCKS.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,10 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
|
||||||
public final class DoorData implements AutoCloseable {
|
public final class DoorData implements AutoCloseable {
|
||||||
public static final List<Block> DOORS = new ArrayList<>();
|
public static final List<Block> DOORS = new ArrayList<>();
|
||||||
private String id;
|
private final String id;
|
||||||
private UnbakedItemSettings itemSettings;
|
private final UnbakedItemSettings itemSettings;
|
||||||
private UnbakedBlockSettings blockSettings;
|
private final UnbakedBlockSettings blockSettings;
|
||||||
private RiftDataList riftDataList;
|
private final RiftDataList riftDataList;
|
||||||
private boolean closed = false;
|
private boolean closed = false;
|
||||||
|
|
||||||
public static DoorData fromJson(JsonObject json) {
|
public static DoorData fromJson(JsonObject json) {
|
||||||
|
@ -51,17 +51,38 @@ public final class DoorData implements AutoCloseable {
|
||||||
|
|
||||||
public JsonObject toJson(JsonObject json) {
|
public JsonObject toJson(JsonObject json) {
|
||||||
json.addProperty("id", this.id);
|
json.addProperty("id", this.id);
|
||||||
|
json.add("itemSettings", this.itemSettings.toJson(new JsonObject()));
|
||||||
|
json.add("blockSettings", this.blockSettings.toJson(new JsonObject()));
|
||||||
|
json.add("riftData", this.riftDataList.toJson());
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Consumer<? super EntranceRiftBlockEntity> createSetupFunction() {
|
private Consumer<? super EntranceRiftBlockEntity> createSetupFunction() {
|
||||||
|
RiftDataList riftDataList = this.riftDataList;
|
||||||
|
|
||||||
return rift -> {
|
return rift -> {
|
||||||
RiftDataList.OptRiftData riftData = this.riftDataList.getRiftData(rift);
|
RiftDataList.OptRiftData riftData = riftDataList.getRiftData(rift);
|
||||||
riftData.getDestination().ifPresent(rift::setDestination);
|
riftData.getDestination().ifPresent(rift::setDestination);
|
||||||
riftData.getProperties().ifPresent(rift::setProperties);
|
riftData.getProperties().ifPresent(rift::setProperties);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnbakedItemSettings getItemSettings() {
|
||||||
|
return itemSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnbakedBlockSettings getBlockSettings() {
|
||||||
|
return blockSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RiftDataList getRiftDataList() {
|
||||||
|
return riftDataList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (closed) {
|
if (closed) {
|
||||||
|
@ -87,11 +108,6 @@ public final class DoorData implements AutoCloseable {
|
||||||
Registry.register(Registry.BLOCK, id, doorBlock);
|
Registry.register(Registry.BLOCK, id, doorBlock);
|
||||||
Registry.register(Registry.ITEM, id, doorItem);
|
Registry.register(Registry.ITEM, id, doorItem);
|
||||||
DOORS.add(doorBlock);
|
DOORS.add(doorBlock);
|
||||||
|
|
||||||
this.id = null;
|
|
||||||
this.blockSettings = null;
|
|
||||||
this.itemSettings = null;
|
|
||||||
this.riftDataList = null;
|
|
||||||
this.closed = true;
|
this.closed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,11 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
@ -79,7 +81,7 @@ public class DoorDataReader {
|
||||||
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(RandomTarget.builder().acceptedGroups(Collections.singleton(0)).coordFactor(1).negativeDepthFactor(80).positiveDepthFactor(Double.MAX_VALUE).weightMaximum(100).noLink(false).newRiftWeight(0).build()), Optional.empty()), AlwaysTrueCondition.INSTANCE)))
|
), new RiftDataList(Util.make(new LinkedList<>(), list -> list.add(new Pair<>(new RiftDataList.OptRiftData(Optional.of(RandomTarget.builder().acceptedGroups(Collections.singleton(0)).coordFactor(1).negativeDepthFactor(80).positiveDepthFactor(Double.MAX_VALUE).weightMaximum(100).noLink(false).newRiftWeight(0).build()), Optional.empty()), AlwaysTrueCondition.INSTANCE)))
|
||||||
));
|
));
|
||||||
private static final DoorData DEFAULT_QUARTZ_DIMENSIONAL_DOOR = new DoorData(
|
private static final DoorData DEFAULT_QUARTZ_DIMENSIONAL_DOOR = new DoorData(
|
||||||
"dimdoors:gold_dimensional_door",
|
"dimdoors:quartz_dimensional_door",
|
||||||
new DoorData.UnbakedItemSettings(
|
new DoorData.UnbakedItemSettings(
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
OptionalInt.of(1),
|
OptionalInt.of(1),
|
||||||
|
@ -98,31 +100,50 @@ public class DoorDataReader {
|
||||||
));
|
));
|
||||||
|
|
||||||
public static void read() {
|
public static void read() {
|
||||||
try {
|
Path doorDir = DimensionalDoorsInitializer.getConfigRoot().resolve("doors");
|
||||||
Path doorDir = DimensionalDoorsInitializer.getConfigRoot().resolve("doors");
|
|
||||||
|
|
||||||
if (Files.notExists(doorDir)) {
|
if (Files.exists(doorDir) && !Files.isDirectory(doorDir)) {
|
||||||
writeDefault(doorDir);
|
try {
|
||||||
|
Files.delete(doorDir);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Error deleting " + doorDir, e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Files.isDirectory(doorDir)) {
|
if (Files.notExists(doorDir)) {
|
||||||
for (Path p : Files.list(doorDir).collect(Collectors.toList())) {
|
try {
|
||||||
if (!Files.isDirectory(p) && Files.isRegularFile(p)) {
|
Files.createDirectory(doorDir);
|
||||||
String jsonStr = new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
|
writeDefault(doorDir);
|
||||||
JsonObject json = GSON.fromJson(jsonStr, JsonObject.class);
|
} catch (IOException e) {
|
||||||
try (DoorData ignored = DoorData.fromJson(json)) {
|
LOGGER.error("Error creating directory " + doorDir, e);
|
||||||
LOGGER.info("Loading door json from {}", p.toAbsolutePath().toString());
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Files.isDirectory(doorDir)) {
|
||||||
|
List<Path> paths;
|
||||||
|
try {
|
||||||
|
paths = Files.list(doorDir).collect(Collectors.toList());
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Error retrieving paths in directory " + doorDir, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Path p : paths) {
|
||||||
|
if (!Files.isDirectory(p) && Files.isRegularFile(p)) {
|
||||||
|
String jsonStr;
|
||||||
|
try {
|
||||||
|
jsonStr = new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Error reading " + p, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JsonObject json = GSON.fromJson(jsonStr, JsonObject.class);
|
||||||
|
try (DoorData ignored = DoorData.fromJson(json)) {
|
||||||
|
LOGGER.info("Loaded door json from {} with id {}", p.toAbsolutePath().toString(), ignored.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Files.delete(doorDir);
|
|
||||||
writeDefault(doorDir);
|
|
||||||
}
|
}
|
||||||
} catch (IOException | RuntimeException e) {
|
|
||||||
LOGGER.error("Error leading door json", e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,9 +154,18 @@ public class DoorDataReader {
|
||||||
writeDefault(root.resolve("quartz_dimensional_door.json"), DEFAULT_QUARTZ_DIMENSIONAL_DOOR);
|
writeDefault(root.resolve("quartz_dimensional_door.json"), DEFAULT_QUARTZ_DIMENSIONAL_DOOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeDefault(Path path, DoorData doorData) throws IOException {
|
private static void writeDefault(Path path, DoorData doorData) {
|
||||||
Files.createFile(path);
|
try {
|
||||||
|
Files.createFile(path);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Error creating " + path, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
String json = GSON.toJson(doorData.toJson(new JsonObject()));
|
String json = GSON.toJson(doorData.toJson(new JsonObject()));
|
||||||
Files.write(path, json.getBytes(StandardCharsets.UTF_8));
|
try {
|
||||||
|
Files.write(path, json.getBytes(StandardCharsets.UTF_8));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Error writing to " + path, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,6 @@ public enum AlwaysTrueCondition implements Condition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition.ConditionType<?> getType() {
|
public Condition.ConditionType<?> getType() {
|
||||||
return null;
|
return ConditionType.ALWAYS_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public interface Condition {
|
||||||
boolean matches(EntranceRiftBlockEntity rift);
|
boolean matches(EntranceRiftBlockEntity rift);
|
||||||
|
|
||||||
default JsonObject toJson(JsonObject json) {
|
default JsonObject toJson(JsonObject json) {
|
||||||
json.addProperty("type", "dimdoors:" + getType().getId());
|
json.addProperty("type", getType().getId());
|
||||||
this.toJsonInner(json);
|
this.toJsonInner(json);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@ public abstract class VirtualTarget implements Target {
|
||||||
protected Location location;
|
protected Location location;
|
||||||
|
|
||||||
public static VirtualTarget fromTag(CompoundTag nbt) {
|
public static VirtualTarget fromTag(CompoundTag nbt) {
|
||||||
return Objects.requireNonNull(REGISTRY.get(new Identifier(nbt.getString("type")))).fromTag(nbt);
|
Identifier id = new Identifier(nbt.getString("type"));
|
||||||
|
return Objects.requireNonNull(REGISTRY.get(id), "Unknown virtual target type " + id.toString()).fromTag(nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompoundTag toTag(VirtualTarget virtualTarget) {
|
public static CompoundTag toTag(VirtualTarget virtualTarget) {
|
||||||
|
@ -126,6 +127,7 @@ public abstract class VirtualTarget implements Target {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||||
public static class NoneTarget extends VirtualTarget {
|
public static class NoneTarget extends VirtualTarget {
|
||||||
public static final NoneTarget INSTANCE = new NoneTarget();
|
public static final NoneTarget INSTANCE = new NoneTarget();
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
"ServerPlayerInteractionManagerMixin",
|
"ServerPlayerInteractionManagerMixin",
|
||||||
"accessor.BuiltinBiomesAccessor",
|
"accessor.BuiltinBiomesAccessor",
|
||||||
"accessor.ChunkGeneratorAccessor",
|
"accessor.ChunkGeneratorAccessor",
|
||||||
"accessor.ChunkGeneratorSettingsAccessor",
|
|
||||||
"accessor.DefaultParticleTypeAccessor",
|
"accessor.DefaultParticleTypeAccessor",
|
||||||
"accessor.DirectionAccessor",
|
"accessor.DirectionAccessor",
|
||||||
"accessor.EntityAccessor",
|
"accessor.EntityAccessor",
|
||||||
|
|
Loading…
Reference in a new issue