Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
logwet committed Jan 16, 2022
1 parent e34f5db commit e6ea75d
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 41 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

[![Build and Release Artifacts](https://github.com/logwet/no-spawnchunks/actions/workflows/build.yml/badge.svg)](https://github.com/logwet/no-spawnchunks/actions/workflows/build.yml)

Mod that prevents the overworld spawn chunks from being and staying loaded.
This means you can pearl hang in the overworld near spawn!
Mod that prevents the overworld spawn chunks from being and staying loaded. This means you can pearl
hang in the overworld near spawn!

## Setup

Put the `jar` file in your mods folder with Fabric Loader installed.
This mod does not require `Fabric API`.
This mod is developed and tested for `1.16.1` but may work in other versions.
Put the `jar` file in your mods folder with Fabric Loader installed. This mod does not
require `Fabric API`. This mod is developed and tested for `1.16.1` but may work in other versions.

## Compatibility

This mod has been tested and is compatible with all of the standard performance mods (lithium, starlight, sodium etc.). It is also compatible with Chunk Mod (illegal) and Noverworld.
This mod has been tested and is compatible with all of the standard performance mods (lithium,
starlight, sodium etc.). It is also compatible with Chunk Mod (illegal) and Noverworld.

## License

This project is available under the `GPL-3.0` license.
Feel free to learn from it and incorporate its components in your own projects, as long as you abide by the terms of the license.
This project is available under the `GPL-3.0` license. Feel free to learn from it and incorporate
its components in your own projects, as long as you abide by the terms of the license.

If you fork the project and distribute your version, please change the name and `modid` to a suitable and distinct alternative to avoid confusion.
If you fork the project and distribute your version, please change the name and `modid` to a
suitable and distinct alternative to avoid confusion.
29 changes: 18 additions & 11 deletions src/main/java/me/logwet/no_spawnchunks/NoSpawnchunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@
import org.apache.logging.log4j.Logger;

public class NoSpawnchunks implements ModInitializer {
public static final String MODID = "no-spawnchunks";
public static final String VERSION = FabricLoader.getInstance().getModContainer(MODID).get().getMetadata().getVersion().getFriendlyString();
public static final boolean IS_CLIENT = FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
public static final Logger LOGGER = LogManager.getLogger(MODID);
public static final String MODID = "no-spawnchunks";
public static final String VERSION =
FabricLoader.getInstance()
.getModContainer(MODID)
.get()
.getMetadata()
.getVersion()
.getFriendlyString();
public static final boolean IS_CLIENT =
FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
public static final Logger LOGGER = LogManager.getLogger(MODID);

public static void log(Level level, String message) {
LOGGER.log(level, "[" + MODID + " v" + VERSION + "] " + message);
}
public static void log(Level level, String message) {
LOGGER.log(level, "[" + MODID + " v" + VERSION + "] " + message);
}

@Override
public void onInitialize() {
log(Level.INFO, "Using "+ MODID + " v" + VERSION);
}
@Override
public void onInitialize() {
log(Level.INFO, "Using " + MODID + " v" + VERSION);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.logwet.no_spawnchunks.mixin.client;

import java.util.List;
import me.logwet.no_spawnchunks.NoSpawnchunks;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -9,19 +10,16 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Environment(EnvType.CLIENT)
@Mixin(DebugHud.class)
public abstract class DebugHudMixin {

/**
* @author DuncanRuns
* @reason Puts mod notice in F3 menu
*/
@Inject(at = @At("RETURN"), method = "getLeftText", cancellable = true)
private void injectGetLeftText(CallbackInfoReturnable<List<String>> info) {
info.getReturnValue().add(NoSpawnchunks.MODID + " mod v" + NoSpawnchunks.VERSION + " by logwet");
info.getReturnValue()
.add(NoSpawnchunks.MODID + " mod v" + NoSpawnchunks.VERSION + " by logwet");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@

@Mixin(MinecraftServer.class)
public class MinecraftServer_RedirectAddStartTicketMixin {

@Redirect(method = "prepareStartRegion", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkManager;addTicket(Lnet/minecraft/server/world/ChunkTicketType;Lnet/minecraft/util/math/ChunkPos;ILjava/lang/Object;)V"))
private void redirectAddTicket(ServerChunkManager serverChunkManager, ChunkTicketType<Unit> ticketType, ChunkPos pos, int radius, Object argument) {
@Redirect(
method = "prepareStartRegion",
at =
@At(
value = "INVOKE",
target =
"Lnet/minecraft/server/world/ServerChunkManager;addTicket(Lnet/minecraft/server/world/ChunkTicketType;Lnet/minecraft/util/math/ChunkPos;ILjava/lang/Object;)V"))
private void redirectAddTicket(
ServerChunkManager serverChunkManager,
ChunkTicketType<Unit> ticketType,
ChunkPos pos,
int radius,
Object argument) {
NoSpawnchunks.log(Level.INFO, "Prevented spawn chunks loading on initial world load.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
import net.minecraft.server.world.ServerChunkManager;
import org.apache.logging.log4j.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = MinecraftServer.class, priority = 1100)
public abstract class MinecraftServer_SkipWaitForChunkGenMixin {

@Redirect(method = "prepareStartRegion", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkManager;getTotalChunksLoadedCount()I"))
@Redirect(
method = "prepareStartRegion",
at =
@At(
value = "INVOKE",
target =
"Lnet/minecraft/server/world/ServerChunkManager;getTotalChunksLoadedCount()I"))
private int redirectGetTotalChunksLoadedCount(ServerChunkManager serverChunkManager) {
NoSpawnchunks.log(Level.INFO, "Redirected chunk count call.");
return 1;
Expand All @@ -29,8 +38,9 @@ private int modifyNumChunksToWaitFor(int value) {
*/
@Inject(method = "prepareStartRegion", at = @At("TAIL"))
private void injectWorldSave(CallbackInfo info) {
NoSpawnchunks.log(Level.INFO, "Forcing world save to ensure advancements and stats files are written.");
((MinecraftServer) (Object) this).save(false,false,false);
NoSpawnchunks.log(
Level.INFO,
"Forcing world save to ensure advancements and stats files are written.");
((MinecraftServer) (Object) this).save(false, false, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,35 @@

@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin {

@Redirect(method = "setSpawnPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkManager;removeTicket(Lnet/minecraft/server/world/ChunkTicketType;Lnet/minecraft/util/math/ChunkPos;ILjava/lang/Object;)V"))
private void redirectRemoveTicket(ServerChunkManager serverChunkManager, ChunkTicketType<Unit> ticketType, ChunkPos pos, int radius, Object argument) {
@Redirect(
method = "setSpawnPos",
at =
@At(
value = "INVOKE",
target =
"Lnet/minecraft/server/world/ServerChunkManager;removeTicket(Lnet/minecraft/server/world/ChunkTicketType;Lnet/minecraft/util/math/ChunkPos;ILjava/lang/Object;)V"))
private void redirectRemoveTicket(
ServerChunkManager serverChunkManager,
ChunkTicketType<Unit> ticketType,
ChunkPos pos,
int radius,
Object argument) {
NoSpawnchunks.log(Level.INFO, "Prevented spawn chunks unloading on spawn point change.");
}

@Redirect(method = "setSpawnPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkManager;addTicket(Lnet/minecraft/server/world/ChunkTicketType;Lnet/minecraft/util/math/ChunkPos;ILjava/lang/Object;)V"))
private void redirectAddTicket(ServerChunkManager serverChunkManager, ChunkTicketType<Unit> ticketType, ChunkPos pos, int radius, Object argument) {
@Redirect(
method = "setSpawnPos",
at =
@At(
value = "INVOKE",
target =
"Lnet/minecraft/server/world/ServerChunkManager;addTicket(Lnet/minecraft/server/world/ChunkTicketType;Lnet/minecraft/util/math/ChunkPos;ILjava/lang/Object;)V"))
private void redirectAddTicket(
ServerChunkManager serverChunkManager,
ChunkTicketType<Unit> ticketType,
ChunkPos pos,
int radius,
Object argument) {
NoSpawnchunks.log(Level.INFO, "Prevented spawn chunks loading on spawn point change.");
}

}

0 comments on commit e6ea75d

Please sign in to comment.