Add a dimension blacklist

This commit is contained in:
zontreck 2024-01-24 15:18:18 -07:00
parent ad35b5d07c
commit d28efa2c72
4 changed files with 99 additions and 1 deletions

View file

@ -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. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3 mod_license=GPLv3
# The mod version. See https://semver.org/ # 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. # 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. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -1,5 +1,6 @@
package dev.zontreck.fire.config.server; package dev.zontreck.fire.config.server;
import dev.zontreck.fire.FireMod;
import dev.zontreck.fire.config.server.sections.RestoreSection; import dev.zontreck.fire.config.server.sections.RestoreSection;
import dev.zontreck.fire.data.FireDatastore; import dev.zontreck.fire.data.FireDatastore;
import dev.zontreck.libzontreck.util.SNbtIo; import dev.zontreck.libzontreck.util.SNbtIo;
@ -24,11 +25,19 @@ public class FireServerConfig
{ {
restore = RestoreSection.deserialize(tag.getCompound(RestoreSection.TAG_NAME)); restore = RestoreSection.deserialize(tag.getCompound(RestoreSection.TAG_NAME));
} else restore = new RestoreSection(); } 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() private static void initialize()
{ {
restore = new RestoreSection(); restore = new RestoreSection();
restore.initialize();
save(); save();
} }

View file

@ -1,30 +1,113 @@
package dev.zontreck.fire.config.server.sections; 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.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 class RestoreSection
{ {
public static final String TAG_VERSION = "Version";
public static final String TAG_NAME = "restore"; public static final String TAG_NAME = "restore";
public static final String TAG_CONTAINERS = "containers"; public static final String TAG_CONTAINERS = "containers";
public static final String TAG_DELAY = "delay"; public static final String TAG_DELAY = "delay";
public static final String TAG_BLACKLISTED_DIMENSIONS = "blacklisted_dimensions";
public boolean restoreContainers = false; public boolean restoreContainers = false;
public int delayForRestore = 120; public int delayForRestore = 120;
public List<String> blacklistedDimensions = new ArrayList<>();
public int Version = 0;
public static RestoreSection deserialize(CompoundTag tag) public static RestoreSection deserialize(CompoundTag tag)
{ {
RestoreSection sect = new RestoreSection(); 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.restoreContainers = tag.getBoolean(TAG_CONTAINERS);
sect.delayForRestore = tag.getInt(TAG_DELAY); 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; 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() public CompoundTag serialize()
{ {
CompoundTag tag = new CompoundTag(); CompoundTag tag = new CompoundTag();
tag.putBoolean(TAG_CONTAINERS, restoreContainers); tag.putBoolean(TAG_CONTAINERS, restoreContainers);
tag.putInt(TAG_DELAY, delayForRestore); 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; return tag;
} }

View file

@ -4,6 +4,7 @@ import dev.zontreck.fire.FireMod;
import dev.zontreck.fire.config.server.FireServerConfig; import dev.zontreck.fire.config.server.FireServerConfig;
import dev.zontreck.fire.data.BlockSnapshot; import dev.zontreck.fire.data.BlockSnapshot;
import dev.zontreck.libzontreck.util.ServerUtilities; import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.libzontreck.vectors.WorldPosition;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -42,6 +43,11 @@ public class EventHandler {
} }
ServerLevel world = (ServerLevel) event.getWorld(); 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(); BlockPos pos = event.getPos();
BlockState blockState = event.getState(); BlockState blockState = event.getState();
boolean bBurning=false; boolean bBurning=false;