This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix datapack loading issue, fixes #28
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ build | |
run | ||
.DS_Store | ||
Thumbs.db | ||
.gradletasknamecache |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/dimdev/rift/mixin/core/MixinMinecraftServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
package org.dimdev.rift.mixin.core; | ||
|
||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.util.math.Vec2f; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.util.text.TextComponentString; | ||
import net.minecraft.world.WorldServer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(MinecraftServer.class) | ||
public class MixinMinecraftServer { | ||
@Shadow | ||
public WorldServer[] worlds; | ||
|
||
@Overwrite | ||
public String getServerModName() { | ||
return "rift"; | ||
} | ||
|
||
@Inject( | ||
method = "getCommandSource", | ||
at = @At(value = "NEW"), | ||
cancellable = true | ||
) | ||
private void beforeNew(CallbackInfoReturnable<CommandSource> ci) { | ||
if(worlds == null) { // World has not been loaded yet, this might happen when the datapack is loaded for the first time | ||
ci.setReturnValue(new CommandSource((MinecraftServer) (Object) this, Vec3d.ZERO, Vec2f.ZERO, null, 4, "Server", | ||
new TextComponentString("Server"), (MinecraftServer) (Object) this, null)); | ||
ci.cancel(); | ||
} | ||
} | ||
} |