add world reset

This commit is contained in:
Sen 2025-07-11 12:10:10 +02:00
parent e784b65be7
commit c261317be9
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
4 changed files with 115 additions and 134 deletions

View file

@ -277,5 +277,7 @@ public class CommandEnvironment {
this.registerExecutable(new CommandShowwarp()); this.registerExecutable(new CommandShowwarp());
this.registerExecutable(new CommandTphere()); this.registerExecutable(new CommandTphere());
this.registerExecutable(new CommandEffect()); this.registerExecutable(new CommandEffect());
this.registerExecutable(new CommandExterminatus());
this.registerExecutable(new CommandReset());
} }
} }

View file

@ -0,0 +1,27 @@
package server.command.commands;
import common.color.TextColor;
import common.dimension.Space;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.RunException;
import server.world.WorldServer;
public class CommandExterminatus extends Command {
public CommandExterminatus() {
super("exterminatus");
this.addWorld("dim", true);
}
public void exec(CommandEnvironment env, Executor exec, WorldServer world) {
if(world.dimension == Space.INSTANCE)
throw new RunException("Der Weltraum kann nicht zerstört werden (lol?)");
else if(world.isExterminated())
throw new RunException("Dimension %s ist bereits zerstört", world.dimension.getFormattedName(false));
exec.log(TextColor.YELLOW + "Dimension %s wird zerstört ...", world.dimension.getFormattedName(false));
world.exterminate();
exec.log(TextColor.CRIMSON + "Die Welt %s wurde vernichtet >:)-", world.dimension.getFormattedName(false));
}
}

View file

@ -0,0 +1,20 @@
package server.command.commands;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.world.WorldServer;
public class CommandReset extends Command {
public CommandReset() {
super("reset");
this.addWorld("dim", true);
}
public void exec(CommandEnvironment env, Executor exec, WorldServer world) {
exec.log("Dimension %s wird zurückgesetzt ...", world.dimension.getFormattedName(false));
world.reset();
exec.log("Dimension %s zurückgesetzt", world.dimension.getFormattedName(false));
}
}

View file

@ -353,90 +353,7 @@ public final class WorldServer extends AWorldServer {
if(this.exterminated) if(this.exterminated)
this.weather = Weather.CLEAR; this.weather = Weather.CLEAR;
this.grng = new Random(this.seed); this.grng = new Random(this.seed);
// GeneratorSettings settings = !debug && !this.exterminated ? dim.getSettings() : null; this.initGenerator(this.exterminated);
if(this.exterminated) {
this.setExterminatedGen();
}
// else if(settings != null) {
//// settings = settings == null ? new GeneratorSettings() : settings;
// this.liquid = settings.useLavaSeas ? Blocks.lava.getDefaultState() : Blocks.water.getDefaultState();
// this.biomeGen = new BiomeGenNew(this.seed, settings);
// switch(settings.genMode) {
// case 0:
// this.generator = new GeneratorFlat(settings);
// break;
// case 1:
// default:
// this.generator = new GeneratorNew(this.grng, settings);
// break;
// case 2:
// this.generator = new GeneratorSimple(this.seed, this.grng, settings);
// break;
// }
// switch(settings.replMode) {
// case 0:
// this.replacer = null;
// break;
// case 1:
// default:
// this.replacer = new ReplacerBiome(this.grng);
// break;
// case 2:
// this.replacer = new ReplacerAltBiome(this.grng, settings);
// break;
// }
// this.populator = settings.populate == 0 ? null :
// (settings.populate == 2 ? new PopulatorSimple(this.grng, settings) : new PopulatorNew(this.grng, settings));
// this.caveGen = settings.useCaves ?
// (new MapGenCaves(settings.caveFill == 1 ? Blocks.lava.getDefaultState() :
// (settings.caveFill == 2 ? Blocks.water.getDefaultState() : Blocks.air.getDefaultState()), Blocks.stone,
// Blocks.dirt, Blocks.grass, Blocks.gravel)) : null;
// this.bigCaveGen = null;
// this.ravineGen = settings.useRavines ?
// (new MapGenRavine(settings.ravineFill == 1 ? Blocks.flowing_lava.getDefaultState() : (settings.ravineFill == 2
// ? Blocks.flowing_water.getDefaultState() : Blocks.air.getDefaultState()), Blocks.stone, Blocks.dirt, Blocks.grass)) : null;
// this.base = settings.useBedrock ? Blocks.bedrock.getDefaultState() : null;
// this.ceil = null;
// this.mobs = settings.mobs;
// this.snow = settings.snow;
// this.strongholdGen = settings.useStrongholds ? new MapGenStronghold() : null;
// this.villageGen = settings.useVillages ? new MapGenVillage() : null;
// this.mineshaftGen = settings.useMineShafts ? new MapGenMineshaft() : null;
// this.scatteredGen = settings.useScattered ? new MapGenScatteredFeature() : null;
// this.bridgeGen = null;
// this.seaLevel = settings.genMode == 0 ? this.generator.getMaximumHeight() : settings.seaLevel;
// this.ores = new FeatureOres[settings.oreList.size()];
// for(int z = 0; z < settings.oreList.size(); z++) {
// this.ores[z] = settings.oreList.get(z).createGenerator();
// }
//// PlanetTerra.setOres(settings.oreList);
// }
else {
this.liquid = this.dimension.getLiquid();
this.biomeGen = this.createBiomeGenerator(this.grng);
this.generator = this.createChunkGenerator(this.grng);
this.replacer = this.createBlockReplacer(this.grng);
this.populate = this.dimension.hasPopulator();
this.caveGen = this.createCaveGenerator();
this.bigCaveGen = this.createBigCaveGenerator();
this.ravineGen = this.createRavineGenerator();
this.base = this.dimension.getFiller().getBlock() != Blocks.air && this.dimension.getGeneratorType() != GeneratorType.FLAT;
this.ceil = this.dimension.hasWorldCeiling();
this.mobs = this.dimension.hasMobs();
this.snow = this.dimension.hasSnow();
this.strongholdGen = this.dimension.hasStrongholds() ? new MapGenStronghold() : null;
this.villageGen = this.dimension.hasVillages() ? new MapGenVillage() : null;
this.mineshaftGen = this.dimension.hasMineshafts() ? new MapGenMineshaft() : null;
this.scatteredGen = this.dimension.hasScattered() ? new MapGenScatteredFeature() : null;
this.bridgeGen = this.dimension.hasFortresses() ? new MapGenBridge() : null;
this.seaLevel = this.dimension.getSeaLevel();
this.ores = this.createOres();
this.lakes = this.createLakes();
this.liquids = this.createLiquids();
this.dungeons = this.createDungeonGenerator();
}
this.height = this.generator.getMaximumHeight();
// this.teleporter = new Teleporter(this);
this.calculateInitialSkylight(); this.calculateInitialSkylight();
this.calculateInitialWeather(); this.calculateInitialWeather();
this.updatePhysics(); this.updatePhysics();
@ -457,18 +374,6 @@ public final class WorldServer extends AWorldServer {
} }
this.loadersModified = false; this.loadersModified = false;
} }
if(this.villageGen != null) {
tag = null;
try {
File dat = new File(this.chunkDir, "villages.cdt");
if(dat.exists() && dat.isFile())
tag = TagObject.readGZip(dat);
}
catch(Exception e) {
Log.IO.error(e, "Konnte Dorfliste nicht laden");
}
this.villageStorage = new VillageCollection(tag);
}
} }
public Server getServer() { public Server getServer() {
@ -1620,9 +1525,23 @@ public final class WorldServer extends AWorldServer {
public boolean exterminate() { public boolean exterminate() {
if(this.exterminated) if(this.exterminated)
return false; return false;
this.setWeather(Weather.CLEAR); this.resetData(true);
this.reloadChunks();
for(EntityNPC player : this.players) {
player.attackEntityFrom(DamageSource.causeExterminatusDamage(null), 5000);
Packet packet = new SPacketEffect(1025, new BlockPos(player.posX, (double)this.getSeaLevel() + 4.0, player.posZ), 0);
player.connection.sendPacket(packet);
}
return true;
}
public void reset() {
this.resetData(false);
}
private void resetData(boolean exterminated) {
this.setWeather(exterminated ? Weather.CLEAR : this.dimension.getWeather());
this.resetWeather(); this.resetWeather();
// this.updateWeather();
if(!this.loaderList.isEmpty()) if(!this.loaderList.isEmpty())
this.loadersModified = true; this.loadersModified = true;
for(BlockPos pos : this.loaderList) { for(BlockPos pos : this.loaderList) {
@ -1637,11 +1556,15 @@ public final class WorldServer extends AWorldServer {
Region.finishWrite(); Region.finishWrite();
deleteFiles(this.chunkDir.listFiles(new FileFilter() { deleteFiles(this.chunkDir.listFiles(new FileFilter() {
public boolean accept(File file) { public boolean accept(File file) {
return file.isDirectory(); return file.isDirectory() || !file.getName().equals("data.cdt");
} }
})); }));
this.exterminated = true; this.exterminated = exterminated;
// this.dataModified = true; this.initGenerator(exterminated);
this.reloadChunks();
}
private void reloadChunks() {
for(Long v : this.dropped) { for(Long v : this.dropped) {
ChunkServer chunk = this.chunks.getValueByKey(v.longValue()); ChunkServer chunk = this.chunks.getValueByKey(v.longValue());
if(chunk != null) { if(chunk != null) {
@ -1653,7 +1576,6 @@ public final class WorldServer extends AWorldServer {
this.dropped.clear(); this.dropped.clear();
List<ChunkServer> loaded = Lists.<ChunkServer>newArrayList(this.loaded); List<ChunkServer> loaded = Lists.<ChunkServer>newArrayList(this.loaded);
this.loaded.clear(); this.loaded.clear();
this.setExterminatedGen();
for(ChunkServer chunk : loaded) { for(ChunkServer chunk : loaded) {
long pos = LongHashMap.packInt(chunk.xPos, chunk.zPos); long pos = LongHashMap.packInt(chunk.xPos, chunk.zPos);
chunk.onChunkUnload(); chunk.onChunkUnload();
@ -1662,10 +1584,11 @@ public final class WorldServer extends AWorldServer {
this.chunks.add(pos, chunk); this.chunks.add(pos, chunk);
this.loaded.add(chunk); this.loaded.add(chunk);
chunk.onChunkLoad(); chunk.onChunkLoad();
chunk.checkLight(); // chunk.checkLight();
chunk.setModified(true); // chunk.setModified(true);
} }
for(ChunkServer chunk : this.loaded) { for(ChunkServer chunk : this.loaded) {
this.popChunk(chunk.xPos, chunk.zPos);
chunk.update(false); chunk.update(false);
} }
this.entities.removeAll(this.unloaded); this.entities.removeAll(this.unloaded);
@ -1685,39 +1608,48 @@ public final class WorldServer extends AWorldServer {
for(int z = 0; z < this.instList.size(); ++z) { for(int z = 0; z < this.instList.size(); ++z) {
this.instList.get(z).resend(); this.instList.get(z).resend();
} }
for(EntityNPC player : this.players) {
player.attackEntityFrom(DamageSource.causeExterminatusDamage(null), 5000);
Packet packet = new SPacketEffect(1025, new BlockPos(player.posX, (double)this.getSeaLevel() + 4.0, player.posZ), 0);
player.connection.sendPacket(packet);
}
return true;
} }
private void setExterminatedGen() { private void initGenerator(boolean exterminated) {
this.mobs = false; this.grng.setSeed(this.seed);
this.snow = false; this.liquid = exterminated ? Blocks.air.getState() : this.dimension.getLiquid();
this.caveGen = null; this.biomeGen = exterminated ? new BiomeGenSingle(Biome.EXTERMINATED) : this.createBiomeGenerator(this.grng);
this.bigCaveGen = null; this.generator = exterminated ? new GeneratorDestroyed(this.dimension.getSeaLevel()) : this.createChunkGenerator(this.grng);
this.ravineGen = null; this.replacer = exterminated ? null : this.createBlockReplacer(this.grng);
this.strongholdGen = null; this.populate = !exterminated && this.dimension.hasPopulator();
this.villageGen = null; this.caveGen = exterminated ? null : this.createCaveGenerator();
this.villageStorage = null; this.bigCaveGen = exterminated ? null : this.createBigCaveGenerator();
this.mineshaftGen = null; this.ravineGen = exterminated ? null : this.createRavineGenerator();
this.scatteredGen = null; this.base = !exterminated && this.dimension.getFiller().getBlock() != Blocks.air && this.dimension.getGeneratorType() != GeneratorType.FLAT;
this.bridgeGen = null; this.ceil = !exterminated && this.dimension.hasWorldCeiling();
this.generator = new GeneratorDestroyed(this.dimension.getSeaLevel()); this.mobs = !exterminated && this.dimension.hasMobs();
this.biomeGen = new BiomeGenSingle(Biome.EXTERMINATED); this.snow = !exterminated && this.dimension.hasSnow();
this.replacer = null; this.strongholdGen = !exterminated && this.dimension.hasStrongholds() ? new MapGenStronghold() : null;
this.populate = false; this.villageGen = !exterminated && this.dimension.hasVillages() ? new MapGenVillage() : null;
this.liquid = Blocks.air.getState(); this.mineshaftGen = !exterminated && this.dimension.hasMineshafts() ? new MapGenMineshaft() : null;
this.base = false; this.scatteredGen = !exterminated && this.dimension.hasScattered() ? new MapGenScatteredFeature() : null;
this.ceil = false; this.bridgeGen = !exterminated && this.dimension.hasFortresses() ? new MapGenBridge() : null;
this.height = this.generator.getMaximumHeight();
this.seaLevel = this.dimension.getSeaLevel(); this.seaLevel = this.dimension.getSeaLevel();
this.ores = null; this.ores = exterminated ? null : this.createOres();
this.lakes = null; this.lakes = exterminated ? null : this.createLakes();
this.liquids = null; this.liquids = exterminated ? null : this.createLiquids();
this.dungeons = null; this.dungeons = exterminated ? null : this.createDungeonGenerator();
this.height = this.generator.getMaximumHeight();
if(this.villageGen != null) {
TagObject tag = null;
try {
File dat = new File(this.chunkDir, "villages.cdt");
if(dat.exists() && dat.isFile())
tag = TagObject.readGZip(dat);
}
catch(Exception e) {
Log.IO.error(e, "Konnte Dorfliste nicht laden");
}
this.villageStorage = new VillageCollection(tag);
}
else {
this.villageStorage = null;
}
} }
public static String getLoadedInfo(Server server) { public static String getLoadedInfo(Server server) {