More fixes

This commit is contained in:
Sebastian Hartte
2020-06-29 21:23:50 +02:00
parent 0d63f560d3
commit ca104912d6
121 changed files with 2623 additions and 2563 deletions
@@ -1,306 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.storage;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import appeng.api.config.FuzzyMode;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.storage.cells.CellState;
import appeng.api.storage.cells.ICellInventory;
import appeng.api.storage.cells.ISaveProvider;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
/**
* @author DrummerMC
* @version rv6 - 2018-01-17
* @since rv6 2018-01-17
*/
public abstract class AbstractCellInventory<T extends IAEStack<T>> implements ICellInventory<T> {
private static final int MAX_ITEM_TYPES = 63;
private static final String ITEM_TYPE_TAG = "it";
private static final String ITEM_COUNT_TAG = "ic";
private static final String ITEM_SLOT = "#";
private static final String ITEM_SLOT_COUNT = "@";
protected static final String ITEM_PRE_FORMATTED_COUNT = "PF";
protected static final String ITEM_PRE_FORMATTED_SLOT = "PF#";
protected static final String ITEM_PRE_FORMATTED_NAME = "PN";
protected static final String ITEM_PRE_FORMATTED_FUZZY = "FP";
private static final String[] ITEM_SLOT_KEYS = new String[MAX_ITEM_TYPES];
private static final String[] ITEM_SLOT_COUNT_KEYS = new String[MAX_ITEM_TYPES];
private final CompoundTag tagCompound;
protected final ISaveProvider container;
private int maxItemTypes = MAX_ITEM_TYPES;
private short storedItems = 0;
private int storedItemCount = 0;
protected IItemList<T> cellItems;
private final ItemStack i;
protected final IStorageCell<T> cellType;
protected final int itemsPerByte;
private boolean isPersisted = true;
static {
for (int x = 0; x < MAX_ITEM_TYPES; x++) {
ITEM_SLOT_KEYS[x] = ITEM_SLOT + x;
ITEM_SLOT_COUNT_KEYS[x] = ITEM_SLOT_COUNT + x;
}
}
protected AbstractCellInventory(final IStorageCell<T> cellType, final ItemStack o, final ISaveProvider container) {
this.i = o;
this.cellType = cellType;
this.itemsPerByte = this.cellType.getChannel().getUnitsPerByte();
this.maxItemTypes = this.cellType.getTotalTypes(this.i);
if (this.maxItemTypes > MAX_ITEM_TYPES) {
this.maxItemTypes = MAX_ITEM_TYPES;
}
if (this.maxItemTypes < 1) {
this.maxItemTypes = 1;
}
this.container = container;
this.tagCompound = o.getOrCreateTag();
this.storedItems = this.tagCompound.getShort(ITEM_TYPE_TAG);
this.storedItemCount = this.tagCompound.getInt(ITEM_COUNT_TAG);
this.cellItems = null;
}
protected IItemList<T> getCellItems() {
if (this.cellItems == null) {
this.cellItems = this.getChannel().createList();
this.loadCellItems();
}
return this.cellItems;
}
@Override
public void persist() {
if (this.isPersisted) {
return;
}
int itemCount = 0;
// add new pretty stuff...
int x = 0;
for (final T v : this.cellItems) {
itemCount += v.getStackSize();
final CompoundTag g = new CompoundTag();
v.writeToNBT(g);
this.tagCompound.put(ITEM_SLOT_KEYS[x], g);
this.tagCompound.putInt(ITEM_SLOT_COUNT_KEYS[x], (int) v.getStackSize());
x++;
}
final short oldStoredItems = this.storedItems;
this.storedItems = (short) this.cellItems.size();
if (this.cellItems.isEmpty()) {
this.tagCompound.remove(ITEM_TYPE_TAG);
} else {
this.tagCompound.putShort(ITEM_TYPE_TAG, this.storedItems);
}
this.storedItemCount = itemCount;
if (itemCount == 0) {
this.tagCompound.remove(ITEM_COUNT_TAG);
} else {
this.tagCompound.putInt(ITEM_COUNT_TAG, itemCount);
}
// clean any old crusty stuff...
for (; x < oldStoredItems && x < this.maxItemTypes; x++) {
this.tagCompound.remove(ITEM_SLOT_KEYS[x]);
this.tagCompound.remove(ITEM_SLOT_COUNT_KEYS[x]);
}
this.isPersisted = true;
}
protected void saveChanges() {
// recalculate values
this.storedItems = (short) this.cellItems.size();
this.storedItemCount = 0;
for (final T v : this.cellItems) {
this.storedItemCount += v.getStackSize();
}
this.isPersisted = false;
if (this.container != null) {
this.container.saveChanges(this);
} else {
// if there is no ISaveProvider, store to NBT immediately
this.persist();
}
}
private void loadCellItems() {
if (this.cellItems == null) {
this.cellItems = this.getChannel().createList();
}
this.cellItems.resetStatus(); // clears totals and stuff.
final int types = (int) this.getStoredItemTypes();
boolean needsUpdate = false;
for (int slot = 0; slot < types; slot++) {
CompoundTag compoundTag = this.tagCompound.getCompound(ITEM_SLOT_KEYS[slot]);
int stackSize = this.tagCompound.getInt(ITEM_SLOT_COUNT_KEYS[slot]);
needsUpdate |= !this.loadCellItem(compoundTag, stackSize);
}
if (needsUpdate) {
this.saveChanges();
}
}
/**
* Load a single item.
*
* @param compoundTag
* @param stackSize
* @return true when successfully loaded
*/
protected abstract boolean loadCellItem(CompoundTag compoundTag, int stackSize);
@Override
public IItemList<T> getAvailableItems(final IItemList<T> out) {
for (final T item : this.getCellItems()) {
out.add(item);
}
return out;
}
@Override
public ItemStack getItemStack() {
return this.i;
}
@Override
public double getIdleDrain() {
return this.cellType.getIdleDrain();
}
@Override
public FuzzyMode getFuzzyMode() {
return this.cellType.getFuzzyMode(this.i);
}
@Override
public FixedItemInv getConfigInventory() {
return this.cellType.getConfigInventory(this.i);
}
@Override
public FixedItemInv getUpgradesInventory() {
return this.cellType.getUpgradesInventory(this.i);
}
@Override
public int getBytesPerType() {
return this.cellType.getBytesPerType(this.i);
}
@Override
public boolean canHoldNewItem() {
final long bytesFree = this.getFreeBytes();
return (bytesFree > this.getBytesPerType()
|| (bytesFree == this.getBytesPerType() && this.getUnusedItemCount() > 0))
&& this.getRemainingItemTypes() > 0;
}
@Override
public long getTotalBytes() {
return this.cellType.getBytes(this.i);
}
@Override
public long getFreeBytes() {
return this.getTotalBytes() - this.getUsedBytes();
}
@Override
public long getTotalItemTypes() {
return this.maxItemTypes;
}
@Override
public long getStoredItemCount() {
return this.storedItemCount;
}
@Override
public long getStoredItemTypes() {
return this.storedItems;
}
@Override
public long getRemainingItemTypes() {
final long basedOnStorage = this.getFreeBytes() / this.getBytesPerType();
final long baseOnTotal = this.getTotalItemTypes() - this.getStoredItemTypes();
return basedOnStorage > baseOnTotal ? baseOnTotal : basedOnStorage;
}
@Override
public long getUsedBytes() {
final long bytesForItemCount = (this.getStoredItemCount() + this.getUnusedItemCount()) / this.itemsPerByte;
return this.getStoredItemTypes() * this.getBytesPerType() + bytesForItemCount;
}
@Override
public long getRemainingItemCount() {
final long remaining = this.getFreeBytes() * this.itemsPerByte + this.getUnusedItemCount();
return remaining > 0 ? remaining : 0;
}
@Override
public int getUnusedItemCount() {
final int div = (int) (this.getStoredItemCount() % 8);
if (div == 0) {
return 0;
}
return this.itemsPerByte - div;
}
@Override
public CellState getStatusForCell() {
if (this.getStoredItemTypes() == 0) {
return CellState.EMPTY;
}
if (this.canHoldNewItem()) {
return CellState.NOT_EMPTY;
}
if (this.getRemainingItemCount() > 0) {
return CellState.TYPES_FULL;
}
return CellState.FULL;
}
}
@@ -1,238 +0,0 @@
package appeng.me.storage;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import appeng.api.config.Actionable;
import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.cells.ICellInventory;
import appeng.api.storage.cells.ISaveProvider;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.util.item.AEStack;
public class BasicCellInventory<T extends IAEStack<T>> extends AbstractCellInventory<T> {
private final IStorageChannel<T> channel;
private BasicCellInventory(final IStorageCell<T> cellType, final ItemStack o, final ISaveProvider container) {
super(cellType, o, container);
this.channel = cellType.getChannel();
}
public static <T extends IAEStack<T>> ICellInventory<T> createInventory(final ItemStack o,
final ISaveProvider container) {
try {
if (o == null) {
throw new AppEngException("ItemStack was used as a cell, but was not a cell!");
}
final Item type = o.getItem();
final IStorageCell<T> cellType;
if (type instanceof IStorageCell) {
cellType = (IStorageCell<T>) type;
} else {
throw new AppEngException("ItemStack was used as a cell, but was not a cell!");
}
if (!cellType.isStorageCell(o)) {
throw new AppEngException("ItemStack was used as a cell, but was not a cell!");
}
return new BasicCellInventory<T>(cellType, o, container);
} catch (final AppEngException e) {
AELog.error(e);
return null;
}
}
public static <T extends AEStack<T>> boolean isCellOfType(final ItemStack input, IStorageChannel<?> channel) {
final IStorageCell<?> type = getStorageCell(input);
return type != null && type.getChannel() == channel;
}
public static boolean isCell(final ItemStack input) {
return getStorageCell(input) != null;
}
private boolean isStorageCell(final T input) {
if (input instanceof IAEItemStack) {
final IAEItemStack stack = (IAEItemStack) input;
final IStorageCell<?> type = getStorageCell(stack.getDefinition());
return type != null && !type.storableInStorageCell();
}
return false;
}
private static IStorageCell<?> getStorageCell(final ItemStack input) {
if (input != null) {
final Item type = input.getItem();
if (type instanceof IStorageCell) {
return (IStorageCell<?>) type;
}
}
return null;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static boolean isCellEmpty(ICellInventory inv) {
if (inv != null) {
return inv.getAvailableItems(inv.getChannel().createList()).isEmpty();
}
return true;
}
@Override
public T injectItems(T input, Actionable mode, IActionSource src) {
if (input == null) {
return null;
}
if (input.getStackSize() == 0) {
return null;
}
if (this.cellType.isBlackListed(this.getItemStack(), input)) {
return input;
}
// This is slightly hacky as it expects a read-only access, but fine for now.
// TODO: Guarantee a read-only access. E.g. provide an isEmpty() method and
// ensure CellInventory does not write
// any NBT data for empty cells instead of relying on an empty IItemContainer
if (this.isStorageCell(input)) {
final ICellInventory<?> meInventory = createInventory(((IAEItemStack) input).createItemStack(), null);
if (!isCellEmpty(meInventory)) {
return input;
}
}
final T l = this.getCellItems().findPrecise(input);
if (l != null) {
final long remainingItemCount = this.getRemainingItemCount();
if (remainingItemCount <= 0) {
return input;
}
if (input.getStackSize() > remainingItemCount) {
final T r = input.copy();
r.setStackSize(r.getStackSize() - remainingItemCount);
if (mode == Actionable.MODULATE) {
l.setStackSize(l.getStackSize() + remainingItemCount);
this.saveChanges();
}
return r;
} else {
if (mode == Actionable.MODULATE) {
l.setStackSize(l.getStackSize() + input.getStackSize());
this.saveChanges();
}
return null;
}
}
if (this.canHoldNewItem()) // room for new type, and for at least one item!
{
final int remainingItemCount = (int) this.getRemainingItemCount()
- this.getBytesPerType() * this.itemsPerByte;
if (remainingItemCount > 0) {
if (input.getStackSize() > remainingItemCount) {
final T toReturn = input.copy();
toReturn.setStackSize(input.getStackSize() - remainingItemCount);
if (mode == Actionable.MODULATE) {
final T toWrite = input.copy();
toWrite.setStackSize(remainingItemCount);
this.cellItems.add(toWrite);
this.saveChanges();
}
return toReturn;
}
if (mode == Actionable.MODULATE) {
this.cellItems.add(input);
this.saveChanges();
}
return null;
}
}
return input;
}
@Override
public T extractItems(T request, Actionable mode, IActionSource src) {
if (request == null) {
return null;
}
final long size = Math.min(Integer.MAX_VALUE, request.getStackSize());
T Results = null;
final T l = this.getCellItems().findPrecise(request);
if (l != null) {
Results = l.copy();
if (l.getStackSize() <= size) {
Results.setStackSize(l.getStackSize());
if (mode == Actionable.MODULATE) {
l.setStackSize(0);
this.saveChanges();
}
} else {
Results.setStackSize(size);
if (mode == Actionable.MODULATE) {
l.setStackSize(l.getStackSize() - size);
this.saveChanges();
}
}
}
return Results;
}
@Override
public IStorageChannel<T> getChannel() {
return this.channel;
}
@Override
protected boolean loadCellItem(CompoundTag compoundTag, int stackSize) {
// Now load the item stack
final T t;
try {
t = this.getChannel().createFromNBT(compoundTag);
if (t == null) {
AELog.warn("Removing item " + compoundTag
+ " from storage cell because the associated item type couldn't be found.");
return false;
}
} catch (Throwable ex) {
if (AEConfig.instance().isRemoveCrashingItemsOnLoad()) {
AELog.warn(ex,
"Removing item " + compoundTag + " from storage cell because loading the ItemStack crashed.");
return false;
}
throw ex;
}
t.setStackSize(stackSize);
if (stackSize > 0) {
this.cellItems.add(t);
}
return true;
}
}
@@ -1,128 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.storage;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.cells.ICellInventory;
import appeng.api.storage.cells.ICellInventoryHandler;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
/**
* @author DrummerMC
* @version rv6 - 2018-01-23
* @since rv6 2018-01-23
*/
public class BasicCellInventoryHandler<T extends IAEStack<T>> extends MEInventoryHandler<T>
implements ICellInventoryHandler<T> {
public BasicCellInventoryHandler(final IMEInventory c, final IStorageChannel<T> channel) {
super(c, channel);
final ICellInventory ci = this.getCellInv();
if (ci != null) {
final IItemList<T> priorityList = channel.createList();
final FixedItemInv upgrades = ci.getUpgradesInventory();
final FixedItemInv config = ci.getConfigInventory();
final FuzzyMode fzMode = ci.getFuzzyMode();
boolean hasInverter = false;
boolean hasFuzzy = false;
for (int x = 0; x < upgrades.getSlotCount(); x++) {
final ItemStack is = upgrades.getInvStack(x);
if (!is.isEmpty() && is.getItem() instanceof IUpgradeModule) {
final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is);
if (u != null) {
switch (u) {
case FUZZY:
hasFuzzy = true;
break;
case INVERTER:
hasInverter = true;
break;
default:
}
}
}
}
for (int x = 0; x < config.getSlotCount(); x++) {
final ItemStack is = config.getInvStack(x);
if (!is.isEmpty()) {
final T configItem = channel.createStack(is);
if (configItem != null) {
priorityList.add(configItem);
}
}
}
this.setWhitelist(hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
if (!priorityList.isEmpty()) {
if (hasFuzzy) {
this.setPartitionList(new FuzzyPriorityList<>(priorityList, fzMode));
} else {
this.setPartitionList(new PrecisePriorityList<>(priorityList));
}
}
}
}
@Override
public ICellInventory getCellInv() {
Object o = this.getInternal();
if (o instanceof MEPassThrough) {
o = ((MEPassThrough) o).getInternal();
}
return (ICellInventory) (o instanceof ICellInventory ? o : null);
}
@Override
public boolean isPreformatted() {
return !this.getPartitionList().isEmpty();
}
@Override
public boolean isFuzzy() {
return this.getPartitionList() instanceof FuzzyPriorityList;
}
@Override
public IncludeExclude getIncludeExcludeMode() {
return this.getWhitelist();
}
CompoundTag openNbtData() {
return this.getCellInv().getItemStack().getOrCreateTag();
}
}
@@ -1,119 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.storage;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.cells.ICellInventoryHandler;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.items.contents.CellConfig;
import appeng.util.item.AEItemStack;
public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack> {
private final IItemList<IAEItemStack> itemListCache = AEApi.instance().storage()
.getStorageChannel(IItemStorageChannel.class).createList();
protected CreativeCellInventory(final ItemStack o) {
final CellConfig cc = new CellConfig(o);
for (final ItemStack is : cc) {
if (!is.isEmpty()) {
final IAEItemStack i = AEItemStack.fromItemStack(is);
i.setStackSize(Integer.MAX_VALUE);
this.itemListCache.add(i);
}
}
}
public static ICellInventoryHandler getCell(final ItemStack o) {
return new BasicCellInventoryHandler(new CreativeCellInventory(o),
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
}
@Override
public IAEItemStack injectItems(final IAEItemStack input, final Actionable mode, final IActionSource src) {
final IAEItemStack local = this.itemListCache.findPrecise(input);
if (local == null) {
return input;
}
return null;
}
@Override
public IAEItemStack extractItems(final IAEItemStack request, final Actionable mode, final IActionSource src) {
final IAEItemStack local = this.itemListCache.findPrecise(request);
if (local == null) {
return null;
}
return request.copy();
}
@Override
public IItemList<IAEItemStack> getAvailableItems(final IItemList out) {
for (final IAEItemStack ais : this.itemListCache) {
out.add(ais);
}
return out;
}
@Override
public IStorageChannel getChannel() {
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
}
@Override
public AccessRestriction getAccess() {
return AccessRestriction.READ_WRITE;
}
@Override
public boolean isPrioritized(final IAEItemStack input) {
return this.itemListCache.findPrecise(input) != null;
}
@Override
public boolean canAccept(final IAEItemStack input) {
return this.itemListCache.findPrecise(input) != null;
}
@Override
public int getPriority() {
return 0;
}
@Override
public int getSlot() {
return 0;
}
@Override
public boolean validForPass(final int i) {
return true;
}
}
@@ -1,167 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.storage;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.IncludeExclude;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.util.prioritylist.DefaultPriorityList;
import appeng.util.prioritylist.IPartitionList;
public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHandler<T> {
private final IMEInventoryHandler<T> internal;
private int myPriority;
private IncludeExclude myWhitelist;
private AccessRestriction myAccess;
private IPartitionList<T> myPartitionList;
private AccessRestriction cachedAccessRestriction;
private boolean hasReadAccess;
private boolean hasWriteAccess;
public MEInventoryHandler(final IMEInventory<T> i, final IStorageChannel<T> channel) {
if (i instanceof IMEInventoryHandler) {
this.internal = (IMEInventoryHandler<T>) i;
} else {
this.internal = new MEPassThrough<>(i, channel);
}
this.myPriority = 0;
this.myWhitelist = IncludeExclude.WHITELIST;
this.setBaseAccess(AccessRestriction.READ_WRITE);
this.myPartitionList = new DefaultPriorityList<>();
}
IncludeExclude getWhitelist() {
return this.myWhitelist;
}
public void setWhitelist(final IncludeExclude myWhitelist) {
this.myWhitelist = myWhitelist;
}
public AccessRestriction getBaseAccess() {
return this.myAccess;
}
public void setBaseAccess(final AccessRestriction myAccess) {
this.myAccess = myAccess;
this.cachedAccessRestriction = this.myAccess.restrictPermissions(this.internal.getAccess());
this.hasReadAccess = this.cachedAccessRestriction.hasPermission(AccessRestriction.READ);
this.hasWriteAccess = this.cachedAccessRestriction.hasPermission(AccessRestriction.WRITE);
}
IPartitionList<T> getPartitionList() {
return this.myPartitionList;
}
public void setPartitionList(final IPartitionList<T> myPartitionList) {
this.myPartitionList = myPartitionList;
}
@Override
public T injectItems(final T input, final Actionable type, final IActionSource src) {
if (!this.canAccept(input)) {
return input;
}
return this.internal.injectItems(input, type, src);
}
@Override
public T extractItems(final T request, final Actionable type, final IActionSource src) {
if (!this.hasReadAccess) {
return null;
}
return this.internal.extractItems(request, type, src);
}
@Override
public IItemList<T> getAvailableItems(final IItemList<T> out) {
if (!this.hasReadAccess) {
return out;
}
return this.internal.getAvailableItems(out);
}
@Override
public IStorageChannel<T> getChannel() {
return this.internal.getChannel();
}
@Override
public AccessRestriction getAccess() {
return this.cachedAccessRestriction;
}
@Override
public boolean isPrioritized(final T input) {
if (this.myWhitelist == IncludeExclude.WHITELIST) {
return this.myPartitionList.isListed(input) || this.internal.isPrioritized(input);
}
return false;
}
@Override
public boolean canAccept(final T input) {
if (!this.hasWriteAccess) {
return false;
}
if (this.myWhitelist == IncludeExclude.BLACKLIST && this.myPartitionList.isListed(input)) {
return false;
}
if (this.myPartitionList.isEmpty() || this.myWhitelist == IncludeExclude.BLACKLIST) {
return this.internal.canAccept(input);
}
return this.myPartitionList.isListed(input) && this.internal.canAccept(input);
}
@Override
public int getPriority() {
return this.myPriority;
}
public void setPriority(final int myPriority) {
this.myPriority = myPriority;
}
@Override
public int getSlot() {
return this.internal.getSlot();
}
@Override
public boolean validForPass(final int i) {
return true;
}
public IMEInventory<T> getInternal() {
return this.internal;
}
}
@@ -1,101 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.storage;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler<T> {
private final IStorageChannel wrappedChannel;
private IMEInventory<T> internal;
public MEPassThrough(final IMEInventory<T> i, final IStorageChannel channel) {
this.wrappedChannel = channel;
this.setInternal(i);
}
protected IMEInventory<T> getInternal() {
return this.internal;
}
public void setInternal(final IMEInventory<T> i) {
this.internal = i;
}
@Override
public T injectItems(final T input, final Actionable type, final IActionSource src) {
return this.internal.injectItems(input, type, src);
}
@Override
public T extractItems(final T request, final Actionable type, final IActionSource src) {
return this.internal.extractItems(request, type, src);
}
@Override
public IItemList<T> getAvailableItems(final IItemList out) {
return this.internal.getAvailableItems(out);
}
@Override
public IStorageChannel getChannel() {
return this.internal.getChannel();
}
@Override
public AccessRestriction getAccess() {
return AccessRestriction.READ_WRITE;
}
@Override
public boolean isPrioritized(final T input) {
return false;
}
@Override
public boolean canAccept(final T input) {
return true;
}
@Override
public int getPriority() {
return 0;
}
@Override
public int getSlot() {
return 0;
}
@Override
public boolean validForPass(final int i) {
return true;
}
IStorageChannel getWrappedChannel() {
return this.wrappedChannel;
}
}