-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
persistence: Ensure that CompoundSavedData always saves to file
- Loading branch information
Showing
6 changed files
with
58 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
silk-persistence/src/main/java/net/silkmc/silk/persistence/mixin/other/MixinSavedData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.silkmc.silk.persistence.mixin.other; | ||
|
||
import net.minecraft.core.HolderLookup; | ||
import net.minecraft.world.level.saveddata.SavedData; | ||
import net.silkmc.silk.persistence.internal.CompoundSavedData; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.io.File; | ||
|
||
@Mixin(SavedData.class) | ||
public class MixinSavedData { | ||
|
||
@SuppressWarnings("UnreachableCode") | ||
@Inject( | ||
method = "save(Ljava/io/File;Lnet/minecraft/core/HolderLookup$Provider;)V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/nbt/NbtUtils;addCurrentDataVersion(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/nbt/CompoundTag;", | ||
shift = At.Shift.BEFORE | ||
), | ||
cancellable = true | ||
) | ||
private void onSave(File file, HolderLookup.Provider provider, | ||
CallbackInfo ci) { | ||
if (((SavedData) (Object) this) instanceof CompoundSavedData compoundSavedData) { | ||
if (compoundSavedData.getCompound().isEmpty() && !file.exists()) { | ||
ci.cancel(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters