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

Commit

Permalink
Fix datapack loading issue, fixes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
Janrupf authored and Runemoro committed Oct 22, 2018
1 parent e5636dd commit dfc75ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ build
run
.DS_Store
Thumbs.db
.gradletasknamecache
25 changes: 25 additions & 0 deletions src/main/java/org/dimdev/rift/mixin/core/MixinMinecraftServer.java
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();
}
}
}

0 comments on commit dfc75ff

Please sign in to comment.