Skip to content

Commit

Permalink
Better suffix config and saner defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Vazkii committed Oct 20, 2023
1 parent fec4889 commit 4c8621d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> variantTypes;
private List<String> 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<String> testedMods;
private List<String> 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<String> aliases;
private List<String> 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<String> stripCandidates = Arrays.asList("_planks", "_wool", "s");
private List<String> 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<String> manualVariants = new ArrayList<>();

@Config
private List<String> 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<String> blacklist = Arrays.asList("minecraft:snow", "minecraft:bamboo", "quark:bamboo_block");

private Map<Block, VariantMap> blockVariants = new HashMap<>();
private Map<Block, Block> originals = new HashMap<>();
Expand All @@ -50,11 +53,7 @@ public class BlockSuffixConfig extends AbstractConfigType {
private List<String> visibleVariants = new ArrayList<>();
private List<String> sortedSuffixes;

public BlockSuffixConfig(List<String> variantTypes, List<String> testedMods, List<String> aliases) {
this.variantTypes = variantTypes;
this.testedMods = testedMods;
this.aliases = aliases;
}
public VariantsConfig() { }

@Override
public void onReload(QuarkModule module, ConfigFlagManager flagManager) {
Expand Down Expand Up @@ -163,13 +162,13 @@ private VariantMap getVariants(Block block) {

Map<String, Block> 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);
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 4c8621d

Please sign in to comment.