Skip to content

Instantly share code, notes, and snippets.

@fadookie
Created June 11, 2020 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fadookie/e43fb6e874729f70e06ee3d363a57f5e to your computer and use it in GitHub Desktop.
Save fadookie/e43fb6e874729f70e06ee3d363a57f5e to your computer and use it in GitHub Desktop.
MC mixin test
@Mixin(ServerWorld.class)
public class ServerWorldMixin extends World {
// I had to implement this to make the compiler happy but I'm hoping it's not actually going to be called
private ServerWorldMixin() {
super(null, null, null, null, false);
}
// This was working before I tried to access this.dimension
@Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/server/MinecraftServer;Ljava/util/concurrent/Executor;Lnet/minecraft/world/WorldSaveHandler;Lnet/minecraft/world/level/LevelProperties;Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/util/profiler/Profiler;Lnet/minecraft/server/WorldGenerationProgressListener;)V")
private void constructor(MinecraftServer server, Executor workerExecutor, WorldSaveHandler worldSaveHandler, LevelProperties properties, DimensionType dimensionType, Profiler profiler, WorldGenerationProgressListener worldGenerationProgressListener, CallbackInfo info) {
System.out.println("Hello server world ctor! CallBack:" +info + ", properties:" + properties + " levelName:" + properties.getLevelName() + " version:" + properties.getVersion() + " thunderTime:" + properties.getThunderTime() + " dimension:" + dimensionType);
if (dimensionType == DimensionType.OVERWORLD) {
CompoundTag worldData = properties.getWorldData(dimensionType);
System.out.println("In overworld! :D worldData:" + worldData.toString());
}
}
// I never observed this get called
@Inject(at = @At("RETURN"), method = "init(Lnet/minecraft/world/level/LevelInfo;)V")
private void init(LevelInfo levelInfo, CallbackInfo info) {
System.out.println("Hello server world! CallBack:" +info + " level:" + levelInfo);
}
// I just tried to add this and not sure if it works yet
@Inject(at = @At("RETURN"), method = "tick(Ljava/util/function/BooleanSupplier;)V")
private void tick(BooleanSupplier shouldKeepTicking, CallbackInfo info) {
System.out.println("ServerWorldMixin.tick shouldKeepTicking:" +shouldKeepTicking + " dimension:" + this.dimension.getType());
}
// Implement a bunch of methods from world to make compiler happy below
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment