new: creativePlayersLoadChunks carpet rule (#1314)

enabled by default: behavior like vanilla
disabled: creative players do not load chunks like spectators with gamerule spectatorsGenerateChunks false
This commit is contained in:
2No2Name authored and GitHub committed 2022-02-05 23:42:50 +01:00
1 parent fa8d2b75d0
commit 5c4e18ead1
3 files changed
+32 -1

No files matched your search

+9
View File
@@ -1092,4 +1092,13 @@ public class CarpetSettings
return "Cannot be negative, can be true, false, or # > 0";
}
}
@Rule(
desc = "Creative players load chunks, or they don't! Just like spectators!",
extra = {"Toggling behaves exactly as if the player is in spectator mode and toggling the gamerule spectatorsGenerateChunks."
},
category = {CREATIVE, FEATURE}
)
public static boolean creativePlayersLoadChunks = true;
}
@@ -0,0 +1,21 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ChunkMap.class)
public class ChunkMap_creativePlayersLoadChunksMixin {
@Inject(method = "skipPlayer(Lnet/minecraft/server/level/ServerPlayer;)Z", at = @At("HEAD"), cancellable = true)
private void startProfilerSection(ServerPlayer serverPlayer, CallbackInfoReturnable<Boolean> cir)
{
if (!CarpetSettings.creativePlayersLoadChunks && serverPlayer.isCreative()) {
cir.setReturnValue(true);
}
}
}