Skip to content

Commit

Permalink
Add a configurable NBT key blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Dec 2, 2015
1 parent 93e4a96 commit 86943ce
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/main/java/mezz/jei/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import javax.annotation.Nonnull;

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

import net.minecraft.util.StatCollector;

import net.minecraftforge.common.config.Configuration;
Expand All @@ -13,6 +19,7 @@ public class Config {

public static boolean cheatItemsEnabled = false;
public static boolean tooltipModNameEnabled = true;
public static Set<String> nbtKeyBlacklist = new HashSet<>();

public static void preInit(@Nonnull FMLPreInitializationEvent event) {
configFile = new Configuration(event.getSuggestedConfigurationFile());
Expand All @@ -33,6 +40,11 @@ private static void syncConfig() {
String tooltipModNameEnabledDescription = StatCollector.translateToLocal("config.jei.tooltipModName.description");
tooltipModNameEnabled = configFile.getBoolean("config.jei.tooltipModName", Configuration.CATEGORY_GENERAL, tooltipModNameEnabled, tooltipModNameEnabledDescription);

String[] defaultNbtKeyBlacklist = new String[]{"BlockEntityTag", "CanPlaceOn"};
String nbtKeyBlacklistDescription = StatCollector.translateToLocal("config.jei.nbtKeyBlacklist.description");
String[] nbtKeyBlacklistArray = configFile.getStringList("config.jei.nbtKeyBlacklist", Configuration.CATEGORY_GENERAL, defaultNbtKeyBlacklist, nbtKeyBlacklistDescription);
Collections.addAll(nbtKeyBlacklist, nbtKeyBlacklistArray);

if (configFile.hasChanged()) {
configFile.save();
}
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/mezz/jei/util/StackUtil.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package mezz.jei.util;

import com.google.common.collect.Sets;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import net.minecraftforge.fml.common.registry.GameData;
import net.minecraftforge.oredict.OreDictionary;

import mezz.jei.config.Config;

public class StackUtil {

@Nonnull
Expand Down Expand Up @@ -280,12 +287,31 @@ public static String uniqueIdentifierForStack(@Nonnull ItemStack stack, boolean

StringBuilder itemKey = new StringBuilder(itemNameString).append(':').append(metadata);
if (stack.hasTagCompound()) {
itemKey.append(':').append(stack.getTagCompound());
NBTTagCompound nbtTagCompound = stack.getTagCompound();
nbtTagCompound = cleanNbt(nbtTagCompound);
if (!nbtTagCompound.hasNoTags()) {
itemKey.append(':').append(nbtTagCompound);
}
}

return itemKey.toString();
}

private static NBTTagCompound cleanNbt(NBTTagCompound nbtTagCompound) {
Set<String> keys = nbtTagCompound.getKeySet();

Set<String> ignoredKeys = Sets.intersection(keys, Config.nbtKeyBlacklist);
if (ignoredKeys.size() == 0) {
return nbtTagCompound;
}

nbtTagCompound = (NBTTagCompound) nbtTagCompound.copy();
for (String ignoredKey : ignoredKeys) {
nbtTagCompound.removeTag(ignoredKey);
}
return nbtTagCompound;
}

public static int addStack(Container container, Collection<Integer> slotIndexes, ItemStack stack, boolean doAdd) {
int added = 0;
// Add to existing stacks first
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/jei/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ config.jei.cheatItemsEnabled=Enable Item Cheating
config.jei.cheatItemsEnabled.description=/give items instead of showing the recipe
config.jei.tooltipModName=Tooltip Mod Name
config.jei.tooltipModName.description=Adds the name of the item's mod to its tooltip.
config.jei.nbtKeyBlacklist=NBT Key Blacklist
config.jei.nbtKeyBlacklist.description=List of NBT Keys that should be ignored when retrieving recipes.

# Recipes
gui.jei.craftingTableRecipes=Crafting Table Recipes
Expand Down

0 comments on commit 86943ce

Please sign in to comment.