magnet filtering
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package appeng.core;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
@@ -380,6 +381,9 @@ final class Registration {
|
||||
Upgrades.FUZZY.registerItem(items.viewCell(), 1);
|
||||
Upgrades.INVERTER.registerItem(items.viewCell(), 1);
|
||||
|
||||
Upgrades.FUZZY.registerItem(AEApi.instance().definitions().materials().cardMagnet(), 1);
|
||||
Upgrades.INVERTER.registerItem(AEApi.instance().definitions().materials().cardMagnet(), 1);
|
||||
|
||||
// Storage Bus
|
||||
Upgrades.FUZZY.registerItem(parts.storageBus(), 1);
|
||||
Upgrades.INVERTER.registerItem(parts.storageBus(), 1);
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
package appeng.items.materials;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.implementations.items.IItemGroup;
|
||||
@@ -27,11 +29,14 @@ import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.api.implementations.tiles.ISegmentedInventory;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.storage.ICellWorkbenchItem;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.IStackSrc;
|
||||
import appeng.core.features.MaterialStackSrc;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
@@ -63,7 +68,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule {
|
||||
public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule, ICellWorkbenchItem {
|
||||
public static ItemMaterial instance;
|
||||
|
||||
private static final int KILO_SCALAR = 1024;
|
||||
@@ -313,6 +318,36 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is) {
|
||||
return is.isItemEqual(AEApi.instance().definitions().materials().cardMagnet().maybeStack(1).get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory(final ItemStack is) {
|
||||
return new CellUpgrades(is, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getConfigInventory(final ItemStack is) {
|
||||
return new CellConfig(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(final ItemStack is) {
|
||||
final String fz = Platform.openNbtData(is).getString("FuzzyMode");
|
||||
try {
|
||||
return FuzzyMode.valueOf(fz);
|
||||
} catch (final Throwable t) {
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
|
||||
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
|
||||
}
|
||||
|
||||
private static class SlightlyBetterSort implements Comparator<String> {
|
||||
private final Pattern pattern;
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ import appeng.api.util.IConfigManager;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.items.materials.ItemMaterial;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.Platform;
|
||||
@@ -154,12 +157,48 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
|
||||
ItemStackHandler siu = new ItemStackHandler(0);
|
||||
siu.deserializeNBT(upgradeNBT);
|
||||
for (int s = 0; s < siu.getSlots(); s++) {
|
||||
if (siu.getStackInSlot(s).isItemEqual(AEApi.instance().definitions().materials().cardMagnet().maybeStack(1).get())) {
|
||||
ItemStack is = siu.getStackInSlot(s);
|
||||
if (is.isItemEqual(AEApi.instance().definitions().materials().cardMagnet().maybeStack(1).get())) {
|
||||
ItemMaterial im = (ItemMaterial) is.getItem();
|
||||
CellConfig c = (CellConfig) im.getConfigInventory(is);
|
||||
CellUpgrades u = (CellUpgrades) im.getUpgradesInventory(is);
|
||||
FuzzyMode fz = null;
|
||||
boolean isFuzzy = u.getInstalledUpgrades(Upgrades.FUZZY) == 1;
|
||||
if (isFuzzy) {
|
||||
fz = im.getFuzzyMode(is);
|
||||
}
|
||||
boolean inverted = u.getInstalledUpgrades(Upgrades.INVERTER) == 1;
|
||||
|
||||
List<EntityItem> ei = worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(
|
||||
new Vec3d(entityIn.posX + 5, entityIn.posY + 5, entityIn.posZ + 5),
|
||||
new Vec3d(entityIn.posX - 5, entityIn.posY - 5, entityIn.posZ - 5)));
|
||||
boolean emptyFilter = true;
|
||||
for (EntityItem i : ei) {
|
||||
i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ);
|
||||
boolean matched = false;
|
||||
for (int ss = 0; ss < c.getSlots(); ss++) {
|
||||
ItemStack filter = c.getStackInSlot(ss);
|
||||
if (filter.isEmpty()) continue;
|
||||
emptyFilter = false;
|
||||
if (isFuzzy) {
|
||||
if (Platform.itemComparisons().isFuzzyEqualItem(filter, i.getItem(), fz)) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (Platform.itemComparisons().isSameItem(filter, i.getItem())) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (emptyFilter) {
|
||||
i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ);
|
||||
}
|
||||
if (matched && !inverted) {
|
||||
i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ);
|
||||
} else if (!matched && inverted) {
|
||||
i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user