Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
"constructionstick.configuration.AngelFalling.tooltip": "Place blocks below you while falling > 10 blocks with angel upgrade (Can be used to save you from drops/the void)",
"constructionstick.configuration.BEList": "Block Entity List",
"constructionstick.configuration.BEList.tooltip": "White/Blacklist for Block Entities. Allow/Prevent blocks with BEs from being placed by stick. You can either add block ids like minecraft:chest or mod ids like minecraft",
"constructionstick.configuration.BEListExclusions": "Block Entity Exclusion List",
"constructionstick.configuration.BEListExclusions.tooltip": "Exclusion List for Block Entities. Exclude specific entries from the more general White/Blacklist. You can only add block ids like minecraft:chest (excluding a whole mod from itself would be nonsensical).",
"constructionstick.configuration.BEWhitelist": "Block Entity Whitelist",
"constructionstick.configuration.BEWhitelist.tooltip": "If set to TRUE, treat BEList as a whitelist, otherwise blacklist",
"constructionstick.configuration.BEWhitelist.tooltip": "If set to TRUE, treat BEList as a whitelist, otherwise blacklist. Exclusions always work opposite to the main list. Blocks get whitelisted when in blacklist mode and vice versa.",
"constructionstick.configuration.MaxRange": "Max Range",
"constructionstick.configuration.MaxRange.tooltip": "Maximum placement range (0: unlimited). Affects all sticks and is meant for lag prevention, not game balancing.",
"constructionstick.configuration.SimilarBlocks": "Similar Blocks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public ConstructionStick(IEventBus eventBus, ModContainer container, Dist dist)

// Config setup
container.registerConfig(ModConfig.Type.SERVER, ConstructionConfig.SPEC);
eventBus.addListener(ConstructionConfig::registerOnLoading);
eventBus.addListener(ConstructionConfig::registerOnReloading);

if (dist.isClient()) {
container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ public static boolean isTEAllowed(BlockState state) {
String fullId = name.toString();
String modId = name.getNamespace();

boolean inList = ConstructionConfig.BE_LIST.get().contains(fullId) || ConstructionConfig.BE_LIST.get().contains(modId);
boolean inModList = ConstructionConfig.BE_LIST.get().contains(modId);
boolean inBlocksList = ConstructionConfig.BE_LIST.get().contains(fullId);
boolean inExcludeList = ConstructionConfig.BE_LIST_EXCLUSIONS.get().contains(fullId);
boolean inList = !inExcludeList && (inModList || inBlocksList);

boolean isWhitelist = ConstructionConfig.BE_WHITELIST.get();

return isWhitelist == inList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package mrbysco.constructionstick.config;

import mrbysco.constructionstick.ConstructionStick;
import mrbysco.constructionstick.registry.ModItems;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Tiers;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.neoforge.common.ModConfigSpec;
import net.neoforged.neoforge.registries.DeferredHolder;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

public class ConstructionConfig {
Expand All @@ -25,7 +28,9 @@ public class ConstructionConfig {

public static final ModConfigSpec.BooleanValue BE_WHITELIST;
public static final ModConfigSpec.ConfigValue<List<? extends String>> BE_LIST;
public static final ModConfigSpec.ConfigValue<List<? extends String>> BE_LIST_EXCLUSIONS;
private static final String[] BE_LIST_DEFAULT = {"chiselsandbits", "mekanism", "waystones"};
private static final String[] BE_LIST_EXCLUSIONS_DEFAULT = {"mekanism:dynamic_tank", "mekanism:structural_glass"};

private static final HashMap<ResourceLocation, StickProperties> stickProperties = new HashMap<>();

Expand Down Expand Up @@ -112,6 +117,30 @@ public boolean isUpgradeable() {
return upgradeable != null && upgradeable.get();
}
}

public static void registerOnLoading(final ModConfigEvent.Loading configEvent) {
if (configEvent.getConfig().getSpec() == SPEC) {
validateConfig();
}
}

public static void registerOnReloading(final ModConfigEvent.Reloading configEvent) {
if (configEvent.getConfig().getSpec() == SPEC) {
validateConfig();
}
}

private static void validateConfig() {
List<? extends String> blocksList = BE_LIST.get();
List<? extends String> excludeList = BE_LIST_EXCLUSIONS.get();

HashSet<? extends String> blocksSet = new HashSet<>(blocksList);
blocksSet.retainAll(excludeList);
if(!blocksSet.isEmpty()) {
ConstructionStick.LOGGER.warn("ConstructionStick has blocks both in white/blacklist and exclude list, exclude list will have priority. Duplicate entries:");
ConstructionStick.LOGGER.warn(blocksSet.toString());
}
}

static {
final var builder = new ModConfigSpec.Builder();
Expand All @@ -137,7 +166,12 @@ public boolean isUpgradeable() {
builder.comment("White/Blacklist for Block Entities. Allow/Prevent blocks with BEs from being placed by stick.",
"You can either add block ids like minecraft:chest or mod ids like minecraft");
BE_LIST = builder.defineListAllowEmpty("BEList", List.of(BE_LIST_DEFAULT), String::new, o -> (o instanceof String));
builder.comment("If set to TRUE, treat BEList as a whitelist, otherwise blacklist");
builder.comment("Exclusion List for Block Entities. Exclude specific entries from the above White/Blacklist.",
"You can only add block ids like minecraft:chest (excluding a whole mod from itself would be nonsensical).");
BE_LIST_EXCLUSIONS = builder.defineListAllowEmpty("BEListExclusions", List.of(BE_LIST_EXCLUSIONS_DEFAULT), String::new, o -> (o instanceof String));
builder.comment("If set to TRUE, treat BEList as a whitelist, otherwise blacklist.",
"Exclusions always work opposite to the main list. Blocks get whitelisted when in blacklist mode and vice versa.",
"If the block id is in both lists, the exclusion will take priority and a warning is issued in the log.");
BE_WHITELIST = builder.define("BEWhitelist", false);
builder.pop();

Expand Down