From 2a751355d7a4e72e2e75257941f03fc97e7552d9 Mon Sep 17 00:00:00 2001 From: Shadows_of_Fire Date: Fri, 1 Dec 2017 16:19:52 -0500 Subject: [PATCH] Adds Sack Blacklist (Closes #974) also apparently the common capabilities maven is throwing 403's so i've set it to the version in my cache. --- build.gradle | 2 +- .../config/values/ConfigStringListValues.java | 3 +- .../mod/inventory/ContainerBag.java | 44 ++++++++++++++++++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 8812703d5..e6e370650 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ dependencies { deobfCompile "mezz.jei:jei_1.12.1:+" deobfCompile "mcp.mobius.waila:Hwyla:+" compile "net.darkhax.tesla:Tesla-1.12:+" - deobfCompile "org.cyclops.commoncapabilities:CommonCapabilities:1.12-1.3.3+" + deobfCompile "org.cyclops.commoncapabilities:CommonCapabilities:1.12-1.3.3-126" } processResources { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java index ff239b302..7aa1d6d37 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java @@ -25,7 +25,8 @@ public enum ConfigStringListValues{ MINER_EXTRA_WHITELIST("Vertical Digger Extra Whitelist", ConfigCategories.MACHINE_VALUES, new String[0], "By default, the Vertical Digger mines everything that starts with 'ore' in the OreDictionary. If there is one that it can't mine, but should be able to, put its REGISTRY NAME here. These are the actual registered Item Names, the ones you use, for example, when using the /give Command. This Config Option only applies if the miner is in Ores Only Mode."), MINER_BLACKLIST("Vertical Digger Blacklist", ConfigCategories.MACHINE_VALUES, new String[0], "By default, the Vertical Digger mines everything that starts with 'ore' in the OreDictionary. If there is one that it can mine, but shouldn't be able to, put its REGISTRY NAME here. These are the actual registered Item Names, the ones you use, for example, when using the /give Command. This Config Option will apply in both modes."), REPAIRER_EXTRA_WHITELIST("Item Repairer Extra Whitelist", ConfigCategories.MACHINE_VALUES, new String[]{"tconstruct:pickaxe", "tconstruct:shovel", "tconstruct:hatchet", "tconstruct:mattock", "tconstruct:broadsword", "tconstruct:longsword", "tconstruct:frypan", "tconstruct:battlesign", "tconstruct:hammer", "tconstruct:excavator", "tconstruct:lumberaxe", "tconstruct:cleaver", "tconstruct:rapier"}, "By default, the Item Repairer only repairs items which are repairable in an anvil. Add an item's REGISTRY NAME here if you want it to be repairable."), - SPAWNER_CHANGER_BLACKLIST("Spawner Changer Blacklist", ConfigCategories.OTHER, new String[]{"minecraft:villager_golem"}, "By default, the Spawner Changer allows every living entity to be put into a spawner. If there is one that shouldn't be able to, put its MAPPING NAME here."); + SPAWNER_CHANGER_BLACKLIST("Spawner Changer Blacklist", ConfigCategories.OTHER, new String[]{"minecraft:villager_golem"}, "By default, the Spawner Changer allows every living entity to be put into a spawner. If there is one that shouldn't be able to, put its MAPPING NAME here."), + SACK_BLACKLIST("Sack Blacklist", ConfigCategories.OTHER, new String[0], "The items that aren't allowed to be put in the Traveller's Sack. Use REGISTRY NAMES, and if metadata is needed, add it like so: somemod:some_block@3"); public final String name; public final String category; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java index 0adba1024..b860ab079 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java @@ -10,6 +10,12 @@ package de.ellpeck.actuallyadditions.mod.inventory; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.tuple.Pair; + +import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotDeletion; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable; @@ -19,6 +25,7 @@ import de.ellpeck.actuallyadditions.mod.items.ItemDrill; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom; +import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -26,8 +33,11 @@ import net.minecraft.inventory.ClickType; import net.minecraft.inventory.Container; import net.minecraft.inventory.IContainerListener; import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -43,7 +53,13 @@ public class ContainerBag extends Container implements IButtonReactor{ public ContainerBag(ItemStack sack, InventoryPlayer inventory, boolean isVoid){ this.inventory = inventory; - this.bagInventory = new ItemStackHandlerCustom(getSlotAmount(isVoid)); + this.bagInventory = new ItemStackHandlerCustom(getSlotAmount(isVoid)) { + @Override + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if(isBlacklisted(stack)) return stack; + return super.insertItem(slot, stack, simulate); + }; + }; this.isVoid = isVoid; this.sack = sack; @@ -65,7 +81,7 @@ public class ContainerBag extends Container implements IButtonReactor{ this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.bagInventory, j+i*7, 10+j*18, 10+i*18){ @Override public boolean isItemValid(ItemStack stack){ - return ContainerBag.this.filter.check(stack); + return !isBlacklisted(stack) && ContainerBag.this.filter.check(stack); } }); } @@ -231,4 +247,28 @@ public class ContainerBag extends Container implements IButtonReactor{ this.filter.onButtonPressed(buttonID); } } + + private static final List> BLACKLIST = new ArrayList<>(); + + private static boolean runOnce = false; + + public static boolean isBlacklisted(ItemStack stack) { + if(!runOnce) { + runOnce = true; + for(String s : ConfigStringListValues.SACK_BLACKLIST.getValue()) { + String[] split = s.split("@"); + Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(split[0])); + if(item == null) { + ModUtil.LOGGER.error("Invalid item in sack blacklist: " + s); + continue; + } + if(split.length == 1) + BLACKLIST.add(Pair.of(item, 0)); + else if(split.length == 2) { + BLACKLIST.add(Pair.of(item, Integer.parseInt(split[1]))); + } + } + } + return BLACKLIST.contains(Pair.of(stack.getItem(), stack.getMetadata())); + } } \ No newline at end of file