diff --git a/gradle.properties b/gradle.properties index 3b0b3a5..3619d91 100644 --- a/gradle.properties +++ b/gradle.properties @@ -49,7 +49,7 @@ mod_name=Fire! Fire! # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1.0.012124.2105 +mod_version=1.0.012424.1509 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/zontreck/fire/config/server/FireServerConfig.java b/src/main/java/dev/zontreck/fire/config/server/FireServerConfig.java index f36a84b..f5d3b13 100644 --- a/src/main/java/dev/zontreck/fire/config/server/FireServerConfig.java +++ b/src/main/java/dev/zontreck/fire/config/server/FireServerConfig.java @@ -1,5 +1,6 @@ package dev.zontreck.fire.config.server; +import dev.zontreck.fire.FireMod; import dev.zontreck.fire.config.server.sections.RestoreSection; import dev.zontreck.fire.data.FireDatastore; import dev.zontreck.libzontreck.util.SNbtIo; @@ -24,11 +25,19 @@ public class FireServerConfig { restore = RestoreSection.deserialize(tag.getCompound(RestoreSection.TAG_NAME)); } else restore = new RestoreSection(); + + + if(restore.isDirty()) + { + FireMod.LOGGER.info("Migrated restore config section from version " + restore.lastVersion + " to version " + restore.Version); + save(); + } } private static void initialize() { restore = new RestoreSection(); + restore.initialize(); save(); } diff --git a/src/main/java/dev/zontreck/fire/config/server/sections/RestoreSection.java b/src/main/java/dev/zontreck/fire/config/server/sections/RestoreSection.java index 25b5bed..706b025 100644 --- a/src/main/java/dev/zontreck/fire/config/server/sections/RestoreSection.java +++ b/src/main/java/dev/zontreck/fire/config/server/sections/RestoreSection.java @@ -1,30 +1,113 @@ package dev.zontreck.fire.config.server.sections; +import dev.zontreck.ariaslib.util.Lists; +import dev.zontreck.fire.config.server.FireServerConfig; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.Tag; + +import java.util.ArrayList; +import java.util.List; public class RestoreSection { + public static final String TAG_VERSION = "Version"; public static final String TAG_NAME = "restore"; public static final String TAG_CONTAINERS = "containers"; public static final String TAG_DELAY = "delay"; + public static final String TAG_BLACKLISTED_DIMENSIONS = "blacklisted_dimensions"; public boolean restoreContainers = false; public int delayForRestore = 120; + public List blacklistedDimensions = new ArrayList<>(); + public int Version = 0; public static RestoreSection deserialize(CompoundTag tag) { RestoreSection sect = new RestoreSection(); + + if(!tag.contains(TAG_VERSION)) + { + sect.migrate(0, CURRENT_VERSION); + }else { + sect.lastVersion = tag.getInt(TAG_VERSION); + sect.Version = tag.getInt(TAG_VERSION); + sect.migrate(sect.lastVersion, CURRENT_VERSION); + } + sect.restoreContainers = tag.getBoolean(TAG_CONTAINERS); sect.delayForRestore = tag.getInt(TAG_DELAY); + if(tag.contains(TAG_BLACKLISTED_DIMENSIONS)) + { + ListTag lst = tag.getList(TAG_BLACKLISTED_DIMENSIONS, ListTag.TAG_STRING); + + for(Tag str : lst) + { + sect.blacklistedDimensions.add(((StringTag)str).getAsString()); + } + } + + return sect; } + public static final int CURRENT_VERSION = 2; + + public void initialize() + { + migrate(0, CURRENT_VERSION); + } + + private void migrate(int lastVersion, int migrateTo) + { + if(lastVersion == migrateTo)return; + for(int i=lastVersion;i<=migrateTo;i++) + { + if(i == 0) + { + restoreContainers=false; + delayForRestore = 120; + } else if(i == 1) + { + blacklistedDimensions = Lists.of("minecraft:the_nether", "minecraft:the_end", "otemod:threshold", "twilightforest:twilight_forest", "otemod:resource"); + } else if(i == 2) + { + // Nothing changes here except adding the version and migration + } + } + + Version = migrateTo; + markDirty(); + } + + private boolean dirty=false; + public int lastVersion=0; + + private void markDirty() + { + dirty=true; + } + + public boolean isDirty() + { + return dirty; + } + public CompoundTag serialize() { CompoundTag tag = new CompoundTag(); tag.putBoolean(TAG_CONTAINERS, restoreContainers); tag.putInt(TAG_DELAY, delayForRestore); + ListTag lst = new ListTag(); + for(String s : blacklistedDimensions) + { + lst.add(StringTag.valueOf(s)); + } + tag.put(TAG_BLACKLISTED_DIMENSIONS, lst); + + dirty=false; return tag; } diff --git a/src/main/java/dev/zontreck/fire/events/EventHandler.java b/src/main/java/dev/zontreck/fire/events/EventHandler.java index fe95700..4a41bbf 100644 --- a/src/main/java/dev/zontreck/fire/events/EventHandler.java +++ b/src/main/java/dev/zontreck/fire/events/EventHandler.java @@ -4,6 +4,7 @@ import dev.zontreck.fire.FireMod; import dev.zontreck.fire.config.server.FireServerConfig; import dev.zontreck.fire.data.BlockSnapshot; import dev.zontreck.libzontreck.util.ServerUtilities; +import dev.zontreck.libzontreck.vectors.WorldPosition; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -42,6 +43,11 @@ public class EventHandler { } ServerLevel world = (ServerLevel) event.getWorld(); + if(FireServerConfig.restore.blacklistedDimensions.contains(WorldPosition.getDim(world))) + { + //FireMod.LOGGER.info("Blacklisted dimension, ignoring"); + return; // Ignore it. + } BlockPos pos = event.getPos(); BlockState blockState = event.getState(); boolean bBurning=false;