Search in sources :

Example 1 with IFuzzyRetrieving

use of com.bluepowermod.tile.IFuzzyRetrieving in project BluePower by Qmunity.

the class TubeLogic method retrieveStack.

public boolean retrieveStack(TileEntity target, ForgeDirection dirToRetrieveInto, ItemStack filter, TubeColor color) {
    if (tube.getWorld() == null)
        return false;
    TubeStack stack = new TubeStack(filter, null, color);
    stack.setTarget(target, dirToRetrieveInto);
    Pair<ForgeDirection, TileEntity> result = getHeadingForItem(stack, false);
    if (result == null)
        return false;
    int fuzzySetting = 0;
    if (target instanceof IFuzzyRetrieving) {
        fuzzySetting = ((IFuzzyRetrieving) target).getFuzzySetting();
    }
    ItemStack extractedItem = null;
    if (result.getValue() instanceof TileManager) {
        // Exception for managers, the result can only end up as a manager if the pulling inventory was
        // a manager.
        TileEntity managedInventory = ((TileManager) result.getValue()).getTileCache(((TileManager) result.getValue()).getFacingDirection());
        extractedItem = IOHelper.extract(managedInventory, result.getKey().getOpposite(), filter, false, false, fuzzySetting);
    } else if (filter != null) {
        extractedItem = IOHelper.extract(result.getValue(), result.getKey().getOpposite(), filter, !(target instanceof TileManager), false, fuzzySetting);
    } else {
        extractedItem = IOHelper.extract(result.getValue(), result.getKey().getOpposite(), false);
    }
    if (extractedItem == null)
        throw new IllegalArgumentException("This isn't possible!");
    stack = new TubeStack(extractedItem, result.getKey().getOpposite(), color);
    stack.setTarget(target, dirToRetrieveInto);
    PneumaticTube tube = MultipartCompatibility.getPart(this.tube.getWorld(), result.getValue().xCoord - result.getKey().offsetX, result.getValue().yCoord - result.getKey().offsetY, result.getValue().zCoord - result.getKey().offsetZ, PneumaticTube.class);
    if (tube == null)
        throw new IllegalArgumentException("wieeeeerd!");
    return tube.getLogic().injectStack(stack, result.getKey().getOpposite(), false);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPneumaticTube(com.bluepowermod.api.tube.IPneumaticTube) IFuzzyRetrieving(com.bluepowermod.tile.IFuzzyRetrieving) MessageRedirectTubeStack(com.bluepowermod.network.message.MessageRedirectTubeStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) TileManager(com.bluepowermod.tile.tier3.TileManager)

Aggregations

IPneumaticTube (com.bluepowermod.api.tube.IPneumaticTube)1 MessageRedirectTubeStack (com.bluepowermod.network.message.MessageRedirectTubeStack)1 IFuzzyRetrieving (com.bluepowermod.tile.IFuzzyRetrieving)1 TileManager (com.bluepowermod.tile.tier3.TileManager)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1