diff --git a/SpongeAPI b/SpongeAPI index 299f484b680..9effc1e7e5c 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 299f484b680631d30da76543c1eb0318d859eb87 +Subproject commit 9effc1e7e5cd7a671c6bb1534446a4669d24b460 diff --git a/src/main/java/org/spongepowered/common/mixin/core/world/chunk/storage/AnvilChunkLoaderMixin.java b/src/main/java/org/spongepowered/common/mixin/core/world/chunk/storage/AnvilChunkLoaderMixin.java index 718adf8955e..9a1b90cb289 100644 --- a/src/main/java/org/spongepowered/common/mixin/core/world/chunk/storage/AnvilChunkLoaderMixin.java +++ b/src/main/java/org/spongepowered/common/mixin/core/world/chunk/storage/AnvilChunkLoaderMixin.java @@ -33,6 +33,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.AnvilChunkLoader; import net.minecraft.world.chunk.storage.RegionFileCache; import net.minecraft.world.storage.ThreadedFileIOBase; @@ -59,6 +60,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.common.SpongeImpl; import org.spongepowered.common.SpongeImplHooks; +import org.spongepowered.common.bridge.world.WorldBridge; import org.spongepowered.common.bridge.world.chunk.ChunkBridge; import org.spongepowered.common.bridge.world.chunk.storage.AnvilChunkLoaderBridge; import org.spongepowered.common.entity.PlayerTracker; @@ -67,12 +69,15 @@ import org.spongepowered.common.util.Constants; import org.spongepowered.common.util.QueuedChunk; import org.spongepowered.common.util.VecHelper; +import org.spongepowered.common.util.WorldChunkPos; import java.io.File; import java.nio.file.Path; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; @Mixin(AnvilChunkLoader.class) @@ -268,14 +273,14 @@ public boolean writeNextIO() { this.writeChunkData(chunkpos, nbttagcompound); laste = null; break; - } catch (Exception exception) { + } catch (final Exception exception) { // LOGGER.error((String)"Failed to save chunk", // (Throwable)exception); laste = exception; } try { Thread.sleep(10); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); } } @@ -305,11 +310,24 @@ public boolean writeNextIO() { return this.chunkSaveLocation.toPath(); } + @Redirect(method = "saveChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/storage/AnvilChunkLoader.addChunkToPending" + + "(Lnet/minecraft/util/math/ChunkPos;Lnet/minecraft/nbt/NBTTagCompound;)V")) + private void impl$useWorldChunkPosWhenQueuing(final AnvilChunkLoader anvilChunkLoader, final ChunkPos pos, final NBTTagCompound compound, + final World worldIn, final Chunk chunkIn) { + this.addChunkToPending(new WorldChunkPos(((org.spongepowered.api.world.World) worldIn).getUniqueId(), pos.x, pos.z), compound); + } + @Inject(method = "writeChunkData", at = @At("RETURN")) - private void impl$callSaveChunkEventPost(ChunkPos pos, NBTTagCompound compound, CallbackInfo ci) { + private void impl$callSaveChunkEventPost(final ChunkPos pos, final NBTTagCompound compound, final CallbackInfo ci) { if (ShouldFire.SAVE_CHUNK_EVENT_POST) { final Cause cause = Cause.of(EventContext.empty(), Collections.singleton(SpongeImpl.getServer())); - SpongeImpl.postEvent(SpongeEventFactory.createSaveChunkEventPost(cause, VecHelper.toVec3i(pos))); + final Optional worldUUID; + if (pos instanceof WorldChunkPos) { + worldUUID = Optional.of(((WorldChunkPos) pos).getWorldUUID()); + } else { + worldUUID = Optional.empty(); + } + SpongeImpl.postEvent(SpongeEventFactory.createSaveChunkEventPost(cause, VecHelper.toVec3i(pos), worldUUID)); } } } diff --git a/src/main/java/org/spongepowered/common/mixin/core/world/gen/ChunkProviderServerMixin.java b/src/main/java/org/spongepowered/common/mixin/core/world/gen/ChunkProviderServerMixin.java index 61f179115b7..97e1ee23906 100644 --- a/src/main/java/org/spongepowered/common/mixin/core/world/gen/ChunkProviderServerMixin.java +++ b/src/main/java/org/spongepowered/common/mixin/core/world/gen/ChunkProviderServerMixin.java @@ -71,6 +71,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Iterator; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import javax.annotation.Nullable; @@ -358,7 +359,7 @@ public boolean tick() if (ShouldFire.SAVE_CHUNK_EVENT_PRE) { final org.spongepowered.api.world.Chunk apiChunk = (org.spongepowered.api.world.Chunk) chunkIn; if (SpongeImpl.postEvent(SpongeEventFactory.createSaveChunkEventPre(SpongeImpl.getCauseStackManager().getCurrentCause(), - apiChunk.getPosition(), apiChunk))) { + apiChunk.getPosition(), Optional.of(apiChunk.getWorld().getUniqueId()), apiChunk))) { ci.cancel(); } } diff --git a/src/main/java/org/spongepowered/common/util/WorldChunkPos.java b/src/main/java/org/spongepowered/common/util/WorldChunkPos.java new file mode 100644 index 00000000000..895a6ac87c2 --- /dev/null +++ b/src/main/java/org/spongepowered/common/util/WorldChunkPos.java @@ -0,0 +1,45 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.util; + +import net.minecraft.util.math.ChunkPos; + +import java.util.UUID; + +// Used in AnvilChunkLoaderMixin +public final class WorldChunkPos extends ChunkPos { + + private final UUID uuid; + + public WorldChunkPos(final UUID uuid, final int x, final int z) { + super(x, z); + this.uuid = uuid; + } + + public UUID getWorldUUID() { + return this.uuid; + } + +}