Skip to content

Commit 307b147

Browse files
committed
Merge branch 'api-15' into api-16
# Conflicts: # src/main/java/org/spongepowered/common/entity/player/SpongeUserData.java
2 parents 55478b9 + 252f572 commit 307b147

File tree

10 files changed

+96
-45
lines changed

10 files changed

+96
-45
lines changed

src/main/java/org/spongepowered/common/entity/SpongeEntityArchetype.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public EntitySnapshot toSnapshot(final ServerLocation location) {
174174
final CompoundTag newCompound = this.compound.copy();
175175
final Vector3d pos = location.position();
176176
newCompound.put(Constants.Entity.ENTITY_POSITION, Constants.NBT.newDoubleNBTList(pos.x(), pos.y(), pos.z()));
177-
newCompound.putString(Constants.Sponge.World.WORLD_KEY, location.worldKey().formatted());
177+
newCompound.putString(Constants.Sponge.World.DIMENSION, location.worldKey().formatted());
178178
builder.compound = newCompound;
179179
builder.worldKey = location.world().properties().key();
180180
builder.position = pos;

src/main/java/org/spongepowered/common/entity/player/SpongeUserData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public void readCompound(final CompoundTag compound) {
229229
this.reset();
230230
this.compound = compound;
231231

232-
compound.read(Constants.Sponge.World.WORLD_KEY, ResourceLocation.CODEC)
232+
compound.read(Constants.Sponge.World.DIMENSION, ResourceLocation.CODEC)
233233
.ifPresent(key -> this.worldKey = (ResourceKey) (Object) key);
234234

235235
final var rotation = compound.read(Constants.Entity.ENTITY_ROTATION, Rotations.CODEC).orElse(new Rotations(0, 0, 0));
@@ -248,7 +248,7 @@ public void readCompound(final CompoundTag compound) {
248248
public void writeCompound(final CompoundTag compound) {
249249
final var holder = SpongeCommon.scopedHolder();
250250
final var output = TagValueOutput.createWithContext(ProblemReporter.DISCARDING, holder);
251-
output.putString(Constants.Sponge.World.WORLD_KEY, this.worldKey.formatted());
251+
output.putString(Constants.Sponge.World.DIMENSION, this.worldKey.formatted());
252252

253253
this.loadInventory();
254254
this.loadEnderInventory();

src/main/java/org/spongepowered/common/util/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ public static final class World {
293293
public static final String LEVEL_SPONGE_DAT_NEW = org.spongepowered.common.util.Constants.Sponge.World.LEVEL_SPONGE_DAT + "_new";
294294
public static final String UNIQUE_ID = "UUID";
295295
public static final String DIMENSIONS_DIRECTORY = "dimensions";
296+
public static final String DIMENSION = "Dimension";
296297
public static final String WORLD_KEY = "WorldKey";
297298
}
298299

src/main/java/org/spongepowered/common/world/teleport/SpongeTeleportHelper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ private Stream<Vector3i> getBlockLocations(ServerLocation worldLocation, int hei
8080
int worldBorderMaxX = GenericMath.floor(worldBorder.getCenterX() + radius);
8181
int worldBorderMaxZ = GenericMath.floor(worldBorder.getCenterZ() + radius);
8282

83-
// Get the World and get the maximum Y value.
83+
// Get the World and get the minimum and maximum Y value.
8484
int worldMaxY = worldLocation.world().max().y();
85+
int worldMinY = worldLocation.world().min().y();
8586

8687
Vector3i vectorLocation = worldLocation.blockPosition();
8788

8889
// We use clamp to remain within the world confines, so we don't waste time checking blocks outside of the
8990
// world border and the world height.
90-
int minY = GenericMath.clamp(vectorLocation.y() - height, 0, worldMaxY);
91-
int maxY = GenericMath.clamp(vectorLocation.y() + height, 0, worldMaxY);
91+
int minY = GenericMath.clamp(vectorLocation.y() - height, worldMinY, worldMaxY);
92+
int maxY = GenericMath.clamp(vectorLocation.y() + height, worldMinY, worldMaxY);
9293

9394
int minX = GenericMath.clamp(vectorLocation.x() - width, worldBorderMinX, worldBorderMaxX);
9495
int maxX = GenericMath.clamp(vectorLocation.x() + width, worldBorderMinX, worldBorderMaxX);
@@ -182,7 +183,7 @@ private boolean isFloorSafe(Vector3i currentTarget, World world, Map<Vector3i, B
182183
}
183184

184185
private BlockData getBlockData(Vector3i vector3i, World world, Map<Vector3i, BlockData> cache, Collection<TeleportHelperFilter> filters) {
185-
if (vector3i.y() < 0) {
186+
if (vector3i.y() < world.min().y()) {
186187
// Anything below this isn't safe, no point going further.
187188
return new BlockData();
188189
}

src/main/resources/common.accesswidener

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ accessible class net/minecraft/network/protocol/game/ServerboundInteractPacket$A
1919
accessible class net/minecraft/world/entity/monster/SpellcasterIllager$IllagerSpell
2020
accessible class net/minecraft/world/level/biome/Biome$ClimateSettings
2121
accessible class net/minecraft/core/MappedRegistry$TagSet
22+
accessible class net/minecraft/server/level/ServerChunkCache$MainThreadExecutor

src/mixins/java/org/spongepowered/common/mixin/core/nbt/CompoundTagMixin.java

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package org.spongepowered.common.mixin.core.nbt;
2626

27-
import com.google.common.collect.Maps;
2827
import net.minecraft.nbt.CompoundTag;
2928
import net.minecraft.nbt.Tag;
3029
import org.apache.logging.log4j.Level;
@@ -33,44 +32,32 @@
3332
import org.spongepowered.asm.mixin.Shadow;
3433
import org.spongepowered.asm.mixin.injection.At;
3534
import org.spongepowered.asm.mixin.injection.ModifyArg;
36-
import org.spongepowered.asm.mixin.injection.Redirect;
3735
import org.spongepowered.common.SpongeCommon;
3836
import org.spongepowered.common.util.PrettyPrinter;
3937

4038
import java.util.Map;
4139
import java.util.function.BiConsumer;
4240

43-
/**
44-
* @author Zidane - Minecraft 1.14.4
45-
*
46-
* Normally this shouldn't be necessary, however, due to unforseen consequences
47-
* of creating block snapshots, there are corner cases where mod authors are
48-
* setting nulls into the compound for their tile entities. This overwrite
49-
* prevents an NPE crashing the game. A pretty warning message will be printed
50-
* out for the client to see and report to both Sponge and the mod author.
51-
*/
5241
@Mixin(CompoundTag.class)
5342
public abstract class CompoundTagMixin {
5443

5544
// @formatter:off
5645
@Shadow @Final private Map<String, Tag> tags;
5746
// @formatter:on
5847

59-
@Redirect(method = "copy()Lnet/minecraft/nbt/CompoundTag;",
60-
at = @At(value = "INVOKE",
61-
target ="Ljava/util/Map;forEach(Ljava/util/function/BiConsumer;)V"))
62-
private <K, V> void impl$checkForOverflowOnCopy(Map<K, V> instance, BiConsumer<? super K, ? super V> consumer) {
63-
instance.forEach((k, v) -> {
48+
@ModifyArg(method = "copy()Lnet/minecraft/nbt/CompoundTag;", at = @At(value = "INVOKE", target = "Ljava/util/Map;forEach(Ljava/util/function/BiConsumer;)V"), require = 0)
49+
private BiConsumer<String, Tag> impl$checkForOverflowOnCopy(final BiConsumer<String, Tag> putCopy) {
50+
return (key, tag) -> {
6451
try {
65-
consumer.accept(k, v);
66-
} catch (StackOverflowError e) {
52+
putCopy.accept(key, tag);
53+
} catch (final StackOverflowError e) {
6754
final PrettyPrinter printer = new PrettyPrinter(60)
6855
.add("StackOverflow from trying to copy this compound")
6956
.centre()
7057
.hr();
7158
printer.addWrapped(70, "Sponge caught a stack overflow error, printing out some special"
72-
+ " handling and printouts to assist in finding out where this"
73-
+ " recursion is coming from.");
59+
+ " handling and printouts to assist in finding out where this"
60+
+ " recursion is coming from.");
7461
printer.add();
7562
try {
7663
printer.addWrapped(80, "%s : %s", "This compound", this);
@@ -89,23 +76,8 @@ public abstract class CompoundTagMixin {
8976
}
9077
printer.add();
9178
printer.log(SpongeCommon.logger(), Level.ERROR);
79+
throw e;
9280
}
93-
});
94-
}
95-
96-
@ModifyArg(method = "copy()Lnet/minecraft/nbt/CompoundTag;", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;<init>(Ljava/util/Map;)V"))
97-
private Map<String, Tag> impl$checkForNullNBTValuesDuringCopy(Map<String, Tag> map) {
98-
return Maps.newHashMap(Maps.filterEntries(map, entry -> {
99-
if (entry.getValue() == null) {
100-
final IllegalStateException exception = new IllegalStateException("There is a null NBT component in the compound for key: " + entry.getKey());
101-
SpongeCommon.logger().error("Printing out a stacktrace to catch an exception in performing an NBTTagCompound.copy!\n"
102-
+ "If you are seeing this, then Sponge is preventing an exception from being thrown due to unforseen\n"
103-
+ "possible bugs in any mods present. Please report this to SpongePowered and/or the relative mod\n"
104-
+ "authors for the offending compound data!", exception);
105-
return false;
106-
}
107-
return true;
108-
}));
81+
};
10982
}
110-
11183
}

src/mixins/java/org/spongepowered/common/mixin/core/server/level/ServerChunkCacheMixin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@
3333
import org.spongepowered.asm.mixin.Mixin;
3434
import org.spongepowered.asm.mixin.Shadow;
3535
import org.spongepowered.asm.mixin.injection.At;
36+
import org.spongepowered.asm.mixin.injection.Inject;
3637
import org.spongepowered.asm.mixin.injection.Redirect;
38+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3739
import org.spongepowered.common.accessor.server.level.ChunkMapAccessor;
3840

3941
@Mixin(ServerChunkCache.class)
4042
public abstract class ServerChunkCacheMixin {
4143

4244
// @formatter:off
4345
@Shadow @Final private ServerLevel level;
46+
@Shadow @Final private ServerChunkCache.MainThreadExecutor mainThreadProcessor;
4447
// @formatter:on
4548

4649
@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;saveAllChunks(Z)V"))
@@ -51,4 +54,9 @@ public abstract class ServerChunkCacheMixin {
5154
((ChunkMapAccessor) chunkManager).invoker$saveAllChunks(flush);
5255
}
5356
}
57+
58+
@Inject(method = "close", at = @At("TAIL"))
59+
private void impl$onClose(final CallbackInfo ci) {
60+
this.mainThreadProcessor.close();
61+
}
5462
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* This file is part of Sponge, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.common.mixin.core.server.level;
26+
27+
import net.minecraft.server.level.ServerChunkCache;
28+
import net.minecraft.util.thread.BlockableEventLoop;
29+
import org.spongepowered.asm.mixin.Mixin;
30+
31+
@Mixin(ServerChunkCache.MainThreadExecutor.class)
32+
public abstract class ServerChunkCache_MainThreadExecutorMixin extends BlockableEventLoop<Runnable> {
33+
34+
private volatile boolean impl$closed;
35+
36+
protected ServerChunkCache_MainThreadExecutorMixin(final String $$0) {
37+
super($$0);
38+
}
39+
40+
@Override
41+
public void schedule(final Runnable $$0) {
42+
if (this.impl$closed) {
43+
$$0.run();
44+
return;
45+
}
46+
47+
super.schedule($$0);
48+
49+
if (this.impl$closed) {
50+
this.runAllTasks();
51+
}
52+
}
53+
54+
@Override
55+
public void close() {
56+
super.close();
57+
58+
this.impl$closed = true;
59+
this.runAllTasks();
60+
}
61+
}

src/mixins/java/org/spongepowered/common/mixin/core/server/level/ServerLevelMixin.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerLevel
163163
private Weather impl$prevWeather;
164164
private boolean impl$isManualSave = false;
165165
private long impl$preTickTime = 0L;
166+
private boolean impl$closed = false;
166167

167168
@Inject(method = "<init>", at = @At("TAIL"))
168169
private void impl$onInit(
@@ -216,7 +217,7 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerLevel
216217

217218
@Override
218219
public boolean bridge$isLoaded() {
219-
if (((LevelBridge) this).bridge$isFake()) {
220+
if (((LevelBridge) this).bridge$isFake() || this.impl$closed) {
220221
return false;
221222
}
222223

@@ -581,4 +582,9 @@ public String toString() {
581582
//Weather, game rules and spawns are per world in Sponge.
582583
instance.broadcastAll($$0, this.shadow$dimension());
583584
}
585+
586+
@Inject(method = "close", at = @At("HEAD"))
587+
private void impl$onClose(final CallbackInfo ci) {
588+
this.impl$closed = true;
589+
}
584590
}

src/mixins/resources/mixins.sponge.core.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"server.level.DistanceManagerMixin",
7979
"server.level.GenerationChunkHolderMixin",
8080
"server.level.ServerBossEventMixin",
81+
"server.level.ServerChunkCache_MainThreadExecutorMixin",
8182
"server.level.ServerChunkCacheMixin",
8283
"server.level.ServerEntityMixin",
8384
"server.level.ServerLevelMixin",

0 commit comments

Comments
 (0)