use of com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode in project Create by Creators-of-Create.
the class BlueprintOverlayRenderer method getItemsMatchingFilter.
private static ItemStack[] getItemsMatchingFilter(ItemStack filter) {
return cachedRenderedFilters.computeIfAbsent(filter, itemStack -> {
CompoundTag tag = itemStack.getOrCreateTag();
if (AllItems.FILTER.isIn(itemStack) && !tag.getBoolean("Blacklist")) {
ItemStackHandler filterItems = FilterItem.getFilterItems(itemStack);
List<ItemStack> list = new ArrayList<>();
for (int slot = 0; slot < filterItems.getSlots(); slot++) {
ItemStack stackInSlot = filterItems.getStackInSlot(slot);
if (!stackInSlot.isEmpty())
list.add(stackInSlot);
}
return list.toArray(new ItemStack[list.size()]);
}
if (AllItems.ATTRIBUTE_FILTER.isIn(itemStack)) {
WhitelistMode whitelistMode = WhitelistMode.values()[tag.getInt("WhitelistMode")];
ListTag attributes = tag.getList("MatchedAttributes", net.minecraft.nbt.Tag.TAG_COMPOUND);
if (whitelistMode == WhitelistMode.WHITELIST_DISJ && attributes.size() == 1) {
ItemAttribute fromNBT = ItemAttribute.fromNBT((CompoundTag) attributes.get(0));
if (fromNBT instanceof ItemAttribute.InTag) {
ItemAttribute.InTag inTag = (ItemAttribute.InTag) fromNBT;
Tag<Item> itag = ItemTags.getAllTags().getTag(inTag.tagName);
if (itag != null)
return Ingredient.of(itag).getItems();
}
}
}
return new ItemStack[0];
});
}
use of com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode in project Create by Creators-of-Create.
the class FilterItem method test.
private static boolean test(Level world, ItemStack stack, ItemStack filter, boolean matchNBT) {
if (filter.isEmpty())
return true;
if (!(filter.getItem() instanceof FilterItem))
return (matchNBT ? ItemHandlerHelper.canItemStacksStack(filter, stack) : ItemStack.isSame(filter, stack));
if (AllItems.FILTER.get() == filter.getItem()) {
ItemStackHandler filterItems = getFilterItems(filter);
boolean respectNBT = filter.getOrCreateTag().getBoolean("RespectNBT");
boolean blacklist = filter.getOrCreateTag().getBoolean("Blacklist");
for (int slot = 0; slot < filterItems.getSlots(); slot++) {
ItemStack stackInSlot = filterItems.getStackInSlot(slot);
if (stackInSlot.isEmpty())
continue;
boolean matches = test(world, stack, stackInSlot, respectNBT);
if (matches)
return !blacklist;
}
return blacklist;
}
if (AllItems.ATTRIBUTE_FILTER.get() == filter.getItem()) {
WhitelistMode whitelistMode = WhitelistMode.values()[filter.getOrCreateTag().getInt("WhitelistMode")];
ListTag attributes = filter.getOrCreateTag().getList("MatchedAttributes", Tag.TAG_COMPOUND);
for (Tag inbt : attributes) {
CompoundTag compound = (CompoundTag) inbt;
ItemAttribute attribute = ItemAttribute.fromNBT(compound);
if (attribute == null)
continue;
boolean matches = attribute.appliesTo(stack, world) != compound.getBoolean("Inverted");
if (matches) {
switch(whitelistMode) {
case BLACKLIST:
return false;
case WHITELIST_CONJ:
continue;
case WHITELIST_DISJ:
return true;
}
} else {
switch(whitelistMode) {
case BLACKLIST:
continue;
case WHITELIST_CONJ:
return false;
case WHITELIST_DISJ:
continue;
}
}
}
switch(whitelistMode) {
case BLACKLIST:
return true;
case WHITELIST_CONJ:
return true;
case WHITELIST_DISJ:
return false;
}
}
return false;
}
use of com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode in project Create by Creators-of-Create.
the class FilterItem method makeSummary.
private List<Component> makeSummary(ItemStack filter) {
List<Component> list = new ArrayList<>();
if (type == FilterType.REGULAR) {
ItemStackHandler filterItems = getFilterItems(filter);
boolean blacklist = filter.getOrCreateTag().getBoolean("Blacklist");
list.add((blacklist ? Lang.translate("gui.filter.deny_list") : Lang.translate("gui.filter.allow_list")).withStyle(ChatFormatting.GOLD));
int count = 0;
for (int i = 0; i < filterItems.getSlots(); i++) {
if (count > 3) {
list.add(new TextComponent("- ...").withStyle(ChatFormatting.DARK_GRAY));
break;
}
ItemStack filterStack = filterItems.getStackInSlot(i);
if (filterStack.isEmpty())
continue;
list.add(new TextComponent("- ").append(filterStack.getHoverName()).withStyle(ChatFormatting.GRAY));
count++;
}
if (count == 0)
return Collections.emptyList();
}
if (type == FilterType.ATTRIBUTE) {
WhitelistMode whitelistMode = WhitelistMode.values()[filter.getOrCreateTag().getInt("WhitelistMode")];
list.add((whitelistMode == WhitelistMode.WHITELIST_CONJ ? Lang.translate("gui.attribute_filter.allow_list_conjunctive") : whitelistMode == WhitelistMode.WHITELIST_DISJ ? Lang.translate("gui.attribute_filter.allow_list_disjunctive") : Lang.translate("gui.attribute_filter.deny_list")).withStyle(ChatFormatting.GOLD));
int count = 0;
ListTag attributes = filter.getOrCreateTag().getList("MatchedAttributes", Tag.TAG_COMPOUND);
for (Tag inbt : attributes) {
CompoundTag compound = (CompoundTag) inbt;
ItemAttribute attribute = ItemAttribute.fromNBT(compound);
boolean inverted = compound.getBoolean("Inverted");
if (count > 3) {
list.add(new TextComponent("- ...").withStyle(ChatFormatting.DARK_GRAY));
break;
}
list.add(new TextComponent("- ").append(attribute.format(inverted)));
count++;
}
if (count == 0)
return Collections.emptyList();
}
return list;
}
Aggregations