|
1 | 1 | package org.dimdev.rift.mixin.core;
|
2 | 2 |
|
| 3 | +import net.minecraft.command.CommandSource; |
3 | 4 | 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; |
4 | 9 | import org.spongepowered.asm.mixin.Mixin;
|
5 | 10 | 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; |
6 | 15 |
|
7 | 16 | @Mixin(MinecraftServer.class)
|
8 | 17 | public class MixinMinecraftServer {
|
| 18 | + @Shadow |
| 19 | + public WorldServer[] worlds; |
| 20 | + |
9 | 21 | @Overwrite
|
10 | 22 | public String getServerModName() {
|
11 | 23 | return "rift";
|
12 | 24 | }
|
| 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 | + } |
13 | 38 | }
|
0 commit comments