This commit is contained in:
Shadows_of_Fire 2019-05-02 03:54:52 -04:00
parent 474a7874ec
commit 673b4bf52a
2 changed files with 46 additions and 9 deletions

View file

@ -78,7 +78,13 @@ public enum ConfigStringListValues {
"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");
"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"),
REPAIR_BLACKLIST(
"Repair Blacklist",
ConfigCategories.OTHER,
new String[0],
"The items that aren't allowed to be put in the Repairer. Use REGISTRY NAMES, and if metadata is needed, add it like so: somemod:some_block@3");
public final String name;
public final String category;

View file

@ -10,6 +10,12 @@
package de.ellpeck.actuallyadditions.mod.tile;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
@ -18,7 +24,9 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -110,11 +118,6 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase {
}
}
@Override
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation || slot == SLOT_INPUT;
}
@SideOnly(Side.CLIENT)
public int getEnergyScaled(int i) {
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
@ -125,13 +128,41 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase {
return 0;
}
@Override
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
return this.storage;
}
@Override
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !isBlacklisted(stack) && (!automation || slot == SLOT_INPUT);
}
@Override
public IRemover getRemover() {
return (slot, automation) -> !automation || slot == SLOT_OUTPUT;
}
@Override
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
return this.storage;
private static final List<Pair<Item, Integer>> BLACKLIST = new ArrayList<>();
private static boolean runOnce = false;
public static boolean isBlacklisted(ItemStack stack) {
if (!runOnce) {
runOnce = true;
for (String s : ConfigStringListValues.REPAIR_BLACKLIST.getValue()) {
String[] split = s.split("@");
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(split[0]));
if (item == null) {
ActuallyAdditions.LOGGER.error("Invalid item in repair 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()));
}
}