From 4c8621d16f8a6904f967cc3abfc4fe0db6dbe5b6 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Fri, 20 Oct 2023 19:22:36 +0100 Subject: [PATCH] Better suffix config and saner defaults --- ...kSuffixConfig.java => VariantsConfig.java} | 40 +++++++++++-------- .../module/VariantSelectorModule.java | 8 +--- 2 files changed, 26 insertions(+), 22 deletions(-) rename src/main/java/vazkii/quark/content/experimental/config/{BlockSuffixConfig.java => VariantsConfig.java} (84%) diff --git a/src/main/java/vazkii/quark/content/experimental/config/BlockSuffixConfig.java b/src/main/java/vazkii/quark/content/experimental/config/VariantsConfig.java similarity index 84% rename from src/main/java/vazkii/quark/content/experimental/config/BlockSuffixConfig.java rename to src/main/java/vazkii/quark/content/experimental/config/VariantsConfig.java index 6a6ee08fcd..79e2a26ae1 100644 --- a/src/main/java/vazkii/quark/content/experimental/config/BlockSuffixConfig.java +++ b/src/main/java/vazkii/quark/content/experimental/config/VariantsConfig.java @@ -15,32 +15,35 @@ import java.util.*; import java.util.Map.Entry; -public class BlockSuffixConfig extends AbstractConfigType { +public class VariantsConfig extends AbstractConfigType { private static final VariantMap EMPTY_VARIANT_MAP = new VariantMap(new HashMap<>()); @Config(description = "The list of all variant types available for players to use. Values are treated as suffixes to block IDs for scanning.\n" + "Prefix any variant type with ! to make it show up for Manual Variants but not be automatically scanned for. (e.g. '!polish')") - private List variantTypes; + private List variantTypes = Arrays.asList("slab", "stairs", "wall", "fence", "fence_gate", "vertical_slab"); @Config(description = "By default, only a mod's namespace is scanned for variants for its items (e.g. if coolmod adds coolmod:fun_block, it'll search only for coolmod:fun_block_stairs).\n" + " Mods in this list are also scanned for variants if none are found in itself (e.g. if quark is in the list and coolmod:fun_block_stairs doesn't exist, it'll try to look for quark:fun_block_stairs next)") - private List testedMods; + private List testedMods = Arrays.asList("quark"); @Config private boolean printVariantMapToLog = false; @Config(description = "Format is 'alias=original' in each value (e.g. 'wall=fence' means that a failed search for, minecraft:cobblestone_fence will try cobblestone_wall next)") - private List aliases; + private List aliases = Arrays.asList("carpet=slab", "pane=fence"); @Config(description = "Ends of block IDs to try and remove when looking for variants. (e.g. minecraft:oak_planks goes into minecraft:oak_stairs, so we have to include '_planks' in this list for it to find them or else it'll only look for minecraft:oak_planks_stairs)") - private List stripCandidates = Arrays.asList("_planks", "_wool", "s"); + private List stripCandidates = Arrays.asList("_planks", "_wool", "_block", "s"); @Config(description = "Add manual variant overrides here, the format is 'type,block,output' (e.g. polish,minecraft:stone_bricks,minecraft:chiseled_stone_bricks). The type must be listed in Variant Types") private List manualVariants = new ArrayList<>(); - @Config - private List blacklist = new ArrayList<>(); + @Config(description = " A list of block IDs and mappings to be excluded from variant selection.\n" + + "To exclude a block from being turned into other blocks, just include the block ID (e.g. minecraft:cobblestone).\n" + + "To exclude a block from having other blocks turned into it, suffix it with = (e.g. =minecraft:cobblestone_stairs)\n" + + "To exclude a specific block->variant combination, put = between the two (e.g. minecraft:cobblestone=minecraft:cobblestone_stairs)") + private List blacklist = Arrays.asList("minecraft:snow", "minecraft:bamboo", "quark:bamboo_block"); private Map blockVariants = new HashMap<>(); private Map originals = new HashMap<>(); @@ -50,11 +53,7 @@ public class BlockSuffixConfig extends AbstractConfigType { private List visibleVariants = new ArrayList<>(); private List sortedSuffixes; - public BlockSuffixConfig(List variantTypes, List testedMods, List aliases) { - this.variantTypes = variantTypes; - this.testedMods = testedMods; - this.aliases = aliases; - } + public VariantsConfig() { } @Override public void onReload(QuarkModule module, ConfigFlagManager flagManager) { @@ -163,13 +162,13 @@ private VariantMap getVariants(Block block) { Map newVariants = new HashMap<>(); - if(!isBlacklisted(block)) + if(!isBlacklisted(block, null)) for(String s : sortedSuffixes) { if(!variantTypes.contains(s)) continue; // this means its marked with ! so it won't be searched Block suffixed = getSuffixedBlock(block, s); - if(suffixed != null && !isBlacklisted(block)) { + if(suffixed != null && !isBlacklisted(null, suffixed) && !isBlacklisted(block, suffixed)) { newVariants.put(s, suffixed); originals.put(suffixed, block); } @@ -233,8 +232,17 @@ private Block getSuffixedBlock(String namespace, String name, String suffix) { return ret; } - private boolean isBlacklisted(Block block) { - return !blacklist.isEmpty() && blacklist.contains(Registry.BLOCK.getKey(block).toString()); + private boolean isBlacklisted(Block block, Block result) { + if(blacklist.isEmpty()) + return false; + + String search = ""; + if(block != null) + search += Registry.BLOCK.getKey(block).toString(); + if(result != null) + search += ("=" + Registry.BLOCK.getKey(result).toString()); + + return !search.isEmpty() && blacklist.contains(search); } public boolean isKnownVariant(String variant) { diff --git a/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java b/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java index fce1ccac4b..fbab615a97 100644 --- a/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java +++ b/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java @@ -53,7 +53,7 @@ import vazkii.quark.base.network.message.experimental.PlaceVariantUpdateMessage; import vazkii.quark.content.experimental.client.screen.VariantSelectorScreen; import vazkii.quark.content.experimental.client.tooltip.VariantsComponent; -import vazkii.quark.content.experimental.config.BlockSuffixConfig; +import vazkii.quark.content.experimental.config.VariantsConfig; import vazkii.quark.content.experimental.item.HammerItem; import java.util.Arrays; @@ -85,11 +85,7 @@ public class VariantSelectorModule extends QuarkModule { @Config public static int hudOffsetY = 0; @Config - public static BlockSuffixConfig variants = new BlockSuffixConfig( - Arrays.asList("slab", "stairs", "wall", "fence", "fence_gate", "vertical_slab"), - Arrays.asList("quark"), - Arrays.asList("carpet=slab", "pane=fence") - ); + public static VariantsConfig variants = new VariantsConfig(); public static Item hammer;