Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit dfc75ff

Browse files
JanrupfRunemoro
authored andcommitted
Fix datapack loading issue, fixes #28
1 parent e5636dd commit dfc75ff

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ build
2727
run
2828
.DS_Store
2929
Thumbs.db
30+
.gradletasknamecache
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
package org.dimdev.rift.mixin.core;
22

3+
import net.minecraft.command.CommandSource;
34
import net.minecraft.server.MinecraftServer;
5+
import net.minecraft.util.math.Vec2f;
6+
import net.minecraft.util.math.Vec3d;
7+
import net.minecraft.util.text.TextComponentString;
8+
import net.minecraft.world.WorldServer;
49
import org.spongepowered.asm.mixin.Mixin;
510
import org.spongepowered.asm.mixin.Overwrite;
11+
import org.spongepowered.asm.mixin.Shadow;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
import org.spongepowered.asm.mixin.injection.Inject;
14+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
615

716
@Mixin(MinecraftServer.class)
817
public class MixinMinecraftServer {
18+
@Shadow
19+
public WorldServer[] worlds;
20+
921
@Overwrite
1022
public String getServerModName() {
1123
return "rift";
1224
}
25+
26+
@Inject(
27+
method = "getCommandSource",
28+
at = @At(value = "NEW"),
29+
cancellable = true
30+
)
31+
private void beforeNew(CallbackInfoReturnable<CommandSource> ci) {
32+
if(worlds == null) { // World has not been loaded yet, this might happen when the datapack is loaded for the first time
33+
ci.setReturnValue(new CommandSource((MinecraftServer) (Object) this, Vec3d.ZERO, Vec2f.ZERO, null, 4, "Server",
34+
new TextComponentString("Server"), (MinecraftServer) (Object) this, null));
35+
ci.cancel();
36+
}
37+
}
1338
}

0 commit comments

Comments
 (0)