Skip to content

Commit 7211324

Browse files
committed
Merge branch 'api-12' into api-14
# Conflicts: # src/main/resources/common.accesswidener # src/mixins/java/org/spongepowered/common/mixin/core/nbt/CompoundTagMixin.java
2 parents ef75430 + fe5f294 commit 7211324

File tree

10 files changed

+117
-63
lines changed

10 files changed

+117
-63
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
@@ -173,7 +173,7 @@ public EntitySnapshot toSnapshot(final ServerLocation location) {
173173
final CompoundTag newCompound = this.compound.copy();
174174
final Vector3d pos = location.position();
175175
newCompound.put(Constants.Entity.ENTITY_POSITION, Constants.NBT.newDoubleNBTList(pos.x(), pos.y(), pos.z()));
176-
newCompound.putString(Constants.Sponge.World.WORLD_KEY, location.worldKey().formatted());
176+
newCompound.putString(Constants.Sponge.World.DIMENSION, location.worldKey().formatted());
177177
builder.compound = newCompound;
178178
builder.worldKey = location.world().properties().key();
179179
builder.position = pos;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ public void readCompound(final CompoundTag compound) {
220220
this.reset();
221221
this.compound = compound;
222222

223-
if (!compound.contains(Constants.Sponge.World.WORLD_KEY)) {
224-
this.worldKey = ResourceKey.resolve(compound.getString(Constants.Sponge.World.WORLD_KEY));
223+
if (!compound.contains(Constants.Sponge.World.DIMENSION)) {
224+
this.worldKey = ResourceKey.resolve(compound.getString(Constants.Sponge.World.DIMENSION));
225225
}
226226
final ListTag position = compound.getList(Constants.Entity.ENTITY_POSITION, Constants.NBT.TAG_DOUBLE);
227227
final ListTag rotation = compound.getList(Constants.Entity.ENTITY_ROTATION, Constants.NBT.TAG_FLOAT);
@@ -238,7 +238,7 @@ public void readCompound(final CompoundTag compound) {
238238

239239
public void writeCompound(final CompoundTag compound) {
240240

241-
compound.putString(Constants.Sponge.World.WORLD_KEY, this.worldKey.formatted());
241+
compound.putString(Constants.Sponge.World.DIMENSION, this.worldKey.formatted());
242242

243243
this.loadInventory();
244244
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
@@ -289,6 +289,7 @@ public static final class World {
289289
public static final String LEVEL_SPONGE_DAT_NEW = org.spongepowered.common.util.Constants.Sponge.World.LEVEL_SPONGE_DAT + "_new";
290290
public static final String UNIQUE_ID = "UUID";
291291
public static final String DIMENSIONS_DIRECTORY = "dimensions";
292+
public static final String DIMENSION = "Dimension";
292293
public static final String WORLD_KEY = "WorldKey";
293294
}
294295

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: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package org.spongepowered.common.mixin.core.nbt;
2626

2727
import com.google.common.base.Function;
28-
import com.google.common.collect.Maps;
2928
import net.minecraft.nbt.CompoundTag;
3029
import net.minecraft.nbt.Tag;
3130
import org.apache.logging.log4j.Level;
@@ -34,75 +33,51 @@
3433
import org.spongepowered.asm.mixin.Shadow;
3534
import org.spongepowered.asm.mixin.injection.At;
3635
import org.spongepowered.asm.mixin.injection.ModifyArg;
37-
import org.spongepowered.asm.mixin.injection.Redirect;
3836
import org.spongepowered.common.SpongeCommon;
3937
import org.spongepowered.common.util.PrettyPrinter;
4038

4139
import java.util.Map;
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;", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Maps;transformValues(Ljava/util/Map;Lcom/google/common/base/Function;)Ljava/util/Map;"))
60-
private Map<String, Tag> impl$checkForOverflowOnCopy(Map<String, Tag> fromMap, Function<? super Tag, Tag> function) {
61-
return Maps.transformValues(fromMap, (tag) -> {try {
62-
return tag == null ? null : tag.copy();
63-
} catch (StackOverflowError e) {
64-
final PrettyPrinter printer = new PrettyPrinter(60)
65-
.add("StackOverflow from trying to copy this compound")
66-
.centre()
67-
.hr();
68-
printer.addWrapped(70, "Sponge caught a stack overflow error, printing out some special"
69-
+ " handling and printouts to assist in finding out where this"
70-
+ " recursion is coming from.");
71-
printer.add();
48+
@ModifyArg(method = "copy()Lnet/minecraft/nbt/CompoundTag;", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Maps;transformValues(Ljava/util/Map;Lcom/google/common/base/Function;)Ljava/util/Map;"))
49+
private Function<Tag, Tag> impl$checkForOverflowOnCopy(final Function<Tag, Tag> copy) {
50+
return (tag) -> {
7251
try {
73-
printer.addWrapped(80, "%s : %s", "This compound", this);
74-
} catch (final Throwable error) {
75-
printer.addWrapped(80, "Unable to get the string of this compound. Printing out some of the entries to better assist");
52+
return copy.apply(tag);
53+
} catch (final StackOverflowError e) {
54+
final PrettyPrinter printer = new PrettyPrinter(60)
55+
.add("StackOverflow from trying to copy this compound")
56+
.centre()
57+
.hr();
58+
printer.addWrapped(70, "Sponge caught a stack overflow error, printing out some special"
59+
+ " handling and printouts to assist in finding out where this"
60+
+ " recursion is coming from.");
61+
printer.add();
62+
try {
63+
printer.addWrapped(80, "%s : %s", "This compound", this);
64+
} catch (final Throwable error) {
65+
printer.addWrapped(80, "Unable to get the string of this compound. Printing out some of the entries to better assist");
7666

77-
for (final Map.Entry<String, Tag> entry : this.tags.entrySet()) {
78-
try {
79-
printer.addWrapped(80, "%s : %s", entry.getKey(), entry.getValue());
80-
} catch (final Throwable throwable) {
81-
printer.add();
82-
printer.addWrapped(80, "The offending key entry is belonging to " + entry.getKey());
83-
break;
67+
for (final Map.Entry<String, Tag> entry : this.tags.entrySet()) {
68+
try {
69+
printer.addWrapped(80, "%s : %s", entry.getKey(), entry.getValue());
70+
} catch (final Throwable throwable) {
71+
printer.add();
72+
printer.addWrapped(80, "The offending key entry is belonging to " + entry.getKey());
73+
break;
74+
}
8475
}
8576
}
77+
printer.add();
78+
printer.log(SpongeCommon.logger(), Level.ERROR);
79+
throw e;
8680
}
87-
printer.add();
88-
printer.log(SpongeCommon.logger(), Level.ERROR);
89-
return null;
90-
}});
91-
}
92-
93-
@ModifyArg(method = "copy()Lnet/minecraft/nbt/CompoundTag;", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;<init>(Ljava/util/Map;)V"))
94-
private Map<String, Tag> impl$checkForNullNBTValuesDuringCopy(Map<String, Tag> map) {
95-
return Maps.newHashMap(Maps.filterEntries(map, entry -> {
96-
if (entry.getValue() == null) {
97-
final IllegalStateException exception = new IllegalStateException("There is a null NBT component in the compound for key: " + entry.getKey());
98-
SpongeCommon.logger().error("Printing out a stacktrace to catch an exception in performing an NBTTagCompound.copy!\n"
99-
+ "If you are seeing this, then Sponge is preventing an exception from being thrown due to unforseen\n"
100-
+ "possible bugs in any mods present. Please report this to SpongePowered and/or the relative mod\n"
101-
+ "authors for the offending compound data!", exception);
102-
return false;
103-
}
104-
return true;
105-
}));
81+
};
10682
}
107-
10883
}

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
@@ -165,6 +165,7 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerLevel
165165
private Weather impl$prevWeather;
166166
private boolean impl$isManualSave = false;
167167
private long impl$preTickTime = 0L;
168+
private boolean impl$closed = false;
168169

169170
@Inject(method = "<init>", at = @At("TAIL"))
170171
private void impl$onInit(
@@ -218,7 +219,7 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerLevel
218219

219220
@Override
220221
public boolean bridge$isLoaded() {
221-
if (((LevelBridge) this).bridge$isFake()) {
222+
if (((LevelBridge) this).bridge$isFake() || this.impl$closed) {
222223
return false;
223224
}
224225

@@ -577,4 +578,9 @@ public String toString() {
577578
//Weather, game rules and spawns are per world in Sponge.
578579
instance.broadcastAll($$0, this.shadow$dimension());
579580
}
581+
582+
@Inject(method = "close", at = @At("HEAD"))
583+
private void impl$onClose(final CallbackInfo ci) {
584+
this.impl$closed = true;
585+
}
580586
}

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

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

0 commit comments

Comments
 (0)