use of mekanism.common.content.oredictionificator.OredictionificatorItemFilter in project Mekanism by mekanism.
the class PacketEditFilter method handle.
@Override
public void handle(NetworkEvent.Context context) {
PlayerEntity player = context.getSender();
if (player == null) {
return;
}
TileEntity tile = WorldUtils.getTileEntity(player.level, pos);
if (tile != null) {
if (filter instanceof SorterFilter && tile instanceof TileEntityLogisticalSorter) {
HashList<SorterFilter<?>> filters = ((TileEntityLogisticalSorter) tile).getFilters();
int index = filters.indexOf(filter);
if (index != -1) {
filters.remove(index);
if (!delete) {
filters.add(index, (SorterFilter<?>) edited);
}
}
} else if (filter instanceof MinerFilter && tile instanceof TileEntityDigitalMiner) {
HashList<MinerFilter<?>> filters = ((TileEntityDigitalMiner) tile).getFilters();
int index = filters.indexOf(filter);
if (index != -1) {
filters.remove(index);
if (!delete) {
filters.add(index, (MinerFilter<?>) edited);
}
}
} else if (filter instanceof OredictionificatorItemFilter && tile instanceof TileEntityOredictionificator) {
HashList<OredictionificatorItemFilter> filters = ((TileEntityOredictionificator) tile).getFilters();
int index = filters.indexOf(filter);
if (index != -1) {
filters.remove(index);
if (!delete) {
filters.add(index, (OredictionificatorItemFilter) edited);
}
}
} else if (filter instanceof QIOFilter && tile instanceof TileEntityQIOFilterHandler) {
HashList<QIOFilter<?>> filters = ((TileEntityQIOFilterHandler) tile).getFilters();
int index = filters.indexOf(filter);
if (index != -1) {
filters.remove(index);
if (!delete) {
filters.add(index, (QIOFilter<?>) edited);
}
}
}
tile.setChanged();
}
}
use of mekanism.common.content.oredictionificator.OredictionificatorItemFilter in project Mekanism by mekanism.
the class CCArgumentWrapper method convertMapToFilter.
@Nullable
private static Object convertMapToFilter(Class<?> expectedType, Map<?, ?> map) {
// We may want to try improving this at some point, or somehow making it slightly less hardcoded
// but for now this will have to do
Object type = map.get("type");
if (type instanceof String) {
// Handle filters as arguments, this may not be the best implementation, but it will do for now
FilterType filterType = sanitizeStringToEnum(FilterType.class, (String) type);
if (filterType != null) {
IFilter<?> filter = BaseFilter.fromType(filterType);
if (expectedType.isInstance(filter)) {
// Validate the filter is of the type we expect
if (filter instanceof IItemStackFilter) {
ItemStack stack = tryCreateFilterItem(map.get("item"), map.get("itemNBT"));
if (stack.isEmpty()) {
return null;
}
((IItemStackFilter<?>) filter).setItemStack(stack);
} else if (filter instanceof IMaterialFilter) {
ItemStack stack = tryCreateFilterItem(map.get("materialItem"), null);
if (stack.isEmpty()) {
return null;
}
((IMaterialFilter<?>) filter).setMaterialItem(stack);
} else if (filter instanceof IModIDFilter) {
String modId = tryGetFilterModId(map.get("modId"));
if (modId == null) {
return null;
}
((IModIDFilter<?>) filter).setModID(modId);
} else if (filter instanceof ITagFilter) {
String tag = tryGetFilterTag(map.get("tag"));
if (tag == null) {
return null;
}
((ITagFilter<?>) filter).setTagName(tag);
}
if (filter instanceof MinerFilter) {
MinerFilter<?> minerFilter = (MinerFilter<?>) filter;
minerFilter.requiresReplacement = getBooleanFromRaw(map.get("requiresReplacement"));
minerFilter.replaceTarget = tryCreateItem(map.get("replaceTarget"));
} else if (filter instanceof SorterFilter) {
SorterFilter<?> sorterFilter = (SorterFilter<?>) filter;
sorterFilter.allowDefault = getBooleanFromRaw(map.get("allowDefault"));
Object rawColor = map.get("color");
if (rawColor instanceof String) {
sorterFilter.color = sanitizeStringToEnum(EnumColor.class, (String) rawColor);
}
sorterFilter.sizeMode = getBooleanFromRaw(map.get("size"));
sorterFilter.min = getIntFromRaw(map.get("min"));
sorterFilter.max = getIntFromRaw(map.get("max"));
if (sorterFilter.min < 0 || sorterFilter.max < 0 || sorterFilter.min > sorterFilter.max || sorterFilter.max > 64) {
return null;
}
if (sorterFilter instanceof SorterItemStackFilter) {
SorterItemStackFilter sorterItemFilter = (SorterItemStackFilter) sorterFilter;
sorterItemFilter.fuzzyMode = getBooleanFromRaw(map.get("fuzzy"));
}
} else if (filter instanceof QIOFilter) {
QIOFilter<?> qioFilter = (QIOFilter<?>) filter;
if (qioFilter instanceof QIOItemStackFilter) {
QIOItemStackFilter qioItemFilter = (QIOItemStackFilter) qioFilter;
qioItemFilter.fuzzyMode = getBooleanFromRaw(map.get("fuzzy"));
}
} else if (filter instanceof OredictionificatorFilter) {
OredictionificatorFilter<?, ?, ?> oredictionificatorFilter = (OredictionificatorFilter<?, ?, ?>) filter;
Object rawTag = map.get("target");
if (!(rawTag instanceof String)) {
return null;
}
String tag = (String) rawTag;
if (tag.isEmpty()) {
return null;
}
ResourceLocation rl = ResourceLocation.tryParse(tag);
if (rl == null || !TileEntityOredictionificator.isValidTarget(rl)) {
return null;
}
oredictionificatorFilter.setFilter(rl);
if (oredictionificatorFilter instanceof OredictionificatorItemFilter) {
Item item = tryCreateItem(map.get("selected"));
if (item != Items.AIR) {
((OredictionificatorItemFilter) oredictionificatorFilter).setSelectedOutput(item);
}
}
}
return filter;
}
}
}
return null;
}
use of mekanism.common.content.oredictionificator.OredictionificatorItemFilter in project Mekanism by mekanism.
the class GuiOredictionificator method addGuiElements.
@Override
protected void addGuiElements() {
super.addGuiElements();
// Filter holder
addButton(new GuiElementHolder(this, 9, 17, 144, 68));
// new filter button border
addButton(new GuiElementHolder(this, 9, 85, 144, 22));
scrollBar = addButton(new GuiScrollBar(this, 153, 17, 90, () -> tile.getFilters().size(), () -> FILTER_COUNT));
addButton(new GuiProgress(() -> tile.didProcess, ProgressType.LARGE_RIGHT, this, 64, 119));
addButton(new TranslationButton(this, 10, 86, 142, 20, MekanismLang.BUTTON_NEW_FILTER, () -> addWindow(GuiOredictionificatorFilter.create(this, tile))));
// Add each of the buttons and then just change visibility state to match filter info
for (int i = 0; i < FILTER_COUNT; i++) {
addButton(new FilterButton(this, 10, 18 + i * 22, 142, 22, i, scrollBar::getCurrentSelection, tile::getFilters, this::onClick, filter -> {
if (filter instanceof OredictionificatorItemFilter) {
return Collections.singletonList(((OredictionificatorItemFilter) filter).getResult());
}
return Collections.emptyList();
})).warning(WarningType.INVALID_OREDICTIONIFICATOR_FILTER, filter -> filter != null && !filter.hasFilter());
}
// While we track and show warnings on the slots themselves we also need to track the warning
// for if any of the set filters have it even if one of them is not visible
// Note: We add this after all the buttons have their warnings added so that it is further down the tracker
// so the tracker can short circuit on this type of warning and not have to check all the filters if one of
// the ones that are currently being shown has the warning
trackWarning(WarningType.INVALID_OREDICTIONIFICATOR_FILTER, () -> tile.getFilters().stream().anyMatch(filter -> !filter.hasFilter()));
}
Aggregations