Skip to content

Commit

Permalink
Explicitly do not save temporary worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jun 7, 2023
1 parent c80d1bb commit b9ff71f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 43 deletions.
2 changes: 0 additions & 2 deletions src/main/java/dev/andante/bubble/BubbleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.andante.bubble.mixin.MinecraftServerAccessor;
import dev.andante.bubble.util.DimensionUtil;
import dev.andante.bubble.util.RemovableSimpleRegistry;
import dev.andante.bubble.world.BubbleDimensionOptionsAccess;
import dev.andante.bubble.world.TemporaryWorld;
import dev.andante.bubble.world.VoidChunkGenerator;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
Expand Down Expand Up @@ -122,7 +121,6 @@ private List<TemporaryWorld> collectAll() {
protected TemporaryWorld add(RegistryKey<World> key, ChunkGenerator chunkGenerator) {
// create options
DimensionOptions options = DimensionUtil.createDimensionOptions(this.server, Bubble.DEFAULT_DIMENSION_TYPE, chunkGenerator);
((BubbleDimensionOptionsAccess) (Object) options).setShouldSave(false);

// registry stuff
SimpleRegistry<DimensionOptions> dimensionsRegistry = this.getDimensionsRegistry(this.server);
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/dev/andante/bubble/mixin/DimensionOptionsMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.andante.bubble.mixin;

import dev.andante.bubble.world.TemporaryWorld;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.storage.ChunkDataList;
import net.minecraft.world.storage.EntityChunkDataAccess;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityChunkDataAccess.class)
public class EntityChunkDataAccessMixin {
@Shadow @Final private ServerWorld world;

/**
* Cancels saving of entities for temporary worlds.
*/
@Inject(method = "writeChunkData", at = @At("HEAD"), cancellable = true)
private void onWriteChunkData(ChunkDataList<Entity> dataList, CallbackInfo ci) {
if (this.world instanceof TemporaryWorld) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import java.util.List;
import java.util.Map;

/**
* Adds support for modifying frozen registries.
*/
@Mixin(SimpleRegistry.class)
public abstract class SimpleRegistryMixin<T> implements RemovableSimpleRegistry<T> {
@Shadow @Final private Map<T, RegistryEntry.Reference<T>> valueToEntry;
Expand Down

This file was deleted.

8 changes: 1 addition & 7 deletions src/main/java/dev/andante/bubble/world/TemporaryWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.util.Util;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionOptions;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;

Expand All @@ -18,11 +17,6 @@ public TemporaryWorld(MinecraftServer server, RegistryKey<World> worldRegistryKe
}

@Override
public void save(@Nullable ProgressListener listener, boolean flush, boolean enabled) {
if (flush) {
return;
}

super.save(listener, flush, enabled);
public void save(ProgressListener listener, boolean flush, boolean savingDisabled) {
}
}
2 changes: 1 addition & 1 deletion src/main/resources/bubble.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"package": "dev.andante.bubble.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"DimensionOptionsMixin",
"EntityChunkDataAccessMixin",
"MinecraftServerAccessor",
"SimpleRegistryMixin"
],
Expand Down

0 comments on commit b9ff71f

Please sign in to comment.