Skip to content

Commit

Permalink
Proper config and player roles compat
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Nov 5, 2024
1 parent 17a40a1 commit f19cfb3
Show file tree
Hide file tree
Showing 25 changed files with 435 additions and 135 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ archivesBaseName = project.slug
repositories {
maven { url "https://api.modrinth.com/maven" }
maven { url "https://maven.enginehub.org/repo/" }
maven { url "https://maven.gegy.dev/releases/" }
mavenCentral()
}

Expand All @@ -33,6 +34,8 @@ dependencies {
modImplementation libs.worldeditCore
modImplementation libs.worldeditFabric

modImplementation "dev.gegy:player-roles-api:1.6.11"

shade(libs.nettyIoUringClasses) { transitive = false }
shade(variantOf(libs.nettyIoUringNative) { classifier "linux-x86_64" }) { transitive = false }
shade(libs.zstd) { transitive = false }
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ authors=jaskarth, unascribed
contributors=Patbox, IThundxr
license=AGPL-3.0-or-later
# Mod Version
baseVersion=0.5.5
baseVersion=0.6.0
# Branch Metadata
branch=1.21
tagBranch=1.21
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/net/modfest/fireblanket/Fireblanket.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,24 @@
import net.modfest.fireblanket.command.DumpCommand;
import net.modfest.fireblanket.command.RegionCommand;
import net.modfest.fireblanket.compat.PolyMcCompat;
import net.modfest.fireblanket.compat.roles.PlayerRolesCompat;
import net.modfest.fireblanket.config.ConfigSpecs;
import net.modfest.fireblanket.config.FireblanketConfig;
import net.modfest.fireblanket.mixin.accessor.ClientConnectionAccessor;
import net.modfest.fireblanket.mixin.accessor.ServerChunkManagerAccessor;
import net.modfest.fireblanket.mixin.accessor.ServerLoginNetworkHandlerAccessor;
import net.modfest.fireblanket.mixinsupport.FSCConnection;
import net.modfest.fireblanket.net.BatchedBEUpdatePayload;
import net.modfest.fireblanket.net.CommandBlockPacket;
import net.modfest.fireblanket.world.blocks.UpdateSignBlockEntityTypes;
import net.modfest.fireblanket.world.entity.EntityFilters;
import net.modfest.fireblanket.world.render_regions.RegionSyncRequest;
import net.modfest.fireblanket.world.render_regions.RenderRegions;
import net.modfest.fireblanket.world.render_regions.RenderRegionsState;
import net.modfest.fireblanket.config.EntityFilters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -90,14 +94,9 @@ public void onInitialize() {
UpdateSignBlockEntityTypes.apply(block);
});

Path configs = FabricLoader.getInstance().getConfigDir().resolve("fireblanket");
if (Files.exists(configs)) {
Path types = configs.resolve("entityfilters.txt");

if (Files.exists(types)) {
EntityFilters.parse(types);
}
}

EntityFilters.init();

for (int i = 0; i < PACKET_QUEUES.length; i++) {
LinkedBlockingQueue<QueuedPacket> q = new LinkedBlockingQueue<>();
Expand Down Expand Up @@ -150,10 +149,12 @@ public void onInitialize() {
PolyMcCompat.init();
}

PlayerRolesCompat.init();

ServerWorldEvents.LOAD.register((server, world) -> {
if (System.getProperty("fireblanket.loadRadius") != null) {
if (FireblanketConfig.get(ConfigSpecs.FORCED_LOAD_RADIUS) > 0) {
if (!world.getRegistryKey().getValue().toString().equals("minecraft:overworld")) return;
int radius = Integer.getInteger("fireblanket.loadRadius");
int radius = FireblanketConfig.get(ConfigSpecs.FORCED_LOAD_RADIUS);
int min = (int) Math.floor(-radius / 16);
int max = (int) Math.ceil(radius / 16);
int count = (max - min) * (max - min);
Expand Down
97 changes: 22 additions & 75 deletions src/main/java/net/modfest/fireblanket/FireblanketMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,38 @@

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.Bootstrap;
import net.modfest.fireblanket.config.ConfigSpecs;
import net.modfest.fireblanket.config.FireblanketConfig;
import org.objectweb.asm.tree.ClassNode;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;

public class FireblanketMixin implements IMixinConfigPlugin {
public static final boolean GAMEPLAY_CHANGES = Boolean.getBoolean("fireblanket.gameplayChanges");
public static final boolean DO_MASKING = Boolean.getBoolean("fireblanket.masking");
private static final boolean DO_CHUNK_CACHE = System.getProperty("fireblanket.loadRadius") != null;
public static final boolean ALLOW_LAMBDAMAP_SAVING = Boolean.getBoolean("fireblanket.allowLambdaMapSaving");
private static final boolean DO_CHUNKSECTION_OPTO = Boolean.getBoolean("fireblanket.flattenChunkPalettes");
public static final boolean ALLOW_FOOTGUNS = Boolean.getBoolean("fireblanket.allowFootguns");
public static final boolean AVOID_ZTSD = Boolean.getBoolean("fireblanket.saveAsDat");

@Override
public void onLoad(String mixinPackage) {
// aaaaagh
boolean ignoreRenderingMods = Boolean.getBoolean("fireblanket.iSolemnlySwearIWillNotReportRenderingCrashesAndAcceptResponsibilityForBreakage");
if (ignoreRenderingMods) {
if (FabricLoader.getInstance().isModLoaded("nvidium")) {
LoggerFactory.getLogger("Fireblanket").error("===================================================");
LoggerFactory.getLogger("Fireblanket").error(" IGNORING THE PRESENCE OF NVIDIUM. ");
LoggerFactory.getLogger("Fireblanket").error("YOU ACCEPT EVERYTHING THAT WILL HAPPEN FROM NOW ON.");
LoggerFactory.getLogger("Fireblanket").error("===================================================");
}
if (FabricLoader.getInstance().isModLoaded("bobby")) {
LoggerFactory.getLogger("Fireblanket").error("Ignoring the presence of Bobby. Be ready for missing chunks.");
Path configs = FabricLoader.getInstance().getConfigDir().resolve("fireblanket");
if (!Files.exists(configs)) {
try {
Files.createDirectory(configs);
} catch (IOException e) {
Fireblanket.LOGGER.error("Exception creating fireblanket directory!", e);
}
}
if (!ignoreRenderingMods && FabricLoader.getInstance().isModLoaded("nvidium")) {
Bootstrap.SYSOUT.println("""
----------------------------------------------------------------------------------------
###### Fireblanket is cowardly refusing to launch the game with Nvidium installed ######
----------------------------------------------------------------------------------------
Due to the amount of mods that change how rendering works, Nvidium can experience
random crashes and other hard to debug issues. From testing in the build server, Nvidium
doesn't have a lot of impact on the types of fps lag that the pack causes. As such,
it is not recommended to use Nvidium with Blanketcon for stability reasons.
========================================================================================
If you would like to ignore these warnings and launch anyway, you must add the following
to your JVM arguments:
-Dfireblanket.iSolemnlySwearIWillNotReportRenderingCrashesAndAcceptResponsibilityForBreakage=true
The JVM will now exit.
""");
System.exit(0xDEAD);
}
if (FabricLoader.getInstance().isModLoaded("entityculling")) {
Bootstrap.SYSOUT.println("""
----------------------------------------------------------------------------------------
### Fireblanket is cowardly refusing to launch the game with EntityCulling installed ###
----------------------------------------------------------------------------------------
EntityCulling causes performance issues and hard-to-debug crashes due to poor use of
threading. Sodium's entity culling is already enabled to optimize this behavior, and
Fireblanket contains additional fixes and optimizations for entities that are tuned
specifically for Blanketcon.
========================================================================================
You may not override this. The JVM will now exit.
""");
System.exit(0xDEAD);
}
if (!ignoreRenderingMods && FabricLoader.getInstance().isModLoaded("bobby")) {
Bootstrap.SYSOUT.println("""
----------------------------------------------------------------------------------------
####### Fireblanket is cowardly refusing to launch the game with Bobby installed #######
----------------------------------------------------------------------------------------
While Bobby can make navigating the map easier, it is causing difficult to debug
issues with chunk culling that keep resulting in false issue reports. We do not ship it
with the pack for a reason — we have had so many other issues to chase and fix that we
simply do not have time to field the Bobby issues. It additionally can cause crashes if
its option to keep block entities in fake chunks is not enabled, so it is not
recommended for use due to stability reasons.
========================================================================================
If you would like to ignore these warnings and launch anyway, you must add the following
to your JVM arguments:
-Dfireblanket.iSolemnlySwearIWillNotReportRenderingCrashesAndAcceptResponsibilityForBreakage=true
The JVM will now exit.
""");
System.exit(0xDEAD);

FireblanketConfig.init();

boolean ignoreRenderingMods = Boolean.getBoolean("fireblanket.iSolemnlySwearIWillNotReportRenderingCrashesAndAcceptResponsibilityForBreakage");
if (ignoreRenderingMods) {
LoggerFactory.getLogger("Fireblanket").error("Ignoring the presence of rendering mods. You are proceeding at your own mortal peril.");
}
}

Expand All @@ -98,27 +49,23 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
}

if (mixinClassName.contains("region_chunk_cache")) {
return DO_CHUNK_CACHE;
}

if (mixinClassName.contains("lambdamap")) {
return !ALLOW_LAMBDAMAP_SAVING;
return FireblanketConfig.get(ConfigSpecs.FORCED_LOAD_RADIUS) > 0;
}

if (mixinClassName.contains("block_format")) {
return DO_CHUNKSECTION_OPTO;
return FireblanketConfig.get(ConfigSpecs.FLATTEN_CHUNK_PALETTES);
}

if (mixinClassName.contains("ai") || mixinClassName.contains("sounds")) {
return GAMEPLAY_CHANGES;
return FireblanketConfig.get(ConfigSpecs.GAMEPLAY_CHANGES);
}

if (mixinClassName.contains("footgun")) {
return !ALLOW_FOOTGUNS;
return !FireblanketConfig.get(ConfigSpecs.ALLOW_FOOTGUNS);
}

if (mixinClassName.contains("MixinRegionFile") || mixinClassName.contains("MixinPersistentState")) {
return !AVOID_ZTSD;
return !FireblanketConfig.get(ConfigSpecs.AVOID_ZSTD);
}

// Conflicts with Krypton, which also lifts the limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.modfest.fireblanket.compat.roles.Roles;

public class CmdFindReplaceCommand {
public static void init(LiteralArgumentBuilder<ServerCommandSource> base, CommandRegistryAccess access) {
base.then(literal("cmd-find-replace")
.requires(source -> source.hasPermissionLevel(4))
.requires(source -> source.hasPermissionLevel(4) && Roles.isNetadmin(source.getPlayer()))
.then(argument("regex", StringArgumentType.string())
.then(argument("replacement", StringArgumentType.string())
.executes(ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import java.util.Map;

import static net.minecraft.server.command.CommandManager.literal;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.modfest.fireblanket.compat.roles.Roles;

public class DumpCommand {
public static void init(LiteralArgumentBuilder<ServerCommandSource> base, CommandRegistryAccess access) {
base.then(literal("dump")
.requires(source -> source.hasPermissionLevel(4))
.requires(source -> source.hasPermissionLevel(4) || Roles.isOrganizer(source.getPlayer()))
.then(literal("command-blocks")
.executes(server -> {
server.getSource().getServer().submit(() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.modfest.fireblanket.compat.roles;

import dev.gegy.roles.api.PlayerRolesApi;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;

public class PlayerRolesCompat {
public static boolean isLoaded = false;

public static void init() {
if (FabricLoader.getInstance().isModLoaded("player_roles")) {
isLoaded = true;
}
}

public static boolean isNetadmin(PlayerEntity player) {
return is(player, "netadmin");
}

public static boolean isOrganizer(PlayerEntity player) {
return is(player, "organizer");
}

public static boolean isBuilder(PlayerEntity player) {
return is(player, "builder") || is(player, "fixer");
}

private static boolean is(PlayerEntity player, String id) {
return PlayerRolesApi.lookup().byPlayer(player).stream().anyMatch(r -> r.getId().equals(id));
}
}
75 changes: 75 additions & 0 deletions src/main/java/net/modfest/fireblanket/compat/roles/Roles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.modfest.fireblanket.compat.roles;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.integrated.IntegratedServer;

public class Roles {
private static boolean isSingleplayer(PlayerEntity player) {
return player.getEntityWorld().getServer() instanceof IntegratedServer;
}

public static boolean isNetadmin(PlayerEntity player) {
if (player == null) {
return false;
}

if (PlayerRolesCompat.isLoaded) {
if (PlayerRolesCompat.isNetadmin(player)) {
return true;
}
}

if (isSingleplayer(player)) {
return true;
}

// check fb config as well
return false;
}

public static boolean isOrganizer(PlayerEntity player) {
if (player == null) {
return false;
}

if (isNetadmin(player)) {
return true;
}

if (PlayerRolesCompat.isLoaded) {
if (PlayerRolesCompat.isOrganizer(player)) {
return true;
}
}

if (isSingleplayer(player)) {
return true;
}

// check fb config as well
return false;
}

public static boolean isBuilder(PlayerEntity player) {
if (player == null) {
return false;
}

if (isOrganizer(player)) {
return true;
}

if (PlayerRolesCompat.isLoaded) {
if (PlayerRolesCompat.isBuilder(player)) {
return true;
}
}

if (isSingleplayer(player)) {
return true;
}

// check fb config as well
return false;
}
}
33 changes: 33 additions & 0 deletions src/main/java/net/modfest/fireblanket/config/ConfigParsers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.modfest.fireblanket.config;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ConfigParsers {
public static final ParseFunc<List<String>> STRING_LIST = in -> {
return Arrays.asList(in.split(","));
};

public static final ParseFunc<String> STRING = in -> in;

public static final ParseFunc<Integer> INTEGER = in -> {
try {
return Integer.parseInt(in);
} catch (Exception e) {
throw new ParseException("Unknown integer value: " + in);
}
};

public static final ParseFunc<Boolean> BOOLEAN = in -> {
if ("yes".equals(in) || "true".equals(in)) {
return true;
}

if ("no".equals(in) || "false".equals(in)) {
return false;
}

throw new ParseException("Unknown boolean value: " + in);
};
}
4 changes: 4 additions & 0 deletions src/main/java/net/modfest/fireblanket/config/ConfigSpec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.modfest.fireblanket.config;

public record ConfigSpec<T>(String name, String prettyName, String description, String defaultValue, ParseFunc<T> parser) {
}
Loading

0 comments on commit f19cfb3

Please sign in to comment.