Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit a31cdc9

Browse files
committed
Fix LocalCapture.PRINT that I forgot about.
1 parent 0e1ba4c commit a31cdc9

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Minecraft Forge
3+
* Copyright (c) 2016-2019.
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.minecraftforge.fml.event.server;
21+
22+
import net.minecraft.server.MinecraftServer;
23+
24+
/**
25+
* Called after {@link FMLServerStoppingEvent} when the server has completely shut down.
26+
* Called immediately before shutting down, on the dedicated server, and before returning
27+
* to the main menu on the client.
28+
*
29+
* @author cpw
30+
*/
31+
public class FMLServerStoppedEvent extends ServerLifecycleEvent {
32+
public FMLServerStoppedEvent(MinecraftServer server) {
33+
super(server);
34+
}
35+
}

patchwork-events-lifecycle/src/main/java/net/minecraftforge/fml/server/ServerLifecycleHooks.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121

2222
import net.minecraft.server.MinecraftServer;
2323

24+
import java.util.concurrent.CountDownLatch;
25+
2426
/**
2527
* This is a stub of the ServerLifecycleHooks class in Forge for mods that use getCurrentServer.
2628
*/
2729
public class ServerLifecycleHooks {
2830
public static MinecraftServer currentServer;
31+
public static volatile CountDownLatch exitLatch = null;
2932

3033
public static MinecraftServer getCurrentServer() {
3134
return currentServer;

patchwork-events-lifecycle/src/main/java/net/patchworkmc/impl/event/lifecycle/LifecycleEvents.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package net.patchworkmc.impl.event.lifecycle;
2121

2222
import java.nio.file.Path;
23+
import java.util.concurrent.CountDownLatch;
2324

2425
import net.minecraftforge.common.MinecraftForge;
2526
import net.minecraftforge.event.TickEvent;
@@ -30,6 +31,7 @@
3031
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
3132
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
3233
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
34+
import net.minecraftforge.fml.event.server.FMLServerStoppedEvent;
3335
import net.minecraftforge.fml.loading.FileUtils;
3436
import net.minecraftforge.fml.server.ServerLifecycleHooks;
3537

@@ -93,6 +95,18 @@ public static void handleLoadComplete() {
9395
loadCompleteCallback.run();
9496
}
9597

98+
public static void handleServerStopped(final MinecraftServer server) {
99+
MinecraftForge.EVENT_BUS.post(new FMLServerStoppedEvent(server));
100+
ServerLifecycleHooks.currentServer = null;
101+
LogicalSidedProvider.setServer(null);
102+
CountDownLatch latch = ServerLifecycleHooks.exitLatch;
103+
104+
if (latch != null) {
105+
latch.countDown();
106+
ServerLifecycleHooks.exitLatch = null;
107+
}
108+
}
109+
96110
@Override
97111
public void onInitialize() {
98112
WorldTickCallback.EVENT.register(world -> fireWorldTickEvent(TickEvent.Phase.END, world));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.patchworkmc.mixin.event.lifecycle;
2+
3+
import net.minecraft.server.MinecraftServer;
4+
import net.patchworkmc.impl.event.lifecycle.LifecycleEvents;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
9+
@SuppressWarnings("ConstantConditions")
10+
@Mixin(MinecraftServer.class)
11+
public class MixinMinecraftServer {
12+
@Inject(method = "run", at = @At(value = "INVOKE", target = "net/minecraft/server/MinecraftServer.exit ()V"))
13+
void serverStoppedHook() {
14+
LifecycleEvents.handleServerStopped((MinecraftServer) (Object) this);
15+
}
16+
}

patchwork-loot/src/main/java/net/patchworkmc/mixin/loot/MixinLootPoolSerializer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import java.lang.reflect.Type;
2323

24+
import com.google.gson.JsonDeserializationContext;
25+
import com.google.gson.JsonElement;
2426
import org.spongepowered.asm.mixin.Mixin;
2527
import org.spongepowered.asm.mixin.injection.At;
2628
import org.spongepowered.asm.mixin.injection.Inject;
@@ -38,8 +40,8 @@
3840

3941
@Mixin(LootPool.Serializer.class)
4042
public class MixinLootPoolSerializer {
41-
@Inject(method = "deserialize", at = @At("RETURN"), cancellable = true, locals = LocalCapture.PRINT)
42-
private void addNameToConstructor(CallbackInfoReturnable<LootPool> cir, JsonObject obj) {
43+
@Inject(method = "deserialize", at = @At("RETURN"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
44+
private void addNameToConstructor(JsonElement elem, Type ty, JsonDeserializationContext ctx, CallbackInfoReturnable<LootPool> cir, JsonObject obj) {
4345
LootPool ret = cir.getReturnValue();
4446
((PatchworkLootPool) ret).patchwork$setName(LootHooks.readPoolName(obj));
4547

0 commit comments

Comments
 (0)